Thanigaivelan
Thanigaivelan

Reputation: 175

Sorting in Elastic Search

I am using Elastic search for searching data. I want to sort it by date. Below is my URL search link:

https://70e97e980f1ff0674f3524a35af2b603.us-east-1.aws.found.io:9243/episode/_search?q=news&size=10

I want to sort by date (pub date). How I can do it? When I tried the below code, it is not working.

https://70e97e980f1ff0674f3524a35af2b603.us-east-1.aws.found.io:9243/episode/_search?q=news&size=10&sort=pubdate&order:desc

How do I order by descending date?

Upvotes: 0

Views: 277

Answers (1)

GoR
GoR

Reputation: 121

Some of your documents does not have pubdate defined and ElasticSearch will not sort on null values.

Use this:

"sort" : [
       { "pubdate": {"order" : "desc" , "missing" : "_last" , "ignore_unmapped" : true} }
]

Upvotes: 1

Related Questions