# Change the shards for index and terms aggregation query

**URL:** <https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467>\
**Category:** Elasticsearch\
**Created:** [May 23, 2019, 2:32pm UTC](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467 "2019-05-23T14:32:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![klaus82](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klaus82/32/45900_2.png) [@klaus82](https://discuss.elastic.co/u/klaus82)\
**Post date:** [May 23, 2019, 5:04pm UTC](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467/5 "2019-05-23T17:04:59Z")

</div>

We have indexed a lot of urls, and for each url we also have title and a metric. We need to perform a query aggregation over url and title.keyword and sum of metric and take the top 10 sof those buckets.  
The aggs portion of our query is the following:

```
"aggs": {
    "by_url_and_title": {
      "composite": {
        "size": 13000,
        "sources": [
          {
            "final_url": {
              "terms": {
                "field": "url"
              }
            }
          },
          {
            "title": {
              "terms": {
                "field": "title.keyword"
              }
            }
          }
        ]
      },
      "aggs": {
        "sum_metric": {
          "sum": {
            "field": "metric"
          }
        },
        "metric_sort": {
          "bucket_sort": {
            "sort": [
              {
                "sum_metric": {
                  "order": "desc"
                }
              }
            ],
            "size": 10
          }
        }
      }
    }

```

If we move from 1 shard to 2 shard we could have different result.

For the "size" field of this query I posted another question here:

> [@Best practice for aggs query](https://discuss.elastic.co/t/best-practice-for-aggs-query/182466):
>
> In aggs query, if I want to have: "doc\_count\_error\_upper\_bound" : 0, "sum\_other\_doc\_count" : 0, or very small. Is a good practice to run before, the aggs query, another query to have the number of hits and the set this value in the "size" aggs query field? Or there is a better strategy?

Do you have any suggestions?  
Thanks in advance.

---

_[View the full topic](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467)._
