Elastic Search: use filter and should bool query Elastic Search: use filter and should bool query elasticsearch elasticsearch

Elastic Search: use filter and should bool query


Following common sense I found that the following does what I want for the bool segment:

bool => {             must => [                {match => { pcode => $postcode }},            ],            should => [                {match => { address => $keyword }},                {match => { name => $keyword }},            ],                minimum_should_match => 1,        }

Having minimum_should_match as 1 (which is a counter rather than true/false), feels like it's inserting an OR in those shoulds


Elastic doc says:

"By default, none of the should clauses are required to match, with one exception: if there are no must clauses, then at least one should clause must match. Just as we can control the precision of the match query, we can control how many should clauses need to match by using the minimum_should_match parameter, either as an absolute number or as a percentage"

So the way to do it is through minimum_should_match. Just as you did. What you did means that either address or name must be matched.