# Multi-index query and sorting by range per index

**URL:** <https://discuss.elastic.co/t/multi-index-query-and-sorting-by-range-per-index/108114>\
**Category:** Elasticsearch\
**Created:** [November 17, 2017, 10:50am UTC](https://discuss.elastic.co/t/multi-index-query-and-sorting-by-range-per-index/108114 "2017-11-17T10:50:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaKro](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@MaKro](https://discuss.elastic.co/u/MaKro)\
**Post date:** [November 17, 2017, 10:50am UTC](https://discuss.elastic.co/t/multi-index-query-and-sorting-by-range-per-index/108114/1 "2017-11-17T10:50:58Z")

</div>

Hi.

I have multiple indices. I would like to execute search against them, and first of all:

- Group by index
- Sort results in the scope of the index by score.

I'm wondering if the better idea is to send one query per index or to execute multi-index query. I'm not sure if it is even possible to get what I want using the latter one.

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 22, 2017, 10:54pm UTC](https://discuss.elastic.co/t/multi-index-query-and-sorting-by-range-per-index/108114/2 "2017-11-22T22:54:49Z")

</div>

A single multi-index query is definitely possible. Use `_index` to use the index name as the primary sort criterion, and use `_score` to sort on score within each index:

```
GET _search
{
  "sort": [
    {
      "_index": {
        "order": "asc"
      }
    },
    "_score"
  ]
}
```

---

<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 20, 2017, 10:54pm UTC](https://discuss.elastic.co/t/multi-index-query-and-sorting-by-range-per-index/108114/3 "2017-12-20T22:54:53Z")

</div>

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