How to sum groups in Solr?

后端 未结 2 2031
再見小時候
再見小時候 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 08:58

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

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题