# Sort by date not working

**URL:** <https://discuss.elastic.co/t/sort-by-date-not-working/121145>\
**Category:** Elasticsearch\
**Created:** [February 22, 2018, 11:50pm UTC](https://discuss.elastic.co/t/sort-by-date-not-working/121145 "2018-02-22T23:50:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kunde](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@kunde](https://discuss.elastic.co/u/kunde)\
**Post date:** [February 22, 2018, 11:50pm UTC](https://discuss.elastic.co/t/sort-by-date-not-working/121145/1 "2018-02-22T23:50:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 23, 2018, 4:39am UTC](https://discuss.elastic.co/t/sort-by-date-not-working/121145/2 "2018-02-23T04:39:56Z")

</div>

May be this could help:

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

---

<div class="post-metadata">

**Author:** ![kunde](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@kunde](https://discuss.elastic.co/u/kunde)\
**Post date:** [February 23, 2018, 6:47pm UTC](https://discuss.elastic.co/t/sort-by-date-not-working/121145/3 "2018-02-23T18:47:27Z")

</div>

Yes, it helps.

I was missing the "nested\_path" clause. That did the job.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 23, 2018, 6:51pm UTC](https://discuss.elastic.co/t/sort-by-date-not-working/121145/4 "2018-03-23T18:51:43Z")

</div>

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