Elasticsearch - how to append term?

依然范特西╮ 提交于 2019-12-04 17:54:34

Here is a full example of how you could achieve this.

Merge new values to array and make it unique after:

DELETE test/test/1

POST test/test/1
{
  "terms":["item1", "item2", "item3"]
}

GET test/test/1

POST test/test/1/_update
{
     "script" : " ctx._source.terms << newItems; ctx._source.terms = ctx._source.terms.flatten().unique()",
     "params" : {
         "newItems" : ["a","b"]
     }
}

make sure you have scripting enabled in server config

user:/etc/elasticsearch# head elasticsearch.yml 
script.inline: true
script.indexed: true
...

Try using 'terms' filter in your code.If you are using NEST then following link will be useful https://nest.azurewebsites.net/nest/writing-queries.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!