1

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?

2
  • Please edit your question to show the full result of GET /{INDEX}/{TYPE}/_mapping .. I've had similar issues to this myself but it was usually when a date field was mistakenly mapped as a string. This does seem peculiar. Is any other filtering being applied when you use this sort? Commented Oct 12, 2017 at 5:08
  • I have tested in 2.4.4 and 5.5.0 and your configs and queries worked fine. Commented Oct 12, 2017 at 5:35

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.