The "minimum_number_should_match" property allows us to specify a minimum number of conditions in the should clause of the bool query that need to be satisfied. So if there are 4 conditions in the should clause and "minimum_number_should_match" is set to 2, then any document where 2 or 3 or all 4 of the conditions are true is returned in the result set.
Is there a way to specify that the query should return only those documents where exactly 2 of the 4 conditions in the should clause are satisfied(In exactly 2 situation, a document where 3 or 4 conditions are satisfied will not be returned )?
Thanks for your reply! I think this solution would work for my problem.
Maybe as a future improvement to the bool query, we could have a "exact_number_should_match" attribute or a "maximum_number_should_match" just like the "minimum_should_match" attribute...that would save the user from writing the exact same query in the "should" and "must_not" blocks.
Maybe it is a rare requirement. But I have a use case where users can specify that they want exactly m out of n conditions to be true, where m < n and n<=10. This system is currently implemented in SQL and is very slow and we are in the process of migrating it to ElasticSearch...
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.