Hi,

In the Solr 7.2 JSON API, when faceting over terms, I would like to sort
the buckets over the average of a numerical property, as shown below

curl http://localhost:8983/solr/core/select -d '
q=*:*&
rows=0&
wt=json&
json.facet={
         "field" : {
                    "type" : "terms",
                    "field" : "string-field",
                    "sort" : "avg desc",
                    "limit" : 50,
                    facet : {
                        avg : "avg(number_i)",
                        unique : "unique(number_i)"
                   }
          }
}'


However, when none of the documents in a bucket has a value for the
numerical property (e.g. unique = 0 in this case), an average value avg = 0
is returned.
This average value of 0 is then used for sorting the buckets.

I would like the buckets with no value for the numerical property to be
sorted last.
Is there a way to e.g. use conditional sorting? E.g.
    sort: "if(gt(unique,0),avg,-999999999) desc"

I can't get this to work, while in the old API this appaers to be possible.

Or is there another way to sort the buckets with a missing numeric value
last?

Kind regards, Tom

Reply via email to