ElasticSearch with multi_match and bool

I am trying to learn Elasticsearch to add it to my Rails application. I want to execute a multi_match request in 2 fields (as if they were only one field), and also have a filter for another field (state), which should be 1.

response = Wine.search({ query: { multi_match: { query: "test", fields: ["winery", "name"] }, bool: { must: { term: { status: 1 } }, should: [], minimum_should_match: 1 } } }) 

Error:

 "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 with the request? How to execute multi_match and BOOL together?

+5
source share
1 answer

Use a filtered query :

 { "query": { "filtered": { "query": { "multi_match": { "query": "test", "fields": [ "winery", "name" ] } }, "filter": { "term": { "status": "1" } } } } } 

The same query for Elasticsearch 5:

 { "query": { "bool": { "must": { "multi_match": { "query": "test", "fields": [ "winery", "name" ] } }, "filter": { "term": { "status": "1" } } } } } 
+14
source

Source: https://habr.com/ru/post/1210642/


All Articles