# Bucket aggregation in string terms is too slow

**URL:** <https://discuss.elastic.co/t/bucket-aggregation-in-string-terms-is-too-slow/129394>\
**Category:** Elasticsearch\
**Created:** [April 25, 2018, 2:58am UTC](https://discuss.elastic.co/t/bucket-aggregation-in-string-terms-is-too-slow/129394 "2018-04-25T02:58:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pakein](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@pakein](https://discuss.elastic.co/u/pakein)\
**Post date:** [April 25, 2018, 2:58am UTC](https://discuss.elastic.co/t/bucket-aggregation-in-string-terms-is-too-slow/129394/1 "2018-04-25T02:58:38Z")

</div>

In GlobalOrdinalsStringTermsAggregator

```
for (long globalTermOrd = 0; globalTermOrd < valueCount; ++globalTermOrd) 

```

why not loop with bucketOrds，bucketOrds size is much small than valueCount

When there are levels of aggregation， parent agg and valueCount both more than 100 thousands bucket. This situation is very very scary。

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [April 25, 2018, 8:31am UTC](https://discuss.elastic.co/t/bucket-aggregation-in-string-terms-is-too-slow/129394/2 "2018-04-25T08:31:42Z")

</div>

> [@pakein](#):
>
> GlobalOrdinalsStringTermsAggregator

Good spot. It looks like the code is designed to cater for both "normal" use and what many might consider to be an edge-case - where `min_doc_count` is set to zero. In the zero-match scenario the user wants ALL buckets, not just those that matched the query, hence we iterate over all terms.

Can you [open an issue](https://github.com/elastic/elasticsearch/issues)?

---

<div class="post-metadata">

**Author:** ![pakein](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@pakein](https://discuss.elastic.co/u/pakein)\
**Post date:** [April 25, 2018, 9:40am UTC](https://discuss.elastic.co/t/bucket-aggregation-in-string-terms-is-too-slow/129394/3 "2018-04-25T09:40:02Z")

</div>

thanks，i open issue #30117

if min\_doc\_count = 0 , it seems there is a bug. the search result is wrong

mapping:

```
tags: {
    type: nested
    name: keyword
    value: keyword
}

```

my query is

```
  nested {
       filter {
            terms {
                 reversed_nested {
                     nested {
                          filter {
                              terms {}
                          }
                     }
                 }
            }
       }
  }
```

---

<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:** [May 23, 2018, 9:47am UTC](https://discuss.elastic.co/t/bucket-aggregation-in-string-terms-is-too-slow/129394/4 "2018-05-23T09:47:28Z")

</div>

Closed on May 23, 2018, 9:47am UTC

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