danpaz / bodybuilder

An elasticsearch query body builder :muscle:

Home Page:http://bodybuilder.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

queryMinimumShouldMatch is only available on more than one should clause

loriling opened this issue · comments

commented

The default value of minimum_should_match is not only one in different query case or es versions.
https://stackoverflow.com/questions/48984706/default-value-of-minimum-should-match

So I think it could be set explicitly in all cases. The same as the filterMinimumShouldMatch.

A single should is an explicit must, so adding minimum_should_match is redundant.

For what it's worth I was bitten by this too.

I have a list of matches that I want to apply, so I was doing

for (const x of list) {
  builder.orQuery('match', 'foo', x);
}
builder.queryMinimumShouldMatch(1);

The code worked if there were multiple elements in list but if there's only one element then it doesn't add in the minimum_should_match which changes the semantics of the query.

Sounds like I'll have to explicitly check whether list is of size 1 and use a .query instead of an .orQuery. Kind of unintuitive in my opinion.