I'm trying to port a Java application from Elasticsearch 2.4 to Elasticsearch 5.0.0, but I'm having trouble with range queries with Dates:
Currently the code looks like this:
SearchRequestBuilder requestBuilder = transportClient.prepareSearch("my_index_name");
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
...
if( searchParameters.getInboundDateFrom()!=null ) {
boolQueryBuilder.filter(QueryBuilders.rangeQuery( "inbound_date" ).gte( searchParameters.getInboundDateFrom()) );
boolQueryBuilder.filter(QueryBuilders.rangeQuery( "outbound_date" ).gte( searchParameters.getOutboundDateFrom()) );
}
...
requestBuilder.setQuery(boolQueryBuilder);
(The getter methods return a Date object and the fields are mapped as Date)
With Elasticsearch 5 I'm getting the following error (it worked with earlier versions):
SearchPhaseExecutionException occurred during search execution: Failed to execute phase [query_fetch], all shards failed; shardFailures {[SrOiHGeDQ0y4GhP0TTPaRw][messages][0]: RemoteTransportException[[local_node][127.0.0.1:9300][indices:data/read/search[phase/query+fetch]]]; nested: ElasticsearchParseException[failed to parse date field [Mon Oct 24 00:00:00 CEST 2016] with format [strict_date_optional_time||epoch_millis]]; nested: IllegalArgumentException[Parse failure at index [0] of [Mon Oct 24 00:00:00 CEST 2016]]; }
One thing is very strange: When I write the generated JSON query to the logfiles with requestBuilder.toString() the query looks good and works fine when I execute it via REST API:
{
"from" : 0,
"size" : 100,
"query" : {
"bool" : {
"filter" : [
{
"range" : {
"inbound_date" : {
"from" : "2016-10-23T22:00:00.000Z",
"to" : null,
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
{
"range" : {
"outbound_date" : {
"from" : "2016-10-23T22:00:00.000Z",
"to" : null,
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"ext" : { }
}
Also searching for other parameters in the application that are not Dates works fine.
Is this a bug or am I doing something wrong?