Range query with dates not working any more with ES 5.0.0 using Java API


#1

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?


(dawi) #2

We are currently in the process of upgrading from 2.4 to 5.0.0 as well and we also had problems with range queries with dates. We were able to fix this by ensuring that what we index and what we use for search is plain java.util.Date. In 2.4 and before it was no problem to use java.sql.Date and java.sql.Timestamp as well.


#3

Thanks dawi for your input! However the objects are java.util.Date.

But your comment gave me the idea to convert the date objects to String ( with .Instant.toString() ). And this seems to work now. But I'm still not sure if this is a bug or the intended behavior.


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.