我需要通过应用两个字段的过滤器来创建数据透视数据,即城市和日期范围。 能够按城市和日期范围过滤数据,但过滤器不适用于统计信息字段。 以下是我使用的Solr查询:
选择&安培; FQ =城市?{标签= F1!}:{!标签= queryOne}(%221000%20OAKS%22)及小面=真安培; facet.query =真安培facet.query = datadate: 2015年1月1日%20TO%202015-12-31&安培; facet.query = datadate {标签= queryTwo!}:[2014年1月1日%20TO%202014-12-31&安培;统计=真安培;统计点域=费及放{标签= A1%20sum =真正%20key = charge1!}; stats.field =支出和放{标签= A2%20sum =真正%20key = spend1!};!facet.pivot = {查询= queryOne%20key = C1%20stats = A1}城市&安培; facet.pivot = {查询= queryTwo%20stats = A2%20key = C2}城市&安培;!面= ON&安培;缩进= ON&安培;重量= JSON&安培;行= 0&安培; q = :
正如你所看到的,总和保持不变(即2348),无论我在queryone& querytwo标签。 似乎datadate过滤器对stats字段没有任何影响。 任何人都可以解释这里发生的事情,因为我对此很陌生。 提前谢谢。
答案 0 :(得分:0)
问题在于StatsComponent
& FacetComponent
并非完全融合在一起。以下Solr Jira包含您的用例:SOLR-6348。
但是,通过JSON Facet API为您的用例提供了解决方法。这是facet参数,它解决了您的特定用例:
{
"date_range": {
"type": "range",
"field": "datadate_dt",
"start": "2014-01-01T00:00:00Z",
"end": "2016-01-01T00:00:00Z",
"gap": "%2B1YEAR",
"facet": {
"cities_and_spends": {
"type": "terms",
"field": "city_s",
"facet": {"sum_of_spend": "sum(spend_d)"}
},
"cities_and_charges": {
"type": "terms",
"field": "city_s",
"facet": {"sum_of_spend": "sum(charge_d)"}
}
}
}
}
因此整体GET请求如下:
.../select?indent=on&q=*:*&fq=city:(%221000%20OAKS%22)&rows=0&wt=json&json.facet={%20%22date_range%22:%20{%20%22type%22:%20%22range%22,%20%22field%22:%20%22datadate_dt%22,%20%22start%22:%20%222014-01-01T00:00:00Z%22,%20%22end%22:%20%222016-01-01T00:00:00Z%22,%20%22gap%22:%20%22%2B1YEAR%22,%20%22facet%22:%20{%20%22cities_and_spends%22:%20{%20%22type%22:%20%22terms%22,%20%22field%22:%20%22city_s%22,%20%22facet%22:%20{%22sum_of_spend%22:%20%22sum(spend_d)%22}%20},%20%22cities_and_charges%22:%20{%20%22type%22:%20%22terms%22,%20%22field%22:%20%22city_s%22,%20%22facet%22:%20{%22sum_of_spend%22:%20%22sum(charge_d)%22}%20}%20}%20}%20}