简体   繁体   English

日期排序弹性搜索

[英]date sorting elastic search

This is my field mapping for the date column in question:这是我对相关日期列的字段映射:

          "date": {
            "type": "date",
            "format": "YYYYMMDD"
          }

And here is my query:这是我的查询:

"sort": [{ "date" : { "order" : "desc" } }]

It's bringing back results and in the results there is a sorting element in the results array like the following:它正在返回结果,并且在结果数组中有一个排序元素,如下所示:

         "sort": [
          1548028800000
        ]

But its very clearly not sorting the sorting the dates properly.但它很明显没有对日期进行正确排序。 is there anything that I am doing wrong?有什么我做错了吗?

----- ANSWER ------- - - - 回答 - - - -

Changed the mapping to the following and it worked.将映射更改为以下内容并且它起作用了。

  "date": {
    "type": "date",
    "format": "yyyyMMdd"
  }

I think it is normal behavior.我认为这是正常的行为。 Sort values that are returned are all in milliseconds-since-the-epoch as the documentation says:正如文档所述,返回的排序值都以毫秒为单位:

https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html

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

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