[英]Solr json.facet range query with month grouping
I have got a solr query (Solr version 6.0.2) which groups and sums sales per day.我有一个 solr 查询(Solr 版本 6.0.2),它对每天的销售额进行分组和汇总。 Everything works great with following parameters:
使用以下参数一切正常:
json.facet=sales:{
type:range,
field:date_add,
start:'2016-05-31T22:00:00Z',
end:'2016-10-31T22:59:59Z',
gap:'+1DAY',
facet:{
ordersSum:'sum(sales_value)'
}
}
(The specified hour 22:00:00 in start parameter is because of time zone ,since Solr keeps dates in UTC and my application works in Europe/Warsaw time zone) ( start参数中指定的小时 22:00:00 是因为时区,因为 Solr 将日期保持在 UTC 并且我的应用程序在欧洲/华沙时区工作)
With that I've got nice sales values with respect to days specified between start and end parameters.有了这个,我就开始和结束参数之间指定的天数获得了不错的销售价值。 However now I want to do the same, but for the month basis, so I want sales for june, july [..] october.
但是现在我想做同样的事情,但以月为基础,所以我想要 6 月、7 月 [..] 10 月的销售额。
I've figured out that, It's possible to change gap parameter to '+1MONTH' , but the values are not consitent, since months aren't equal:我发现,可以将 gap 参数更改为'+1MONTH' ,但值不一致,因为月份不相等:
"val":"2016-05-31T22:00:00Z",
"val":"2016-06-30T22:00:00Z",
"val":"2016-07-30T22:00:00Z",
"val":"2016-08-30T22:00:00Z",
"val":"2016-09-30T22:00:00Z",
As it can be seen, the dates defaults to the first occured lower number of days (ie. july and agust have 31 days).可以看出,日期默认为第一个出现的较低天数(即 7 月和 8 月有 31 天)。 Again the problem can be solved by manipulation of start parameter to:
同样,这个问题可以通过操作start参数来解决:
2016-05-31T22:00:00Z/MONTH
The /MONTH suffix tells Solr to default to first day of month, at midnight. /MONTH后缀告诉 Solr 默认为每月第一天的午夜。 Then fetched dates looks good:
然后获取的日期看起来不错:
"val":"2016-06-01T00:00:00Z",
"val":"2016-07-01T00:00:00Z",
"val":"2016-08-01T00:00:00Z",
"val":"2016-09-01T00:00:00Z",
"val":"2016-10-01T00:00:00Z",
However given date values are correct for UTC time zone.但是,给定的日期值对于 UTC 时区是正确的。 Is there a way for Solr to add months properly, or set timezone for results?
Solr 有没有办法正确添加月份,或者为结果设置时区?
Ok, I think I've figured it out.好吧,我想我已经想通了。 It's possible to set timezone globally for the Solr query by adding additional parameter to the query:
通过向查询添加附加参数,可以为 Solr 查询全局设置时区:
&TZ=Europe/Warsaw &TZ=欧洲/华沙
In my case the results are following:在我的情况下,结果如下:
"val":"2015-08-31T22:00:00Z",
"val":"2015-09-30T22:00:00Z",
"val":"2015-10-31T23:00:00Z",
"val":"2015-11-30T23:00:00Z",
(I've changed start / end parameters a bit to show how daylight saving time is kept). (我稍微更改了开始/结束参数以显示夏令时是如何保持的)。 Additionally, the /MONTH suffix is not needed in that case, it only helps to keep the starting time correct.
此外,在这种情况下不需要/MONTH后缀,它只会帮助保持开始时间正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.