如何在弹性搜索

时间:2017-11-30 10:33:08

标签: elasticsearch elasticsearch-bulk-api

说我的文件存储如下。

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

我需要使用bulk 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"],
        ...
        }

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

抱歉我对弹性搜索很新。我甚至可能对这个问题很愚蠢。请原谅并告诉我这个问题。

1 个答案:

答案 0 :(得分:1)

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

  

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

相关问题