uylmz
uylmz

Reputation: 1552

Solr how to write a custom aggregation function/facet function

Is it possible/how to write a new custom facet function in Solr?

I want to write some new functions that executes against a facet bucket and produces a single result, but couldn't find where to start. One of them is a function that just returns some arbitrary value from bucket without calculating min/max/avg etc.

Upvotes: 0

Views: 458

Answers (1)

MatsLindh
MatsLindh

Reputation: 52832

A good way to get started in these cases are usually to find one of the existing and more uniquely named functions, then search for those in the code base.

Starting from JSON Facet API: Stat Facet Functions I see a couple of good candidates, such as percentile and sumsq (and a few others).

Searching for those in the code shows that the percentile aggregator is implemented in solr/core/src/java/org/apache/solr/search/facet/PercentileAgg.java as can be seen on Github. That seems a bit complicated, but the directory contains all the facet aggregation functions.

The Variance aggregator should be simpler, and indeed it is. Starting from the VarianceAgg source you should be able to create another version that aggregates all the values for a specific facet into a single value as well.

Start by extending SimpleAggValueSource and work from there.

Upvotes: 2

Related Questions