That should work... what version of Solr are you using? Did you
change the type of the popularity field w/o completely reindexing?
You can try to verify the number of documents in each bucket that have
the popularity field by adding another sub-facet next to cat_pop:
num_pop:{query:"popularity:[* TO *]"}
> A quick check with this json.facet parameter:
>
> json.facet: {cat_pop:"sum(popularity)“}
>
> returns:
>
> "facets“: {
> "count":2508,
> "cat_pop":21.0},
That looks like a pretty low sum for all those documents.... perhaps
most of them are missing "popularity" (or have a 0 popularity).
To test one of the buckets at the top-level this way, you could add
fq=shop_cat:"Men > Clothing > Jumpers & Cardigans"
and see if you get anything.
-Yonik
On Wed, Dec 14, 2016 at 12:46 PM, CA <[email protected]> wrote:
> Hi all,
>
> this is about using a function in nested facets, specifically the „sum()“
> function inside a „terms“ facet using the json.facet api.
>
> My json.facet parameter looks like this:
>
> json.facet={shop_cat: {type:terms, field:shop_cat, facet:
> {cat_pop:"sum(popularity)"}}}
>
> A snippet of the result:
>
> "facets“: {
> "count":2508,
> "shop_cat“: {
> "buckets“: [{
> "val“: "Men > Clothing > Jumpers & Cardigans",
> "count":252,
> "cat_pop“:0.0
> }, {
> "val":"Men > Clothing > Jackets & Coats",
> "count":157,
> "cat_pop“:0.0
> }, // and more
>
> This looks fine all over but it turns out that „cat_pop“, the result of
> „sum(popularity)“ is always 0.0 even if the documents for this facet value
> have popularities > 0.
>
> A quick check with this json.facet parameter:
>
> json.facet: {cat_pop:"sum(popularity)“}
>
> returns:
>
> "facets“: {
> "count":2508,
> "cat_pop":21.0},
>
> To me, it seems it works fine on the base level but not when nested. Still,
> Yonik’s documentation and the Jira issues indicate that it is possible to use
> functions in nested facets so I might just be using the wrong structure? I
> have a hard time finding any other examples on the i-net and I had no luck
> changing the structure around.
> Could someone shed some light on this for me? It would also help to know if
> it is not possible to sum the values up this way.
>
> Thanks a lot!
> Chantal
>
>