如何在弹性搜索中向已存在列表中插入元素
假设我有如下存储的文档如何在弹性搜索中向已存在列表中插入元素,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,假设我有如下存储的文档 document 1 { id : '1', title : "This is a test document1", list : ["value1" , "value2"], ... } document 2 { id : '2', title : "This is a test document2", valueList : ["va
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"],
...
}
我需要向文档中的valueList添加更多元素,并使用BulkAPI创建文档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"],
...
}
我能做些什么来实现这一点?
我尝试使用脚本,但它只更新一个文档
对不起,我是弹性搜索的新手。在这个问题上我甚至可能很愚蠢。请原谅,并让我清楚地回答这个问题。请参阅。这应该是直截了当的。您需要使用_update,只是为了给您一个想法,即使文档近乎完美,它也可能是这样的:
POST /your_index/your_type/document1/_update
{
id : '1',
title : "This is a test document1",
list : ["value1" , "value2", "value3"]
}
这将更新文档1
如果是批量更新,您应该阅读并查看
从文档中:
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参数,它刚刚与现有文档合并。
对象合并在一起,现有标量字段被覆盖,
并添加了新字段
提示:google update按查询elasticsearchUpdate在文档中是直接的。它用于更新整个值。但我真正需要的不是替换整个列表。我需要用已经存在的元素添加另一个元素。该操作也是批量操作。更新将合并文档。我在答案中加了这个。顺便说一句,您不能只更新字段的一部分。更新时替换文档中的整个字段值。获得解决方案。顺便谢谢你的努力。