【Elasticsearch】ES中時間查詢報錯:Caused by: ElasticsearchParseException[failed to parse date field [Sun Dec

ES中時間查詢報錯:Caused by: ElasticsearchParseException[failed to parse date field [Sun Dec 31 16:00:00 UTC 2017] with format [yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis]];html

spring boot集成ES進行時間範圍查詢,報錯以下:java

* Failed to execute phase [query], all shards failed; shardFailures {[ZVpk9AuzQdCYQrkIIseGxQ][swapping][0]: RemoteTransportException[[ZVpk9Au][172.17.0.3:9300][indices:data/read/search[phase/query]]]; nested: ElasticsearchParseException[failed to parse date field [Sun Dec 31 16:00:00 UTC 2017] with format [yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis]]; nested: IllegalArgumentException[Parse failure at index [0] of [Sun Dec 31 16:00:00 UTC 2017]]; }{[ZVpk9AuzQdCYQrkIIseGxQ][swapping][1]: RemoteTransportException[[ZVpk9Au][172.17.0.3:9300][indices:data/read/search[phase/query]]]; nested: ElasticsearchParseException[failed to parse date field [Sun Dec 31 16:00:00 UTC 2017] with format [yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis]]; nested: IllegalArgumentException[Parse failure at index [0] of [Sun Dec 31 16:00:00 UTC 2017]]; }
* Caused by: ElasticsearchParseException[failed to parse date field [Sun Dec 31 16:00:00 UTC 2017] with format [yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis]];

緣由是因爲:spring

  java傳入查詢參數,對於app

  ES中,index的mapping設置的時間字段的格式是不能解析的。才致使了報了上面這個錯誤。ui

 

解決方案:spa

  只須要在java中,將查詢的時間字段由傳入時間對象  變成   傳入時間戳。便可!!code

以下:orm

  報錯代碼:htm

QueryBuilder queryBuilder = QueryBuilders.rangeQuery("buildDate").from(builder.getBuildDate());

  正確方式:對象

QueryBuilder queryBuilder = QueryBuilders.rangeQuery("buildDate").from(builder.getBuildDate().getTime());

 

 

具體能夠參考:http://www.javashuo.com/article/p-qybptmvv-bm.html

相關文章
相關標籤/搜索