[英]ElasticSearch: Query_String but must match 1 of the terms in a specific field?
I want to build an ElasticSearch query where I query multiple fields, but one of the words in the query MUST match one of the fields. 我想在其中查询多个字段的地方构建一个ElasticSearch查询,但是查询中的单词之一必须与其中一个字段匹配。
For instance, suppose I query for "holiday party food", I want it to return all documents that have at least 1 of the terms in the title, and the rest in the html_source. 例如,假设我查询“节假日食品”,我希望它返回标题中至少包含一个术语,而html_source中具有其余术语的所有文档。
If a document has: 如果文档具有:
title: Holiday, html_source: party food => MATCH
title: Party, html_source: food holiday => MATCH
title: Food, html_source: holiday party => MATCH
title: RANDOM TITLE, html_source: holiday party food => NO MATCH.
This is what I have constructed so far, and it matches documents that have all the terms in the html_source, but NOT in the title, which is not what I want. 到目前为止,这是我构建的内容,它与在html_source中具有所有术语但在标题中没有所有术语的文档匹配,这不是我想要的。
{
"query":{
"query_string":{
"query":"holiday party food",
"default_operator":"AND",
"fields":[
"title","html_source"
]
}
},
"sort":[
{
"total_shares":"desc"
}
]
}
Here is a query syntax version that I think will do want you want: 这是我希望您想要的查询语法版本:
+(
(+title:holiday +(body:party body:food -body:holiday))
(+title:party +(body:holiday body:food -body:party)
(+title:food +(body:holiday body:party -body:food))
)
If this does not work, I think it points you in the right direction. 如果这不起作用,我认为它为您指明了正确的方向。 The trick in this kind of query is to enumerate all of the choices explicitly.
这种查询的诀窍是显式枚举所有选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.