# How to implement custom aggregations or algorithms

**URL:** <https://discuss.elastic.co/t/how-to-implement-custom-aggregations-or-algorithms/21449>\
**Category:** Elasticsearch\
**Created:** [January 1, 2015, 9:39am UTC](https://discuss.elastic.co/t/how-to-implement-custom-aggregations-or-algorithms/21449 "2015-01-01T09:39:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cto](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@cto](https://discuss.elastic.co/u/cto)\
**Post date:** [January 1, 2015, 9:39am UTC](https://discuss.elastic.co/t/how-to-implement-custom-aggregations-or-algorithms/21449/1 "2015-01-01T09:39:27Z")

</div>

Hi,

I have been using ElasticSearch for the past 2 months and have tried  
various aggregations and filtering options on my data and is very happy  
with the performance.  
But, recently there is a requirement to implement some algorithms on my  
data set while retrieving data from ElasticSearch. This requirement is not  
solved by existing aggregations or filters.

So, is there a way of implementing any algorithm or custom aggregations on  
the data present in ElasticSearch ???

Thanks  
cto@TCS

--  
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/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [January 2, 2015, 7:53pm UTC](https://discuss.elastic.co/t/how-to-implement-custom-aggregations-or-algorithms/21449/2 "2015-01-02T19:53:37Z")

</div>

There is a way, but it is not documented as the aggregations internal API  
is not stable (and we kind-of like having this ability to break it whenever  
we want...) so it's very likely that upgrading your code to a new release  
would require important refactorings. Basically you need to write a plugin  
that will call AggregationModule.addAggregatorParser with a parser for your  
own aggregation. You can get inspiration from an existing aggregation such  
as the stats aggregation (in org.elasticsearch.search.aggregations.stats)  
to get started.

That said if you think that you need is common, a better option might be to  
open an issue so that we implement it and expose it in Elasticsearch, this  
way you would not have to maintain it yourself.

On Thu, Jan 1, 2015 at 10:39 AM, cto@TCS [rimita.mitra6@gmail.com](mailto:rimita.mitra6@gmail.com) wrote:

> Hi,
> 
> I have been using Elasticsearch for the past 2 months and have tried  
> various aggregations and filtering options on my data and is very happy  
> with the performance.  
> But, recently there is a requirement to implement some algorithms on my  
> data set while retrieving data from Elasticsearch. This requirement is not  
> solved by existing aggregations or filters.
> 
> So, is there a way of implementing any algorithm or custom aggregations on  
> the data present in Elasticsearch ???
> 
> Thanks  
> cto@TCS
> 
> --  
> 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/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j4AS9SCkU4apC-e5Q%2BqjVN3Nws33qjNzL9A9jmBXxE-jw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j4AS9SCkU4apC-e5Q%2BqjVN3Nws33qjNzL9A9jmBXxE-jw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![cto](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@cto](https://discuss.elastic.co/u/cto)\
**Post date:** [January 5, 2015, 6:51am UTC](https://discuss.elastic.co/t/how-to-implement-custom-aggregations-or-algorithms/21449/3 "2015-01-05T06:51:52Z")

</div>

Thank you so much!

On Saturday, January 3, 2015 1:23:44 AM UTC+5:30, Adrien Grand wrote:

> There is a way, but it is not documented as the aggregations internal API  
> is not stable (and we kind-of like having this ability to break it whenever  
> we want...) so it's very likely that upgrading your code to a new release  
> would require important refactorings. Basically you need to write a plugin  
> that will call AggregationModule.addAggregatorParser with a parser for your  
> own aggregation. You can get inspiration from an existing aggregation such  
> as the stats aggregation (in org.elasticsearch.search.aggregations.stats)  
> to get started.
> 
> That said if you think that you need is common, a better option might be  
> to open an issue so that we implement it and expose it in Elasticsearch,  
> this way you would not have to maintain it yourself.
> 
> On Thu, Jan 1, 2015 at 10:39 AM, cto@TCS \<[rimita...@gmail.com](mailto:rimita...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > I have been using Elasticsearch for the past 2 months and have tried  
> > various aggregations and filtering options on my data and is very happy  
> > with the performance.  
> > But, recently there is a requirement to implement some algorithms on my  
> > data set while retrieving data from Elasticsearch. This requirement is not  
> > solved by existing aggregations or filters.
> > 
> > So, is there a way of implementing any algorithm or custom aggregations  
> > on the data present in Elasticsearch ???
> > 
> > Thanks  
> > cto@TCS
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f4a1b1c5-cad8-4ab4-a4c9-844508d6f96b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Adrien Grand

--  
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/be63da4f-99bd-46e3-924e-69adf6f16682%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/be63da4f-99bd-46e3-924e-69adf6f16682%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:40am UTC](https://discuss.elastic.co/t/how-to-implement-custom-aggregations-or-algorithms/21449/4 "2017-07-06T00:40:59Z")

</div>


