# Sorting Multiple Nested Tuple Data

**URL:** <https://discuss.elastic.co/t/sorting-multiple-nested-tuple-data/35380>\
**Category:** Elasticsearch\
**Created:** [November 24, 2015, 5:35am UTC](https://discuss.elastic.co/t/sorting-multiple-nested-tuple-data/35380 "2015-11-24T05:35:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suresh\_Ghatuwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_ghatuwa/32/99976_2.png) [@Suresh\_Ghatuwa](https://discuss.elastic.co/u/Suresh_Ghatuwa)\
**Post date:** [November 24, 2015, 5:35am UTC](https://discuss.elastic.co/t/sorting-multiple-nested-tuple-data/35380/1 "2015-11-24T05:35:44Z")

</div>

i had data as Below:  
{  
"data": [  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"studentId": "1",  
"student": [  
{  
"program": "Computer",  
"type": "Student",  
"value": 100  
},  
{  
"program": "Architecture",  
"type": "Student",  
"value": 200  
},  
{  
"program": "Civil",  
"type": "Teacher",  
"value": 150  
}  
]  
}  
},  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "2",  
"\_score": 1,  
"\_source": {  
"studentId": "2",  
"student": [  
{  
"program": "Elex",  
"type": "Student",  
"value": 400  
},  
{  
"program": "Computer",  
"type": "Teacher",  
"value": 250  
},  
{  
"program": "Electronics",  
"type": "Student",  
"value": 150  
}  
]  
}  
},  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "3",  
"\_score": 1,  
"\_source": {  
"studentId": "3",  
"student": [  
{  
"program": "Computer",  
"type": "Teacher",  
"value": 500  
}  
]  
}  
}  
]  
}

Now, when i try to sort by program field i.e Nested field (student.program), it doesnot give accurate result. Please Suggest for that case.

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [November 24, 2015, 11:46am UTC](https://discuss.elastic.co/t/sorting-multiple-nested-tuple-data/35380/2 "2015-11-24T11:46:16Z")

</div>

Can you post the result you'd expect for clarification?

---

<div class="post-metadata">

**Author:** ![Suresh\_Ghatuwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_ghatuwa/32/99976_2.png) [@Suresh\_Ghatuwa](https://discuss.elastic.co/u/Suresh_Ghatuwa)\
**Post date:** [November 24, 2015, 12:34pm UTC](https://discuss.elastic.co/t/sorting-multiple-nested-tuple-data/35380/3 "2015-11-24T12:34:14Z")

</div>

DataSource:  
{  
"took": 30,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 3,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"studentId": "1",  
"student": [  
{  
"program": "Computer",  
"type": "Student",  
"value": 100  
},  
{  
"program": "Architecture",  
"type": "Student",  
"value": 200  
},  
{  
"program": "Civil",  
"type": "Teacher",  
"value": 150  
}  
]  
}  
},  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "2",  
"\_score": 1,  
"\_source": {  
"studentId": "2",  
"student": [  
{  
"program": "Elex",  
"type": "Student",  
"value": 400  
},  
{  
"program": "Computer",  
"type": "Teacher",  
"value": 250  
},  
{  
"program": "Electronics",  
"type": "Student",  
"value": 150  
}  
]  
}  
},  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "3",  
"\_score": 1,  
"\_source": {  
"studentId": "3",  
"student": [  
{  
"program": "Computer",  
"type": "Teacher",  
"value": 500  
}  
]  
}  
}  
]  
}  
}

Query I had Implement:  
{  
"size": 3,  
"sort": [  
{  
"student.program": {  
"order": "desc"  
}  
}  
],  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
}  
}  
}  
}

Expected Result;  
{  
"took": 13,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 3,  
"max\_score": null,  
"hits": [  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"studentId": "1",  
"student": [  
{  
"program": "Architecture",  
"type": "Student",  
"value": 200  
},  
{  
"program": "Civil",  
"type": "Teacher",  
"value": 150  
},  
{  
"program": "Computer",  
"type": "Student",  
"value": 100  
}  
]  
}  
},  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "2",  
"\_score": 1,  
"\_source": {  
"studentId": "2",  
"student": [  
{  
"program": "Computer",  
"type": "Teacher",  
"value": 250  
},  
{  
"program": "Electronics",  
"type": "Student",  
"value": 150  
},  
{  
"program": "Elex",  
"type": "Student",  
"value": 400  
}  
]  
}  
},  
{  
"\_index": "school",  
"\_type": "NestedSort",  
"\_id": "3",  
"\_score": 1,  
"\_source": {  
"studentId": "3",  
"student": [  
{  
"program": "Computer",  
"type": "Teacher",  
"value": 500  
}  
]  
}  
}  
]  
}  
}

---

<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, 11:36pm UTC](https://discuss.elastic.co/t/sorting-multiple-nested-tuple-data/35380/4 "2017-07-05T23:36:17Z")

</div>

Closed on July 5, 2017, 11:36pm UTC


