0

假设我有如下存储的文档。

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"],
        ...
        }

我能做些什么来实现这一目标?我尝试使用脚本,但它只更新一个文档。

抱歉,我对弹性搜索真的很陌生。在这个问题上我什至可能是愚蠢的。请原谅并让我清楚这个问题。

4

1 回答 1

1

请参阅更新文档。它应该是直截了当的。您需要使用_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用于部分更新

更新请求的最简单形式接受部分文档作为 doc 参数,它只是与现有文档合并。对象被合并在一起,现有的标量字段被覆盖,并且新的字段被添加。

于 2017-11-30T11:15:17.087 回答