# Sorting breaks aggregation

**URL:** https://discuss.elastic.co/t/sorting-breaks-aggregation/182867
**Category:** Elasticsearch
**Created:** [May 27, 2019, 9:06am UTC](https://discuss.elastic.co/t/sorting-breaks-aggregation/182867 "2019-05-27T09:06:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Junker](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Junker](https://discuss.elastic.co/u/Junker)
#### Post date: [May 27, 2019, 9:06am UTC](https://discuss.elastic.co/t/sorting-breaks-aggregation/182867/1 "2019-05-27T09:06:29Z")

</div>

I use this query to get search hits and the count of search hits across multiple indices:

```auto
/index1,index2/_search
{
  "query":{
    "query_string":{
      "query":"*"
    }
  },
  "aggs":{
    "group_by_index":{
      "terms":{
        "field":"_index",
        "min_doc_count":0
      }
    }
  },
  "post_filter":{
    "terms":{
      "_index":"index1"
    }
  },
  "sort":{
    "my_field":"asc"
  }
}

```

The problem is if I sort on a field (my\_field) that only exist in `index1`, the aggregation will only give me the hits count of `index1`, and not `index2`.

I thought the aggregation would work regardless of what sorting I have specified?

Using Elasticsearch 6.4

---

<div class="post-metadata">

### Author: ![Junker](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Junker](https://discuss.elastic.co/u/Junker)
#### Post date: [May 27, 2019, 9:55am UTC](https://discuss.elastic.co/t/sorting-breaks-aggregation/182867/2 "2019-05-27T09:55:43Z")

</div>

Solved it by using [unmapped\_type](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-request-sort.html#_ignoring_unmapped_fields)

---

<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: [June 24, 2019, 9:55am UTC](https://discuss.elastic.co/t/sorting-breaks-aggregation/182867/3 "2019-06-24T09:55:58Z")

</div>

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