# Getting nested document in sorted order

**URL:** <https://discuss.elastic.co/t/getting-nested-document-in-sorted-order/58397>\
**Category:** Elasticsearch\
**Created:** [August 18, 2016, 8:31pm UTC](https://discuss.elastic.co/t/getting-nested-document-in-sorted-order/58397 "2016-08-18T20:31:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carolingfish](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@carolingfish](https://discuss.elastic.co/u/carolingfish)\
**Post date:** [August 18, 2016, 8:31pm UTC](https://discuss.elastic.co/t/getting-nested-document-in-sorted-order/58397/1 "2016-08-18T20:31:56Z")

</div>

Suppose I have following mapping.

```
mappings:
  grocery_store:
    properties:
      business_id:
        type: integer
        store: true
    fruits:
      type: nested
      properties:
        name:
          type: string
          store: true
          index: not_analyzed
        price:
          type: double
          store: true
        weight:
          type: double
          store: true

```

Suppose I want to get list of fruits of a specific grocery store (i already know the business\_id) ordered by the price of the fruit. Is such query possible?  
Also, the nested document fruit may have more properties in the future and I would want to get list of the fruit of specific grocery store, ordered by more complicated logic, leveraging on elastic search engine.  
I've seen a lot of documentation on how to order grocery\_store by aggregate value of nested items, but I haven't seen what I want although it seems to be simpler than the prior.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 19, 2016, 9:31am UTC](https://discuss.elastic.co/t/getting-nested-document-in-sorted-order/58397/2 "2016-08-19T09:31:46Z")

</div>

This isn't possible, elasticsearch uses documents as a basic piece of information, it cannot do much at the field level.

---

<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 5, 2017, 10:26pm UTC](https://discuss.elastic.co/t/getting-nested-document-in-sorted-order/58397/3 "2017-07-05T22:26:42Z")

</div>


