如何修复 ElasticSearch '[match] query doesn't support multiple fields, found [...] and [...]'
问题:
你想运行类似这样的 ElasticSearch 查询
match-query-example.json
{
"query": {
"match" : {
"one_field" : "one_value",
"another_field": "another_value"
}
}
}但你只看到类似这样的错误消息
elasticsearch-error.txt
elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', "[match] query doesn't support multiple fields, found [one_field] and [another_field]")解决方案
Match 查询仅支持一个字段。你应该使用包含多个 match 查询的 must 子句的 bool 查询:
bool-must-multi-match.json
{
"query": {
"bool": {
"must": [
{"match": {"one_field" : "one_value"}},
{"match": {"another_field" : "another_value"}},
]
}
}
}另请参见MultiMatch 查询的官方文档。
Check out similar posts by category:
Databases, ElasticSearch
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow