【Elasticsearch】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]];


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]];

spring boot集成ES進行時間范圍查詢,報錯如下:

* 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]];

原因是由於:

  java傳入查詢參數,對於

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

 

解決方案:

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

如下:

  報錯代碼:

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

  正確方式:

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

 

 

具體可以參考:https://www.cnblogs.com/sxdcgaq8080/p/10411423.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM