问题
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:
- 2019-10-01 07:46:22
- 2019-10-01 09:06:28
- 2019-10-01 10:39:43
- 2019-10-01 11:35:00
- 2019-10-02 12:27:40
- 2019-10-04 00:50:00
- 2019-07-05 09:57:15
- 2019-11-05 22:58:00
- 2019-06-06 12:39:49
- 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