{
"id":100,
"name":"xxx",
"others":{
"hobbies":["cricket","footbal"]
}}
- 如何在爱好中增加新的值(value)(“爱好”:[“板球”,“足球”,“读书”])
- 如何在其他字段中添加新字段(例如:位置)
- 如何从爱好中去除“蟋蟀”。
最佳答案
您可以根据您的要求使用脚本更新
( documentation link )。
在爱好中增加值(value)的查询
{ "script" : { "source": "ctx._source.others.hobbies.add(params.hobby)", "lang": "painless", "params" : { "hobby": "reading books" } } }
在他人中添加新字段
{ "script": { "source": "ctx._source.others.location = 'value_of_new_field'", "lang": "painless" } }
从爱好中删除蟋蟀
{ "script" : { "source": "int index = ctx._source.others.hobbies.indexOf(params.remove_string); if(index != -1){ctx._source.others.hobbies.remove(index);}", "lang": "painless", "params" : { "remove_string" : "cricket" } } }
UPDATE-1 根据下面评论中的要求,添加数组字段的方法。
添加一个数组字段
{
"script": {
"source": "ctx._source.extra.location = []",
"lang": "painless"
}
}
关于hadoop - Elasticsearch 5.4 更新\添加嵌套文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48924943/