Sort by date not working


(Eduardo Patron) #1

I have a nested date field like this:

{
    "nestedField": {
        "type": "nested",
        "properties": {
             "sellableDate": {
                 "properties": {
                     "US": {
                         "type": "date",
                         "format": "MM/dd/yyy"
                     }
                 }
            }
        }
    }
}

when I try to sort using:

{
    "sort": {
        "nestedField.sellableDate.US": {
            "order": "desc"
        }
    }
}

it doesn't work. The five results are sorted like this:

"sellableDate": { "US": "06/28/2017"}
"sellableDate": { "US": "06/28/2017"}
"sellableDate": { "US": "01/01/2001"}
"sellableDate": { "US": "06/28/2017"}
"sellableDate": { "US": "06/28/2017"}

The third results is odd. It's like it didn't applied any sorting at all. Even if I change the order of sorting, it does nothing.

EDIT: If I move this property at top level (not inside nested) it works. Any idea why this happens?


(David Pilato) #2

May be this could help:

https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-request-sort.html#nested-sorting


(Eduardo Patron) #3

Yes, it helps.

I was missing the "nested_path" clause. That did the job.


(system) #4

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