Change the shards for index and terms aggregation query

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?

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

Thank you @dadoonet

it was what I feared

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.

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:

Do you have any suggestions?
Thanks in advance.

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

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

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