Mixing Elastic 'bool' and 'range' queries

February 28, 2022

To mix ‘bool’ and ‘range’ queries in an Elastic query, add the range query to the array of queries:

GET documents/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "entityId": [
              "-832106300000216000"
            ],
            "boost": 1
          }
        },{
          "range" : {
            "pubyear" : {
              "gte" : 2020
            }
          }
        }
      ]
    }
  }
}