我使用es7.1,我想使用多匹配查询从几个字段中获取结果,但我希望在特定字段上使用match_phrase获取结果。
我尝试了很多东西,这是最接近我想要的版本:
'bool' : {
'must' : {
'multi_match' : {
'fields' => ['titre', 'subtitre', 'description'],
'query' => $query
},
'match_phrase' : {
'titre' => $query
}
},
'filters' : { // ... some filters }
}
我收到一个错误:
Parsing_exception,“原因”:“multi_match格式错误的查询,期望END_OBJECT但找到了FIELD_NAME
有办法将两者结合起来吗?我不想创建2个查询。
发布于 2019-06-19 09:48:48
当您想要多个must
子查询时,只需要将子查询作为一个数组传递。这个修改应该可以工作(翻译成JSON):
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "hello",
"fields": ["name", "brand_name"]
}
},
{
"match_phrase": {
"title": "hello"
}
}
]
}
}
}
https://stackoverflow.com/questions/56672791
复制相似问题