Search code examples
elasticsearchelasticsearch-dsl

elasticsearch: can remove duplicate field in query?


I would like to remove duplicated field in query.
For example:

# figure1 

{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must": []
                }
              }
            ]
          }
        }
      ]
    }
  }
}

in above query example base,
Is it possible to remove duplicate bool fields except for the first bool?

The result I want is below

# figure2

{
  "query": {
    "bool": {
      "filter": [
        {
          "should": [
            {
              "must": []
            }
          ]
        }
      ]
    }
  }
}

please, I hope wating for your answer, thanks.


Solution

  • The answer is no. With figure #2 elastic throws an error:

    [should] query malformed, no start_object after query name
    

    If you want to create a nested boolean expression, you must put the keyword bool before.

    For example: How to combine multiple bool queries in elasticsearch