ElasticSearch with multi_match和bool [英] ElasticSearch with multi_match AND bool
本文介绍了ElasticSearch with multi_match和bool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试学习弹性搜索将其添加到我的Rails应用程序中。
我想执行一个multi_match查询到2个字段(好像它们只是一个字段),并且还有另一个字段(状态)必须等于1的过滤器。
I try to learn Elasticsearch to add it in my Rails app. I want to perform a multi_match query into 2 fields (as if they were just a single field) and also have a filter to another field (status) that must be equal to 1.
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}
请求中有什么问题?多个匹配和一个BOOL在一起?
What is wrong in the request ? How to perform a multi_match AND a BOOL together ?
推荐答案
使用过滤查询:
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "test",
"fields": [
"winery",
"name"
]
}
},
"filter": {
"term": {
"status": "1"
}
}
}
}
}
与Elasticsearch 5相同的查询:
Same query for Elasticsearch 5:
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "test",
"fields": [
"winery",
"name"
]
}
},
"filter": {
"term": {
"status": "1"
}
}
}
}
}
这篇关于ElasticSearch with multi_match和bool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文