How to Query OpenSearch Using Boolean Queries
OpenSearch boolean queries find or match documents using boolean clauses. In the article linked below we describe how to construct a boolean query, or bool query. We will also work through several example OpenSearch bool queries.
Here let's discuss the four boolean clauses used for bool queries: filter, must, must_not, and should.
filter – Filter prunes the dataset; a document will either fit into a filter or be excluded by it. Filter queries can reduce datasets to a specific date range, location, or other exact match.
Filtering increases search performance because the OpenSearch cache stores filter queries. The next time a repeat filter query is run, the results get pulled from the cache. We will go into more depth about filtering below.
must – Must is like the “and” operator used when making a Google search. Must tells OpenSearch that document matches need to include all the queries that fall under the must clause. If you have more than one query, then all those queries need to match.
must-not – Mustnot is like the “not” operator used when making a Google search. It is the opposite of the must clause. Mustnot tells OpenSearch that document matches cannot include any of the queries that fall under the must_not clause.
should – It would be ideal for the matching documents to include all the queries in the should clause, but they don’t have to be included. Scoring ranks the matches.
Further down in this article we have a section on how OpenSearch uses scoring. Simply put, the more should queries that a matched document has, the higher the score for that document.
As a default setting, any match needs to contain at least one of the should queries. This minimum value is adjustable using the parameter minimumnumbershould_match.
Click on the link below to keep reading about how to query OpenSearch.