说我有如下存储的文件。
document 1
{
id : '1',
title : "This is a test document1",
list : ["value1" , "value2"],
...
}
document 2
{
id : '2',
title : "This is a test document2",
valueList : ["value1" , "value2"],
...
}
我需要使用批量api将更多元素添加到文档的valueList中,并带有文档ID列表。结果应该看起来像
document 1
{
id : '1',
title : "This is a test document1",
list : ["value1" , "value2", "value3"],
...
}
document 2
{
id : '2',
title : "This is a test document2",
valueList : ["value1" , "value2" , "value3"],
...
}
我该怎么做?
我尝试使用脚本,但它仅更新单个文档。
抱歉, Elasticsearch 真的很新。我什至在这个问题上很愚蠢。请原谅我,让我清楚这个问题。
最佳答案
参见Updating Document。它应该很简单。您需要使用_update
并给您一个想法,即使文档几乎是完美的,也可能是这样的:
POST /your_index/your_type/document1/_update
{
id : '1',
title : "This is a test document1",
list : ["value1" , "value2", "value3"]
}
这将更新
document1
。如果进行批量更新,则应阅读Batch Processing并查看Bulk API。
从文档:
POST /your_index/your_type/_bulk
{ "update" : {"_id" : "document1", "_type" : "your_type", "_index" : "your_index"}}
{ "doc" : {"myfield" : "newvalue"} }
{ "update" : {"_id" : "document2", "_type" : "your_type", "_index" : "your_index"}}
{ "doc" : {"myfield" : "newvalue"} }
请注意,您可以只将
_update
用作Partial Updates。The simplest form of the update request accepts a partial document as the doc parameter, which just gets merged with the existing document. Objects are merged together, existing scalar fields are overwritten, and new fields are added.
关于elasticsearch - 如何在 Elasticsearch 中将元素插入已经存在的列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47571259/