0

I'm running a should query with any empty list against an index. I'm expecting it to return 0 results since there are no should queries/filters to match against:

(Syntax is Chewy but pretty close to regular ES)

OrganizationsIndex.filter(
   bool: {
     must: [
       {
         bool: {
           should: [],
    minimum_should_match: 1
         }
       }
     ]
   })

However, it returns all the documents in the index. Is that expected behavior? Is there a way that I could make should: [] always return 0 documents?

  • Having no constraints in your bool query, it is equivalent to a `match_all`query. – Val Mar 28 '18 at 04:12
  • @Val Thanks. If you put that as an answer I'll accept. Could you point me to some documentation on that so I could understand more about the behavior? – not_user9123 Mar 28 '18 at 17:59

1 Answers1

0

This behaviour was changed in 1.3.3 version of Elasticsearch. Before, the empty should clause was treated as no match, and afterwards as it was mentioned by @Val it became match_all query.

From the discussion on the issue:

When a query with just a bool {} is run on its own, the empty bool clause in this case does not throw a NPE and is treated as a valid query, except that it returns no documents (when it should really be returning a match_all):

The link to this GitHub issue - https://github.com/elastic/elasticsearch/issues/7240

Mysterion
  • 9,050
  • 3
  • 30
  • 52