简体   繁体   English

日期范围查询Elasticsearch

[英]Date Range Query Elasticsearch

Below query when executed in Elasticsearch version 1.x 在Elasticsearch版本1.x中执行时的以下查询

Was considering documents created after 6/15/2016 that is documents which have time beyond 12 Am for the date 6/15/2016.It was considering documents till 6/15/2016 23:59:59.999 . 正在考虑在2016年6月15日之后创建的文档,即在2016年6月15日上午12点之后的文档。正在考虑文档到6/15/2016 23:59:59.999。

But with new version of ES 2.x the range query has stopped considering documents which have time beyond 12 Am for the date 6/15/2016. 但是,对于新版本的ES 2.x,范围查询已停止考虑2016年6月15日时间超过12 Am的文档。 Now It is considering documents till 6/14/2016 23:59:59.999. 现在它正在考虑直到6/14/2016 23:59:59.999的文件。

What exactly changed here? 这里到底发生了什么变化?

{
 "from": 0,
 "size": 10,
 "sort": [
   {
     "PRONumber.sort": {
       "order": "desc"
     }
   }
 ],
 "query": {
   "bool": {
     "must": [
       {
         "match": {
           "BOLNumber": {
             "query": "7861254",
             "analyzer": "gtz_search_analyzer",
             "operator": "and"
           }
         }
       },
       {
         "range": {
           "CreatedDate": {
             "gte": "1753-01-01",
             "lte": "2016-06-15"
           }
         }
       }
     ]
   }
 }
}

In elasticsearch 2.x for the query in the OP the upper-limit is 6/15/2016 00:00:00.000 and not 6/14/2016 23.59.59.999 . 在OP中查询的Elasticsearch 2.x中,上限为6/15/2016 00:00:00.000而不是6/14/2016 23.59.59.999
From the documentation it follows that you would need to explictly specify in the query to round-up by day as shown in the example below 文档中可以得出,您需要在查询中明确指定要按天round-up ,如下例所示

Example: 例:

{
 "from": 0,
 "size": 10,
 "sort": [
   {
     "PRONumber.sort": {
       "order": "desc"
     }
   }
 ],
 "query": {
   "bool": {
     "must": [
       {
         "match": {
           "BOLNumber": {
             "query": "7861254",
             "analyzer": "gtz_search_analyzer",
             "operator": "and"
           }
         }
       },
       {
         "range": {
           "CreatedDate": {
             "gte": "1753-01-01",
             "lte": "2016-06-15||/d"
           }
         }
       }
     ]
   }
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM