弹性搜索 - 如何追加术语? [英] Elasticsearch - how to append term?
问题描述
例如,如果我的文档如下所示:
{
items:[item1,item2,item3]
}
我想追加item4和item5。
必须在2个查询中执行?一个加载当前的值列表,并更新该列表?或者是否有更优雅的方式让我将这些项目附加在一个查询中?
我正在尝试用这样的elastic4s:
client.execute(ElasticDsl.update id index in indexName / documentType script {
script(sctx._source.items + = tag) .params(map(tag - >item4))
})
为了使用上面的代码片段,我需要启用groovy脚本,我不知道如何使用多个项目。
任何想法? p>
这是一个完整的例子,您可以如何实现这一目标。
将新的值合并到数组中,并使其独特之后:
DELETE test / test / 1
POST test / test / 1
{
terms:[item1,item2,item3]
}
GET test / test / 1
POST测试/测试/ 1 / _update
{
脚本:ctx._source.terms<< newItems; ctx._source.terms = ctx._source .terms.flatten() 。$$$$
/$$$$ $ c>
确保您有 Is there a way to append term into an array of values? For example if my document looks like this: I want to append "item4" and "item5" to it. I must do it in 2 queries? one to load the current list of values, and on to update that list? or is there more elegant way that will let me append those items in one query? I am trying to do it with elastic4s like this: In order to use the above code snippet, I need to enable groovy scripts, and I am not sure how to do it with multiple items. Any idea? Here is a full example of how you could achieve this. Merge new values to array and make it unique after: make sure you have scripting enabled in server config
这篇关于弹性搜索 - 如何追加术语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
user:/ etc /弹性搜索#head elasticsearch.yml
script.inline:true
script.indexed:true
...
{
"items": ["item1", "item2", "item3"]
}
client.execute(ElasticDsl.update id id in indexName / documentType script {
script(s"ctx._source.items += tag").params(Map("tag"->"item4"))
})
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"]
}
}
user:/etc/elasticsearch# head elasticsearch.yml
script.inline: true
script.indexed: true
...