[英]Multi-“match-phrase” query in Elastic Search
this should be obvious to me but is not.这对我来说应该是显而易见的,但事实并非如此。 The following two-match only the second phase (in this case,
Cape Basin
)以下两场比赛仅进行第二阶段(本例中为
Cape Basin
)
"query": {
"match_phrase": {
"contents": {
"query": "St Peter Fm",
"query": "Cape Basin"
}
}
}
"query": {
"match_phrase": {
"contents": {
"query": ["St Peter Fm", "Cape Basin"]
}
}
}
while the following croaks with an error而以下发出错误的咝咝声
"query": {
"match_phrase": {
"contents": {
"query": "St Peter Fm"
},
"contents": {
"query": "Cape Basin"
}
}
}
I want to match all documents that contain either phrases exactly as entered.我想匹配包含与输入的任何一个短语完全相同的所有文档。
Your first query is not really a valid JSON object because you use the same field name twice.您的第一个查询并不是真正有效的 JSON 对象,因为您两次使用相同的字段名称。
You can use a bool must query to match both phrases:您可以使用bool must 查询来匹配这两个短语:
PUT phrase/doc/1
{
"text": "St Peter Fm some other text Cape Basin"
}
GET phrase/_search
{
"query": {
"bool": {
"must": [
{"match_phrase": {"text": "St Peter Fm"}},
{"match_phrase": {"text": "Cape Basin"}}
]
}
}
}
It turns out you can do this by enabling phrase semantics for multi_match
.事实证明,您可以通过为
multi_match
启用短语语义来做到这multi_match
。
To do this you add a type:
attribute to the multi_match
syntax as below:为此,您向
multi_match
语法添加一个type:
属性,如下所示:
GET /_search
{
"query": {
"multi_match" : {
"query": "quick brown fox",
"type": "phrase",
"fields": [ "subject", "message" ]
}
}
}
Once you think of it that way (vs. enabling "multi" support on other search clauses) it fits in where you'd expect.一旦您这样想(与在其他搜索子句上启用“多”支持相比),它就符合您的期望。
ref: https://www.elastic.co/guide/en/elasticsearch/reference/6.5/query-dsl-multi-match-query.html#type-phrase参考: https : //www.elastic.co/guide/en/elasticsearch/reference/6.5/query-dsl-multi-match-query.html#type-phrase
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.