# 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:** 8\
**Page:** 1

<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, 2:32pm UTC](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467/1 "2019-05-23T14:32:30Z")

</div>

Currently, I have two nodes on Elastic Cloud and my indexes have one shard and one replica each.  
If I'd increase to 3 the number of nodes and I'd reindex my indexes with two shards and one replica, could I have a different result for term aggregations after this change?

---

<div class="post-metadata">

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

</div>

> [@klaus82](#):
>
> could I have a different result for term aggregations after this change?

Yes. Moving from 1 shard to 2 shards could have an effect on Terms agg.  
See [Terms aggregation | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-approximate-counts)

---

<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, 3:27pm UTC](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467/3 "2019-05-23T15:27:03Z")

</div>

Thank you @dadoonet

it was what I feared

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 23, 2019, 3:50pm UTC](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467/4 "2019-05-23T15:50:58Z")

</div>

But what is the actual problem? I mean there are some ways to deal with that depending on the use case, like using routing keys.

---

<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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 24, 2019, 7:55am UTC](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467/6 "2019-05-24T07:55:39Z")

</div>

As you are sorting by the sum, I don't think that will be an issue but I might be wrong. @jimczi WDYT?

---

<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 29, 2019, 6:45am UTC](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467/7 "2019-05-29T06:45:02Z")

</div>

Hello @dadoonet @jimczi,  
any update about this topic?

---

<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 26, 2019, 6:45am UTC](https://discuss.elastic.co/t/change-the-shards-for-index-and-terms-aggregation-query/182467/8 "2019-06-26T06:45:08Z")

</div>

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