Apache Solr需要按日期分组

时间:2018-11-09 12:56:10

标签: apache solr

在Apache Solr中,我有财务交易,我需要按日期分组并汇总销售额。该怎么做?

我的日期字段在solr中的数据类型为 pdate ,其值与下面的数据和销售额类似

"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

如何按日期获得销售组总和的结果

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

2 个答案:

答案 0 :(得分:1)

Use a term facet with a nested aggregation facet

json.facet={
  dates: {
    terms: {
      field: transaction_date,
      facet: {
        "total" : "sum(sales_amount)"
      }
    }
  }
}

答案 1 :(得分:0)

尝试

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]

以上查询可能对您有所帮助。并使用json-facet-api作为总和。

请参考下图。

enter image description here