# How to sort by different fields in different indices

**URL:** <https://discuss.elastic.co/t/how-to-sort-by-different-fields-in-different-indices/237065>\
**Category:** Elasticsearch\
**Created:** [June 15, 2020, 5:30am UTC](https://discuss.elastic.co/t/how-to-sort-by-different-fields-in-different-indices/237065 "2020-06-15T05:30:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muna](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@Muna](https://discuss.elastic.co/u/Muna)\
**Post date:** [June 15, 2020, 5:30am UTC](https://discuss.elastic.co/t/how-to-sort-by-different-fields-in-different-indices/237065/1 "2020-06-15T05:30:11Z")

</div>

Hi,  
below is my query . here i want to sort the 'abc\_class' by it's "classId" and also a different sort for another Index.

please advise is there any approach to achieve this.

---

<div class="post-metadata">

**Author:** ![defalt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defalt/32/71379_2.png) [@defalt](https://discuss.elastic.co/u/defalt)\
**Post date:** [June 15, 2020, 2:45pm UTC](https://discuss.elastic.co/t/how-to-sort-by-different-fields-in-different-indices/237065/2 "2020-06-15T14:45:53Z")

</div>

Error 404: No Query found.

---

<div class="post-metadata">

**Author:** ![Muna](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@Muna](https://discuss.elastic.co/u/Muna)\
**Post date:** [June 16, 2020, 4:40am UTC](https://discuss.elastic.co/t/how-to-sort-by-different-fields-in-different-indices/237065/3 "2020-06-16T04:40:32Z")

</div>

Below query i have tried and it's failing : -

GET abc\_class,bad/\_search  
{  
"aggs": {  
"abc\_class,bad": {  
"terms": {  
"field": "{\_index}"  
}  
}  
},  
"sort": [  
{  
"abc\_class.classId": {  
"order": "desc"  
}  
}  
],  
"query": {  
"bool": {  
"should": [  
{  
"bool": {  
"filter": [  
{  
"terms": {  
"\_index": [  
"abc\_class"  
]  
}  
}  
]  
}  
},  
{  
"bool": {  
"filter": [  
{  
"terms": {  
"\_index": [  
"bad"  
]  
}  
}  
]  
}  
}  
]  
}  
}  
}

---

<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 14, 2020, 4:40am UTC](https://discuss.elastic.co/t/how-to-sort-by-different-fields-in-different-indices/237065/4 "2020-07-14T04:40:41Z")

</div>

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