带有multi_match AND bool的ElasticSearch
我尝试学习Elasticsearch将其添加到我的Rails应用程序中。我想对2个字段(就像它们只是一个字段)执行一次multi_match查询,并且还要对另一个必须等于1的字段(状态)进行过滤。
let response = Wine.search({ query: {
multi_match: {
query: "test",
fields: ["winery", "name"]
},
bool: {
must: {
term: { status: 1 }
},
should: [],
minimum_should_match: 1
}
}
})
错误是:
"fields\":[\"winery\",\"name\"]},\"bool\":{\"must\":{\"term\":{\"status\":1}},\"should\":[],\"minimum_should_match\":1}}}]]]; nested: ElasticsearchParseException[Expected field name but got START_OBJECT \"bool\"]; }]","status":400}
请求中有什么问题?如何一起执行multi_match和BOOL?
回答:
使用过滤查询:
{ "query": {
"filtered": {
"query": {
"multi_match": {
"query": "test",
"fields": [
"winery",
"name"
]
}
},
"filter": {
"term": {
"status": "1"
}
}
}
}
}
与Elasticsearch 5相同的查询:
{ "query": {
"bool": {
"must": {
"multi_match": {
"query": "test",
"fields": [
"winery",
"name"
]
}
},
"filter": {
"term": {
"status": "1"
}
}
}
}
}
以上是 带有multi_match AND bool的ElasticSearch 的全部内容, 来源链接: utcz.com/qa/417204.html