What is a bool query in Elasticsearch?

Answer

The bool query is the primary compound query in Elasticsearch used to combine multiple queries with logical operators. It has four clause types: must — the query must match and contributes to the score (AND); should — the query is optional but boosts the score if it matches (OR); must_not — the query must NOT match (executed in filter context, no score contribution); and filter — the query must match but does NOT contribute to the score and IS cached. For example, a product search might use must for the keyword match, filter for category and price range, and must_not to exclude out-of-stock items.