user1214199
user1214199

Reputation: 51

How to sum groups in Solr?

I want to know how to do this like sql in solr ?

select sum(Col1) group by Col2,Col3

I could solve the problem like select sum(Col1) group by Col2 in solr .( http://wiki.apache.org/solr/StatsComponent) can you help me ?

Upvotes: 5

Views: 4693

Answers (2)

brass monkey
brass monkey

Reputation: 6781

I think you can achieve this using the Stats Component feature which you already mentioned. For example

/select?q=:&stats=true&stats.facet=Col2&stats.field=Col1

This way you get the stats block with a grouped Col2 in the result where you can access the sum value for each Col2. But the documentation states that the use of stats.facet is not recommended any more.

This legacy parameter is not recommended for new users - instead please consider combining stats.field with facet.pivot

But i have to admit that i fail to solve your use case using only the recommended stats.field with facet.pivot.

Upvotes: 2

Jayendra
Jayendra

Reputation: 52809

Solr provides an grouping feature called field Collapsing
This will allow you to group on a non multivalued field.

Upvotes: 1

Related Questions