# Help with aggregation performance improvement for nested aggregations

**URL:** <https://discuss.elastic.co/t/help-with-aggregation-performance-improvement-for-nested-aggregations/223524>\
**Category:** Elasticsearch\
**Created:** [March 13, 2020, 2:28pm UTC](https://discuss.elastic.co/t/help-with-aggregation-performance-improvement-for-nested-aggregations/223524 "2020-03-13T14:28:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankkoornstra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frankkoornstra/32/6780_2.png) [@frankkoornstra](https://discuss.elastic.co/u/frankkoornstra)\
**Post date:** [March 13, 2020, 2:28pm UTC](https://discuss.elastic.co/t/help-with-aggregation-performance-improvement-for-nested-aggregations/223524/1 "2020-03-13T14:28:19Z")

</div>

I'm trying to find out what the underlying problem for some of my searches' and aggregations' performance is but I can't seem to find any documentation on what the terms in the profiling breakdown mean and what I can do to improve performance. Can you point me somewhere where I can find out what the following things mean (and maybe how to improve on them):

For search:

- score
- build\_scorer\_count
- match\_count
- create\_weight
- next\_doc
- match
- create\_weight\_count
- next\_doc\_count
- score\_count
- build\_scorer
- advance
- advance\_count

For aggregations:

- reduce
- build\_aggregation
- build\_aggregation\_count
- initialize
- initialize\_count
- reduce\_count
- collect
- collect\_count

[Update]  
Aaaaaand of course, now I find [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-profile.html) 🤦‍♂️

Ok, now I can at least be more specific because it doesn't really help me that much for my specific problem 🙂

Any idea why the `collect` phase of this aggregator takes so long? Also, is this CPU/Memory/IO bound?

```json
{
  "type": "NestedAggregator",
  "description": "customVariables",
  "time_in_nanos": 10816958154,
  "breakdown": {
    "reduce": 0,
    "build_aggregation": 36583,
    "build_aggregation_count": 1,
    "initialize": 15959,
    "initialize_count": 1,
    "reduce_count": 0,
    "collect": 10816896702,
    "collect_count": 8908
  },
  "children": [
    {
      "type": "GlobalOrdinalsStringTermsAggregator",
      "description": "context",
      "time_in_nanos": 10410704736,
      "breakdown": {
        "reduce": 0,
        "build_aggregation": 33198,
        "build_aggregation_count": 1,
        "initialize": 2215,
        "initialize_count": 1,
        "reduce_count": 0,
        "collect": 10410563544,
        "collect_count": 105777
      }
    }
  ]
}

```

With this query:

```json
{
  "profile": true,
  "size": 0,
  "aggregations": {
    "customVariables": {
      "nested": {
        "path": "customer_input.context"
      },
      "aggregations": {
        "context": {
          "terms": {
            "field": "customer_input.context.key",
            "size": 100
          }
        }
      }
    }
  }
}

```

And this mapping:

```json
{
  "properties": {
    "customer_input": {
      "dynamic": "strict",
      "properties": {
        "context": {
          "type": "nested",
          "dynamic": "strict",
          "properties": {
            "key": {
              "type": "keyword",
              "eager_global_ordinals": true,
              "ignore_above": 200
            }
          }
        }
      }
    }
  }
}

```

It's usually just a single shard that is slow.

---

<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:** [April 10, 2020, 2:45pm UTC](https://discuss.elastic.co/t/help-with-aggregation-performance-improvement-for-nested-aggregations/223524/4 "2020-04-10T14:45:10Z")

</div>

Closed on April 10, 2020, 2:45pm UTC

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