Date field Sorting in ElasticSearch


(Paddy Mahadeva) #1

Hi,

I have an index & type in elasticsearch which has a field mapping

,
"data_received_on": {
"type": "date",
"format": "YYYY-MM-DD"
},

I need to get the newest 10 records and i have about 5000 records that is spread out over the last 1 month.

ie. date_received_on field has values ranging from 2017-09-01 to 2017-09-30.

But my sorting does not give me the records in the right order when I order by this date. When I order by a number or string field it works well, but the moment I use a date field, it behaves unpredictably.

my sort condition is simple

"sort" : {
"data_received_on" : {
"order" : "desc"
}
}

What do I need to do differently to get the date field based sorting right?


(Paddy Mahadeva) #2

I found the issue.

The reason was my date format being YYYY-MM-DD. It should have been yyyy-MM-dd. Fixing that solved the problem


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.