在elasticsearch中是否可以在单个查询中获取包含phrase1或phrase2的所有文档? 我知道要匹配一个短语,可以使用以下查询:
"query" : {
"match_phrase" : {
"title" : "rock climbing"
}
}
但是,如果有多个短语并且目标是检索包含这些短语的文档,那该怎么办。
答案 0 :(得分:3)
您可以在bool query的match_phrase
子句中包含两个should
个查询:
{
"query" : {
"bool": {
"should": [
{
"match_phrase" : {
"title" : "phrase1"
}
},
{
"match_phrase": {
"title": "phrase2"
}
}
],
"minimum_number_should_match": 1
}
}
}
答案 1 :(得分:1)
您可以执行Query String搜索
{
"query_string" : {
"default_field" : "content",
"query" : "this AND that OR thus"
}
}
您可以在查询中指定AND / OR子句或使用default_operator
,只需将关键字写入query
参数即可。如果你想要精确的phare,只需将单词换成引号即可。