词组之间的Elasticsearch OR操作 [英] Elasticsearch OR operation between phrases
本文介绍了词组之间的Elasticsearch OR操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Elasticsearch中是否有可能在单个查询中获取所有包含短语1"或短语2"的文档? 我知道要匹配一个短语,可以使用以下查询:
Is it possible in elasticsearch to get all documents that contain phrase1 OR phrase2 in a single query? I know to match a phrase, one can use the following query:
"query" : {
"match_phrase" : {
"title" : "rock climbing"
}
}
但是如果有多个词组并且目标是检索包含这些词组之一的文档,那该怎么办?
But how about a case when there are multiple phrases and the goal is to retrieve documents containing either of these phrases.
推荐答案
您可以将两个match_phrase
查询包装在
You can wrap the two match_phrase
queries in the should
clause of a bool query :
{
"query" : {
"bool": {
"should": [
{
"match_phrase" : {
"title" : "phrase1"
}
},
{
"match_phrase": {
"title": "phrase2"
}
}
],
"minimum_number_should_match": 1
}
}
}
这篇关于词组之间的Elasticsearch OR操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文