How to sum groups in Solr?

后端 未结 2 2026
再見小時候
再見小時候 2021-02-10 08:31

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) gr

2条回答
  •  一向
    一向 (楼主)
    2021-02-10 09:18

    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.

提交回复
热议问题