# Multi-level nested sort in elasticsearch v5.5

**URL:** <https://discuss.elastic.co/t/multi-level-nested-sort-in-elasticsearch-v5-5/146235>\
**Category:** Elasticsearch\
**Created:** [August 27, 2018, 7:37pm UTC](https://discuss.elastic.co/t/multi-level-nested-sort-in-elasticsearch-v5-5/146235 "2018-08-27T19:37:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xiaofeng\_Zhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xiaofeng_zhan/32/34448_2.png) [@Xiaofeng\_Zhan](https://discuss.elastic.co/u/Xiaofeng_Zhan)\
**Post date:** [August 27, 2018, 7:37pm UTC](https://discuss.elastic.co/t/multi-level-nested-sort-in-elasticsearch-v5-5/146235/1 "2018-08-27T19:37:50Z")

</div>

Hello,  
I am using elasticsearch v5.5, and trying to build a sort query, sorted by 3 level nested field.  
In [https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-sort.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-sort.html), there is an example on sorting by 2 level nested field.

```
POST /_search
{
   "query" : {
      "term" : { "product" : "chocolate" }
   },
   "sort" : [
       {
          "offer.price" : {
             "mode" : "avg",
             "order" : "asc",
             "nested_path" : "offer",
          }
       }
    ]
}

```

And to convert to Java, it is like  
FieldSortBuilder sortBuilder = new FieldSortBuilder("offer.price").order(SortOrder.ASC)  
.setNestedPath("offer");

What if I want to sort by 3 level nested field (say: parent.child.age) in elasticsearch v5.5? And what is the corresponding Java builder format?

Thanks!

P.S. I saw multi-level nested sorting example (sort by parent.child.age, which is a 3 level sort) on elasticsearch v6.1 and onward. Can you also provide an example on v5.5

---

<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:** [September 24, 2018, 7:37pm UTC](https://discuss.elastic.co/t/multi-level-nested-sort-in-elasticsearch-v5-5/146235/2 "2018-09-24T19:37:52Z")

</div>

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