Difficulty combining bool and range query, elastic search Difficulty combining bool and range query, elastic search elasticsearch elasticsearch

Difficulty combining bool and range query, elastic search


Your range query must be inside the must clause:

{  "query": {    "bool": {      "must": [        {          "term": {            "Underlying": {              "value": "eurodollar"            }          }        },        {          "range": {            "Expiration": {              "gte": "20160315",              "lte": "20160515"            }          }        }      ]    }  }}

You combine different queries with bool query. And it take 4 different clause in it: must, should, not_must and filter.

filter is same as must. Difference is score for filter is not counted.

And basic structure is (taken from doc):

{  "bool": {    "must": {      "term": { "user": "kimchy" }    },    "filter": {      "term": { "tag": "tech" }    },    "must_not": { <= single inside query      "range": {        "age": { "from": 10, "to": 20 }      }    },    "should": [   <= that is an array,      {           <= start of inner query is important        "term": { "tag": "wow" }      },      {        "term": { "tag": "elasticsearch" }      }    ]  }}