skip to Main Content

In Apache Solr I have financial transactions and I need to groupby date and sumup the sales amount. How to do this?

my date field is of datatype pdate in solr and the values are like the below for data and sales

"2018-10-01T00:00:00Z", 56.25
"2018-10-01T01:50:00Z", 58.35 
"2018-10-01T05:20:00Z", 65.15
"2018-10-02T00:00:00Z", 56.25
"2018-10-03T01:50:00Z", 58.35 
"2018-10-03T05:20:00Z", 65.15

How to get the result as sum of sales group by date

"2018-10-01", 179.75 
"2018-10-02",  56.25 
"2018-10-03", 123.50

2

Answers


  1. Use a term facet with a nested aggregation facet.

    json.facet={
      dates: {
        terms: {
          field: transaction_date,
          facet: {
            "total" : "sum(sales_amount)"
          }
        }
      }
    }
    
    Login or Signup to reply.
  2. Try

    group.query

    http://xx.yy.xx.zz:8983/solr/mycorename/select?fl=eventTimeStamp%2Cevent1&group.sort=event1%20desc&group=true&q=%3A&group.query=eventTimeStamp:[2019-08-01T00:00:00Z%20TO%202019-08-01T23:59:59Z]&group.query=eventTimeStamp:[2019-08-02T00:00:00Z%20TO%202019-08-02T23:59:59Z]&group.query=eventTimeStamp:[2019-08-03T00:00:00Z%20TO%202019-08-03T23:59:59Z]

    Above query can be helpful for you. And use json-facet-api for sum.

    Refer below image.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search