# How to extend terms aggregation in elasticsearch

**URL:** https://discuss.elastic.co/t/how-to-extend-terms-aggregation-in-elasticsearch/20298
**Category:** Elasticsearch
**Created:** [October 17, 2014, 4:11am UTC](https://discuss.elastic.co/t/how-to-extend-terms-aggregation-in-elasticsearch/20298 "2014-10-17T04:11:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yang\_ming](https://avatars.discourse-cdn.com/v4/letter/y/ecb155/32.png) [@yang\_ming](https://discuss.elastic.co/u/yang_ming)
#### Post date: [October 17, 2014, 4:11am UTC](https://discuss.elastic.co/t/how-to-extend-terms-aggregation-in-elasticsearch/20298/1 "2014-10-17T04:11:18Z")

</div>

Hi,  
As terms aggregation will collect top size terms on each shard, so the  
final result may not accuracy if the shard size is not big enough.

```
so, in order to promote the accuracy of terms aggregation, we may need 

```

to calculate a weighted value by size. if there are more

```
documents on the shard, the terms collected on this shard will be 

```

greater. This means that we do not collect same size terms on each

```
shard.

so, we want to develop a customized plug-in which has the same manner 

```

with terms aggregation and different way of collecting terms on each shard.

```
The simple way is to inherit from terms aggregation, and override the 

```

way of collecting terms on each shard, but this seems difficulty,

```
because some classes in terms aggregation can only be accessed in 

```

package scope like the Bucket class.

```
we can also copy the whole source code of terms aggregation into our 

```

customized plug-in, but I don't think this is a good way.

```
Is it a good way to inherit from terms aggregation in user customized 

```

plug-in?

```
And Is there a good way to extend the terms aggregation?

```

Thanks,

ming

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e41cb9a8-b401-40ee-87cb-08ef9479aebf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e41cb9a8-b401-40ee-87cb-08ef9479aebf%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 12:55am UTC](https://discuss.elastic.co/t/how-to-extend-terms-aggregation-in-elasticsearch/20298/2 "2017-07-06T00:55:36Z")

</div>


