# About Nested Script Sort

**URL:** <https://discuss.elastic.co/t/about-nested-script-sort/67748>\
**Category:** Elasticsearch\
**Created:** [December 1, 2016, 11:11am UTC](https://discuss.elastic.co/t/about-nested-script-sort/67748 "2016-12-01T11:11:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Leonard](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@Richard\_Leonard](https://discuss.elastic.co/u/Richard_Leonard)\
**Post date:** [December 1, 2016, 11:11am UTC](https://discuss.elastic.co/t/about-nested-script-sort/67748/1 "2016-12-01T11:11:52Z")

</div>

How to Combine Script Sort and Nested Search and Sort

I know how to search a nested object and also how to sort by script sort.  
How could they work together?....

Say I have doc as following  
{  
"id": 1,  
"tag": [{ "desc": "a", "weight": 0.8 }, { "desc": "b", "weight": 0.6 }, { "desc": "c", "weight": 0.4 }]  
}

{  
"id": 2,  
"tag": [{ "desc": "a", "weight": 0.4 }, { "desc": "c", "weight": 0.7 }]  
}

{  
"id": 3,  
"tag": [{ "desc": "a", "weight": 2.0 }]  
}

I want to search for tag [a or c] and sort by sum of their weight  
So I want  
doc 3 \> doc 1 \> doc 2,  
with weight is 2.0 \> 0.8+0.4 \> 0.4+0.7

How can I achieve that?

---

<div class="post-metadata">

**Author:** ![Richard\_Leonard](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@Richard\_Leonard](https://discuss.elastic.co/u/Richard_Leonard)\
**Post date:** [December 2, 2016, 6:13am UTC](https://discuss.elastic.co/t/about-nested-script-sort/67748/2 "2016-12-02T06:13:35Z")

</div>

Anyone Help?

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [December 2, 2016, 8:18am UTC](https://discuss.elastic.co/t/about-nested-script-sort/67748/3 "2016-12-02T08:18:54Z")

</div>

Have a look at this:

[https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-sorting.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-sorting.html)

---

<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:** [December 30, 2016, 8:18am UTC](https://discuss.elastic.co/t/about-nested-script-sort/67748/4 "2016-12-30T08:18:58Z")

</div>

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