2013-06-13 45 views
4

是否可以在elasticsearch中为现有文档添加更多字段?更新elasticsearch中的现有文档

我索引例如下列文件:

{ 
    "user":"xyz", 
    "message":"for increase in fields" 
} 

现在,我想更多的1字段添加到它即日期:

{ 
    "user":"xyz", 
    "message":"for increase in fields", 
    "date":"2013-06-12" 
} 

如何才能做到这一点?

回答

9

弹性搜索登记update

更新API还支持传递局部文档(自0.20), 将被合并到现有的文件(简单的递归 合并,对象的内合并,替换核心“键/值”和 阵列)

Solr 4.0也支持部分更新。勾选Link

3

这可以用partial update来完成(假设该文件为1的ID):

curl -XPOST 'http://localhost:9200/myindex/mytype/1/_update' -d ' 
{ 
    "doc" : { 
    "date":"2013-06-12" 
    } 
}' 

然后查询文档:

curl -XGET 'http://localhost:9200/myindex/mytype/_search?q=user:xyz' 

你应该看到:

"_id":"1", 
"_source: 
    { 
     { 
      "user":"xyz", 
      "message":"for increase in fields", 
      "date":"2013-06-12" 
     } 
    } 
相关问题