Hossein Nasr
Hossein Nasr

Reputation: 1458

Solr facet division of 2 aggregation function

I'm storing 2 type of data for each record in my Solr core. first one is the total number of tasks in each day (total) and the second one is the total number of finished tasks in each day (finished). I want to compute how many percents of tasks was finished in each month using solr json facet query. Something like this:

{
  finishedRate : {
    type : range,
    field : date,
    gap : "+1MONTH"
    facet: "div(sum(finished),sum(total))"
  }
}

but it said

org.apache.solr.search.SyntaxError: Unknown aggregation agg_div

I test the following query to solve SyntaxError, but it gives me the maximum percentage of tasks that finished in a day for each month:

{
  finishedRate : {
    type : range,
    field : date,
    gap : "+1MONTH"
    facet: "max(div(sum(finished),sum(total)))"
  }
}

how can I implement this query?

Upvotes: 1

Views: 722

Answers (1)

Dr. Pro
Dr. Pro

Reputation: 41

Had a similar use case a while back. After searching through the official Solr documentation, I finally gave up the idea of dividing it in the query itself.

I took another approach of just calculating the two values in the Solr query and then handling the division in my code.

Something like this -

{
  finishedRate : {
    type : range,
    field : date,
    gap : "+1MONTH",
    facet : {
      "finished tasks" : sum(finished),
      "total tasks" : sum(total)
    }
  }
}

Upvotes: 1

Related Questions