Minimum_should_match appears to default to 0 when not explicitly set

I'm confused about the behaviour of a query with shoulds.

I have the following query on a 6.2.3 cluster:

GET reporting_tags/_search
{
  "query": {
    "bool": {
      "must": [
        {"term": {"source": "analytics"}}
      ],
      "should": [
        {"range": {"created": {"lt": 1525206239677}}},
        {
          "bool": {
            "must_not": [
              {"exists": {"field": "created"}}
            ]
          }
        }
      ]
    }
  }
}

Unless I add an explicit "minimum_should_match": 1, only the must part of the query limits the results. I get results that match none of the should clauses (tags with a created property with a larger long than the one specified in the query). When I add minimum_should_match, then all is as it should be. Did the default change?

It's always been that way being based on the Lucene behaviour that predates elasticsearch. Going back as far as 0.9 docs the distinction between default behaviour when must is present and not is noted.

Thanks for the quick reply! Can't believe I never noticed that.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.