查询ElasticSearch日期字段

时间:2019-06-10 09:48:04

标签: elasticsearch

我有一个带有某些日期字段的弹性搜索文档。我需要查询索引以提取日期早于指定日期的文档。       {         “ _index”:“ *********”,         “ _type”:“ **********”,         “ _id”:“ -2116171797”,         “ _source”:{

      "GRP": "UP1",
      "CTDATE": "2019-04-26 00:00:00"

    }

我尝试通过以下两种方式使用rangeQuery:

  1. QueryBuilder queryBuilder = QueryBuilders.boolQuery()。must(QueryBuilders.matchQuery(“ GRP”,“ UP1”))                     .filter(QueryBuilders.rangeQuery(“ CTDATE”)                             .lt(CTDATE1).format(“ yyyy-MM-dd HH:mm:ss”));

  2. QueryBuilder queryBuilder = QueryBuilders.boolQuery()。must(QueryBuilders.matchQuery(“ GRP”,“ UP1”))                     .must(QueryBuilders.rangeQuery(“ CTDATE”)                             .lt(CTDATE1).format(“ yyyy-MM-dd HH:mm:ss”));

它返回所有日期,与日期无关

0 个答案:

没有答案