[Elasticsearch] Combine query clauses whenever possible to avoid deep nested BoolQuery#9069
Merged
rodrigozhou merged 1 commit intomainfrom Jan 27, 2026
Merged
[Elasticsearch] Combine query clauses whenever possible to avoid deep nested BoolQuery#9069rodrigozhou merged 1 commit intomainfrom
rodrigozhou merged 1 commit intomainfrom
Conversation
… nested BoolQuery
4059169 to
4fdea6b
Compare
awln-temporal
approved these changes
Jan 23, 2026
simvlad
pushed a commit
that referenced
this pull request
Jan 27, 2026
… nested BoolQuery (#9069) ## What changed? Combining query clauses in Elasticsearch. 1. `AND` queries: combined multiple `AND` clause into a single `BoolQuery`. Example: `a AND b AND c` - Before: ```json { "bool": { "filter": [ { ... }, // `a` clause { "bool": { "filter": [ { ... }, // `b` clause { ... } // `c` clause ] } } ] } } ``` - After: ```json { "bool": { "filter": [ { ... }, // `a` clause { ... }, // `b` clause { ... } // `c` clause ] } } ``` 2. `OR` queries: combined multiple `OR` clause into a single `BoolQuery` (similar to `AND` above) 3. `NOT (a OR b)`: replace `should` with `must_not`. - Before: ```json { "bool": { "must_not": { "bool": { "should": [ { ... }, // `a` clause { ... } // `b` clause ] } } } } ``` - After: ```json { "bool": { "must_not": [ { ... }, // `a` clause { ... } // `b` clause ] } } ``` 4. `a AND !b`: combine `filter` and `must_not` clauses into a single `BoolQuery`. - Before: ```json { "bool": { "filter": [ { ... }, // `a` clause { "bool": { "must_not": [ { ... } // `b` clause ] } } ] } } ``` - After: ```json { "bool": { "filter": [ { ... } // `a` clause ] "must_not": [ { ... } // `b` clause ] } } ``` ## Why? Reduce nesting depth of bool queries. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) ## Potential risks
Merged
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed?
Combining query clauses in Elasticsearch.
ANDqueries: combined multipleANDclause into a singleBoolQuery. Example:a AND b AND c{ "bool": { "filter": [ { ... }, // `a` clause { "bool": { "filter": [ { ... }, // `b` clause { ... } // `c` clause ] } } ] } }{ "bool": { "filter": [ { ... }, // `a` clause { ... }, // `b` clause { ... } // `c` clause ] } }ORqueries: combined multipleORclause into a singleBoolQuery(similar toANDabove)NOT (a OR b): replaceshouldwithmust_not.{ "bool": { "must_not": { "bool": { "should": [ { ... }, // `a` clause { ... } // `b` clause ] } } } }{ "bool": { "must_not": [ { ... }, // `a` clause { ... } // `b` clause ] } }a AND !b: combinefilterandmust_notclauses into a singleBoolQuery.{ "bool": { "filter": [ { ... }, // `a` clause { "bool": { "must_not": [ { ... } // `b` clause ] } } ] } }{ "bool": { "filter": [ { ... } // `a` clause ] "must_not": [ { ... } // `b` clause ] } }Why?
Reduce nesting depth of bool queries.
How did you test it?
Potential risks