2013-06-13 44 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" 
     } 
    } 
相關問題