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.
let response = Wine.search({
query: {
multi_match: {
query: "test",
fields: ["winery", "name"]
},
bool: {
must: {
term: { status: 1 }
},
should: [],
minimum_should_match: 1
}
}
})
The error is:
"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}
What is wrong in the request ? How to perform a multi_match AND a BOOL together ?
Use a filtered query:
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "test",
"fields": [
"winery",
"name"
]
}
},
"filter": {
"term": {
"status": "1"
}
}
}
}
}
Same query for Elasticsearch 5:
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "test",
"fields": [
"winery",
"name"
]
}
},
"filter": {
"term": {
"status": "1"
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With