Skip to content

Conversation

@rodrigozhou
Copy link
Contributor

@rodrigozhou rodrigozhou commented Jan 16, 2026

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:
    {
      "bool": {
        "filter": [
          { ... }, // `a` clause
          {
            "bool": {
              "filter": [
                { ... }, // `b` clause
                { ... }  // `c` clause
              ]
            }
          }
        ]
      }
    }
  • After:
    {
      "bool": {
        "filter": [
          { ... }, // `a` clause
          { ... }, // `b` clause
          { ... }  // `c` clause
        ]
      }
    }
  1. OR queries: combined multiple OR clause into a single BoolQuery (similar to AND above)

  2. NOT (a OR b): replace should with must_not.

  • Before:
    {
      "bool": {
        "must_not": {
          "bool": {
            "should": [
              { ... }, // `a` clause
              { ... }  // `b` clause
            ]
          }
        }
      }
    }
  • After:
    {
      "bool": {
        "must_not": [
          { ... }, // `a` clause
          { ... }  // `b` clause
        ]
      }
    }
  1. a AND !b: combine filter and must_not clauses into a single BoolQuery.
  • Before:
    {
      "bool": {
        "filter": [
          { ... }, // `a` clause
          {
            "bool": {
              "must_not": [
                { ... } // `b` clause
              ]
            }
          }
        ]
      }
    }
  • After:
    {
      "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

@rodrigozhou rodrigozhou force-pushed the rodrigozhou/opt-es-qc branch from 4059169 to 4fdea6b Compare January 16, 2026 22:06
@rodrigozhou rodrigozhou marked this pull request as ready for review January 16, 2026 22:06
@rodrigozhou rodrigozhou requested review from a team as code owners January 16, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants