I am using the python elastic search client to query my elasticsearch index. My index is very small, because I am trying to deduce where my query is going wrong. Here is an example entry
_source: {
Expiration: 20160115
}
and another
_source: {
Expiration: 20160215
}
and another
_source: {
Expiration: 20160315
}
Essentially, all the 15th's of each month for this year.
Here is my query/request
try:
results = client.search(
body = {
'query' : {
'range' : {
'Expiration' : {
'gte' : '2015',
'lte' : '2017',
'format' : 'yyyy'
}
}
}
},
index = 'test-index'
)
except Exception as e:
import pdb
pdb.set_trace()
When I inevitably hit the break point in the exception, the exception is as follows.
RequestError(400, u'SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[xPPw7B5wTUu50pxUGxFGIQ][test-index][0]: RemoteTransportException[[guts_search_dev2][inet[/158.171.65.122:9301]][search/phase/query]]; nested: SearchParseException[[test-index][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"range": {"Expiration": {"gte": "2015", "lte": "2017", "format": "yyyy"}}}}]]]; nested: QueryParsingException[[test-index] [range] query does not support [format]]; }{[cCrh939sR7yHdKgawRi6Sw][test-index][1]: SearchParseException[[test-index][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"range": {"Expiration": {"gte": "2015", "lte": "2017", "format": "yyyy"}}}}]]]; nested: QueryParsingException[[test-index] [range] query does not support [format]]; }]', {u'status': 400, u'error': u'SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[xPPw7B5wTUu50pxUGxFGIQ][test-index][0]: RemoteTransportException[[guts_search_dev2][inet[/158.171.65.122:9301]][search/phase/query]]; nested: SearchParseException[[test-index][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"range": {"Expiration": {"gte": "2015", "lte": "2017", "format": "yyyy"}}}}]]]; nested: QueryParsingException[[test-index] [range] query does not support [format]]; }{[cCrh939sR7yHdKgawRi6Sw][test-index][1]: SearchParseException[[test-index][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"range": {"Expiration": {"gte": "2015", "lte": "2017", "format": "yyyy"}}}}]]]; nested: QueryParsingException[[test-index] [range] query does not support [format]]; }]'})
Something about "query does not support [format]" appears to be a common string.
I thought this might be an issue with the way I have mapped my index initially, so I deleted and remapped as follows.
{
"test-index" : {
"mappings" : {
"properties" : {
"Expiration" : {
"type" : "date",
"format" : "yyyy"
}
}
}
}
}
Still no luck. I am trying to do my best to follow this guide for my range queries. I don't know what I am doing wrong. Please help.
UPDATE : I removed "format" from my query, so that it now looks like this.
'query' : {
'range' : {
'Expiration' : {
'gte' : '20160215',
'lte' : '20160415',
}
}
}
And I got the desired entry. But why can I not use "format" as a param?