0

I have a facet query working with count but I would like to do a sum on a field on the data already grouped by the facet.field. I have the json facet query working in the browser but no luck with PySolr.

import pysolr
import pprint

conn = pysolr.Solr('http://localhost:8080/solr/corename')
result = conn.search('*:*', **{
    'facet': 'true',
    'facet.type': 'terms',
    'facet.limit': 5,
    'facet.field': 'field_name',
    'f.results.facet.sum': '{!func}sum(daily_amount)'
})   

pprint.pprint(result.facets)

I would like to do a sum on a particualr field, is that possible in PySolr?

Chirdeep Tomar
  • 4,281
  • 8
  • 37
  • 66
  • Have you seen the JSON Facet API? It allows you to create buckets and operations on those buckets: https://solr.apache.org/guide/solr/latest/query-guide/json-facet-api.html – MatsLindh Jun 29 '22 at 19:05
  • I have exactly the same requirement as listed under Sorting Facets By Nested Functions on the link above, I have it working via CURL, how can I achieve the same in PySolr? – Chirdeep Tomar Jun 29 '22 at 19:47
  • See https://github.com/django-haystack/pysolr/issues/213 for an example: `'json.facet': json.dumps({'uniq':"unique(foo)"}),` – MatsLindh Jun 29 '22 at 21:11
  • Tried that earlier but finally got it working now, thanks. – Chirdeep Tomar Jun 29 '22 at 21:26
  • Add a proper, contained example as an answer and accept it yourself so that future search engine users find out how to do it properly right here :-) – MatsLindh Jun 30 '22 at 10:00

0 Answers0