Elasticsearch sort by dates is incorrect

不问归期 提交于 2019-12-11 17:39:28

问题


In the Elasticsearch documents, there is a field createdAt defined as follows:

"createdAt" : {
            "type" : "date",
            "format" : "YYYY-MM-DD HH:mm:ss"
          }

When trying to sort the records by date, I get the following order:

  1. 2019-10-01 07:46:22
  2. 2019-10-01 09:06:28
  3. 2019-10-01 10:39:43
  4. 2019-10-01 11:35:00
  5. 2019-10-02 12:27:40
  6. 2019-10-04 00:50:00
  7. 2019-07-05 09:57:15
  8. 2019-11-05 22:58:00
  9. 2019-06-06 12:39:49
  10. 2019-09-06 19:46:00

Does anyone know why the dates are not sorted correctly?


回答1:


Your format is wrong, it should be:

"createdAt" : {
        "type" : "date",
        "format" : "yyyy-MM-dd HH:mm:ss"
      }

Lowercase y and d



来源:https://stackoverflow.com/questions/58993167/elasticsearch-sort-by-dates-is-incorrect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!