The following range_query returns a result as expected:
{\"query\": {
\"bool\": {
\"must\": [
{
\"range\": {
\"created_at
Under your bool
queries' must
clause there's no need to wrap it in an and
. There is no and
query, maybe you were thinking of the and filter?
Example runnable play as curl commands for convenience:
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"settings": {},
"mappings": {
"type": {
"properties": {
"created_at": {
"type": "date",
"format": "dateOptionalTime"
},
"name": {
"type": "string"
},
"happens_on": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type"}}
{"name":"foo","created_at":"2013-12-09T00:00:00.000Z","happens_on":"2013-12-16T00:00:00.000Z"}
{"index":{"_index":"play","_type":"type"}}
{"name":"bar","created_at":"2013-12-08T00:00:00.000Z","happens_on":"2013-12-16T00:00:00.000Z"}
{"index":{"_index":"play","_type":"type"}}
{"name":"bar","created_at":"2013-12-09T00:00:00.000Z","happens_on":"2013-12-17T00:00:00.000Z"}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"bool": {
"must": [
{
"range": {
"created_at": {
"gte": "2013-12-09T00:00:00.000Z"
}
}
},
{
"range": {
"happens_on": {
"lte": "2013-12-16T00:00:00.000Z"
}
}
}
]
}
}
}
'