elasticsearch - 如何在 Elasticsearch 中将元素插入已经存在的列表中

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

我需要使用批量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/

相关文章:

javascript - 如何过滤带有多个参数的json对象?

elasticsearch - 带有子文档计数的Elasticsearch分数

Action 部分的elasticsearch批量索引和冗余数据

c# - 在 ElasticSearch 中使用 Bulk.IndexMany 指定 _id 字段

ruby-on-rails - ElasticSearch/Tire 只返回一个索引的结果

elasticsearch - Elasticsearch多个搜索条件

elasticsearch - 在Elasticsearch中对分析字段进行过滤查询

elasticsearch - 从 ElasticSearch 6+ 中的文档中批量删除属性

elasticsearch - ElasticSearch,在使用批量API时在索引名称上使用通配符

elasticsearch - 使用批量API将批处理上传到Elasticsearch存储中