Using the json facet api is quite easy
Check out: http://yonik.com/json-facet-api/#TermsFacet

http://solr:8983/solr/your_collection/select?q=*:*&wt=json&indent=true&json.facet=
{
  property_codes_group_by : {
    type : terms,
    field : property_code,
    facet : { sum_price : "sum(price)" }
  }
}


2016-07-29 7:47 GMT-03:00 andreap21 <a.pisc...@reply.it>:

> Hi,
> is there any way in SOLR 5.3 to achieve grouping and do mathematical
> operations like sum, avg on a certain document property?
>
> Please find below example:
>
> <doc>
>   <str name="property_code">HIKS</str>
>   <str name="property_name">Hotel Holiday Inn King's cross</str>
>   <date name="day_of_year>2016-08-21T14:05:00Z</date>
>   <long name="number_of_adults">4</long>
>   <double name="price">40.99</double>
> </doc>
>
> <doc>
>   <str name="property_code">HIKS</str>
>   <str name="property_name">Hotel Holiday Inn King's cross</str>
>   <date name="day_of_year>2016-08-22T14:05:00Z</date>
>   <long name="number_of_adults">4</long>
>   <double name="price">40.99</double>
> </doc>
>
> <doc>
>   <str name="property_code">HIKS</str>
>   <str name="property_name">Hotel Holiday Inn King's cross</str>
>   <date name="day_of_year>2016-08-23T14:05:00Z</date>
>   <long name="number_of_adults">4</long>
>   <double name="price">40.99</double>
> </doc>
>
> We would need to group by the property_code (HIKS) and get the sum of all
> the prices from the resulting group.
>
>
> Thanks,
> Andrea
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Group-and-sum-in-SOLR-5-3-tp4289556.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Reply via email to