need to upgrade from AND, OR filters on elasticsearch to boolean queries for ES7

67 Views Asked by At

i'm trying to update a query that was possible on ElasticSearch 2 and does not exist in ES7. it's this query below:

{
"filter":
  {
  "and":[
     {
      "or":[
        { 
         "range":
          {
           "date_of_birth":
             {
             "lte": 5
             }
           }
         },
          {
           "range":
              {
              "age":{
                   "gte": 15
                    }
              }
            }]
       },{
         "range":
          {
            "begin_time":
              {
               "lte": 23
              }
           }
        }]
    } 
}            

i am aware that i should use boolean queries but because it is a filter, i am confused and i would appreciate your help :)

1

There are 1 best solutions below

3
Val On BEST ANSWER

There you go, just replace and by bool/filter and or by bool/should:

{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "should": [
              {
                "range": {
                  "date_of_birth": {
                    "lte": 5
                  }
                }
              },
              {
                "range": {
                  "age": {
                    "gte": 15
                  }
                }
              }
            ]
          }
        },
        {
          "range": {
            "begin_time": {
              "lte": 23
            }
          }
        }
      ]
    }
  }
}