zoukankan      html  css  js  c++  java
  • 【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

  • 相关阅读:
    使用IDENTITY列属性和Sequence对象
    使用OFFSET-FETCH进行数据过滤
    SQL 插入语句汇总
    建立&修改视图
    Centos 7.x 搭建 Zabbix3.4
    RDS 导出Mysqlbinlog_二进制日志
    Yac
    云服务器漏洞更新
    Centos 内存释放
    Centos 安装 Htop
  • 原文地址:https://www.cnblogs.com/sxdcgaq8080/p/10413121.html
Copyright © 2011-2022 走看看