如何在 ElasticSearch 中组合多个查询
How do I combine multiple queries in ElasticSearch
我正在尝试检索匹配两个查询的记录。
第一个是match_phrase
"match_phrase": {
"searchstring": {
"query": "' . $searchQ . '",
"slop": 10
}
}
第二个我用的是多重匹配
"multi_match": {
"query": "' . $searchQ . '",
"fields" : ["_all"],
"type": "cross_fields",
}
我怎样才能正确地做到这一点。请帮助
您可以使用 bool/must
(或 bool/should
)查询来合并您的两个查询:
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"searchstring": {
"query": "xyz",
"slop": 10
}
}
},
{
"multi_match": {
"query": "xyz",
"fields": [
"_all"
],
"type": "cross_fields"
}
}
]
}
}
}
我正在尝试检索匹配两个查询的记录。
第一个是match_phrase
"match_phrase": {
"searchstring": {
"query": "' . $searchQ . '",
"slop": 10
}
}
第二个我用的是多重匹配
"multi_match": {
"query": "' . $searchQ . '",
"fields" : ["_all"],
"type": "cross_fields",
}
我怎样才能正确地做到这一点。请帮助
您可以使用 bool/must
(或 bool/should
)查询来合并您的两个查询:
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"searchstring": {
"query": "xyz",
"slop": 10
}
}
},
{
"multi_match": {
"query": "xyz",
"fields": [
"_all"
],
"type": "cross_fields"
}
}
]
}
}
}