# Sorting nested documents by nested field

**URL:** <https://discuss.elastic.co/t/sorting-nested-documents-by-nested-field/24806>\
**Category:** Elasticsearch\
**Created:** [July 2, 2015, 1:34pm UTC](https://discuss.elastic.co/t/sorting-nested-documents-by-nested-field/24806 "2015-07-02T13:34:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spencerapplegate](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spencerapplegate/32/3555_2.png) [@spencerapplegate](https://discuss.elastic.co/u/spencerapplegate)\
**Post date:** [July 2, 2015, 1:34pm UTC](https://discuss.elastic.co/t/sorting-nested-documents-by-nested-field/24806/1 "2015-07-02T13:34:21Z")

</div>

I have unit\_type documents that have nested rent documents. The rent documents have a price property and an effective\_date property. I want to filter unit\_types and sort the nested rent documents by their effective date. The rent documents are **not** stored in sorted order currently. If this cannot be done with a nested data type, can it be done with parent/child?

I am using v1.6  
Here is my index mapping:

```json
{
  "unit_types_v1": {
    "aliases": {
      "unit_types": {}
    },
    "mappings": {
      "unit_type": {
        "properties": {
          "id": {
            "type": "long"
          },
          "property_id": {
            "type": "long"
          },
          "rents": {
            "type": "nested",
            "properties": {
              "effective_date": {
                "type": "date",
                "format": "dateOptionalTime"
              },
              "id": {
                "type": "long"
              },
              "price": {
                "type": "double"
              },
              "unit_type_id": {
                "type": "long"
              }
            }
          }
        }
      }
    }
  }
}

```

---

<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:** [July 6, 2017, 12:03am UTC](https://discuss.elastic.co/t/sorting-nested-documents-by-nested-field/24806/2 "2017-07-06T00:03:58Z")

</div>


