简体   繁体   English

Elasticsearch 无法按日期时间范围过滤

[英]Elasticsearch can not filter by datetime range

This might be a silly question but I could not manage to filter elasticsearch indexes by a datetime field.这可能是一个愚蠢的问题,但我无法通过日期时间字段过滤弹性搜索索引。 I must be missing something.我肯定错过了什么。

This is the mapping:这是映射:

"created_at": {
    "type": "date",
    "format": "strict_date_optional_time||epoch_millis"
},

This is what I got:这是我得到的:

{
    "_index": "myindex",
    "_type": "myindextype",
    "_id": "21c",
    "_score": 1,
    "_source": {
      "code": "21c",
      "name": "hello",
      ...
      "created_at": "2015-04-30T13:10:50.107769Z"
    }
 },

With this query:有了这个查询:

"query": {
  "filtered": {
    "query": {},
    "filter": {
      "range": {
        "created_at": {
          "gte": "2015-05-02T13:10:50.107769Z"
          "format": "strict_date_optional_time||epoch_millis"
}}}}}

I would expect to filter out the entry above.我希望过滤掉上面的条目。 But it returns nothing.但它什么都不返回。

Is there a problem with time format?时间格式有问题吗? Because it is directly coming from Django Rest Framework's serializers .因为它直接来自 Django Rest Framework 的序列化程序 They claim that it is ISO 8601 format and elasticsearch claims the same .他们声称它是 ISO 8601 格式并且 elasticsearch 声称相同

I would also like to filter them out by a simpler date like "2015-05-02".我还想通过更简单的日期(如“2015-05-02”)过滤掉它们。

I am stuck.我被困住了。 Thank you in advance.先感谢您。

Edit: It does not matter whatever i write into the range filter.编辑:无论我写什么到范围过滤器都没有关系。 It always return all the entries.它总是返回所有条目。

This worked.这奏效了。 I tried a lot of different things and lost my way at some point.我尝试了很多不同的东西,但在某些时候迷失了方向。

{
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "created_at": {
            "gte": "2015-05-02"
          }
        }
      }
    }
  }
}

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

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