# Composite aggs with an after key in a large index take forever

**URL:** <https://discuss.elastic.co/t/composite-aggs-with-an-after-key-in-a-large-index-take-forever/262412>\
**Category:** Elasticsearch\
**Created:** [January 27, 2021, 7:48pm UTC](https://discuss.elastic.co/t/composite-aggs-with-an-after-key-in-a-large-index-take-forever/262412 "2021-01-27T19:48:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benlin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benlin/32/83007_2.png) [@benlin](https://discuss.elastic.co/u/benlin)\
**Post date:** [January 27, 2021, 7:48pm UTC](https://discuss.elastic.co/t/composite-aggs-with-an-after-key-in-a-large-index-take-forever/262412/1 "2021-01-27T19:48:34Z")

</div>

I'm running into an issue where composite aggs with an after key seem to run forever on large indices (several 100m docs) when the same agg without an after key runs just fine.

So this runs in seconds:

```auto
{
  "size": 0, 
  "aggs": {
    "test": {
      "composite": {
        "sources": [{"test": {"terms": {"field": "field1"}}}],
        "size": 1
      }
    }
  }
}

```

But when using the after key returned from that query, it seems to run ~~forever~~ edit: did more testing and found that it did actually return after ~4.5 minutes

```auto
{
  "size": 0, 
  "aggs": {
    "test": {
      "composite": {
        "sources": [{"test": {"terms": {"field": "field1"}}}],
        "after": {"test": value1},
        "size": 1
      }
    }
  }
}

```

This issue doesn't seem to happen for smaller indices. Any ideas what could be causing this? Would greatly appreciate any help 🙏

---

<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:** [February 24, 2021, 7:48pm UTC](https://discuss.elastic.co/t/composite-aggs-with-an-after-key-in-a-large-index-take-forever/262412/2 "2021-02-24T19:48:39Z")

</div>

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