gpt4 book ai didi

mysql - 如何通过对solr中的天数进行分组来获取列的总和

转载 作者:可可西里 更新时间:2023-11-01 07:05:10 25 4
gpt4 key购买 nike

我的solr数据如下:

{
{
"total_amount": 100,
"created_at": "2015-07-08T18:30:00Z"
},
{
"total_amount": 200,
"created_at": "2015-07-08T18:30:00Z"
},
{
"total_amount": 300,
"created_at": "2015-06-08T18:30:00Z"
},
{
"total_amount": 400,
"created_at": "2015-06-08T18:30:00Z"
}
}

我想通过分组月份获得 total_amount 的总和。因此输出响应将如下所示:

{
"2015-07-01T00:00:00Z" : 300,
"2015-06-01T00:00:00Z" : 700
}

我正在使用下面的查询来获得给定的响应,但它只给我出现的次数。

查询和响应如下:

{
"responseHeader": {
"status": 0,
"QTime": 2,
"params": {
"facet.date.start": "2015-04-01T00:00:00Z",
"facet": "true",
"fl": "created_at,total_amount",
"q": "campaign_id:1",
"facet.date": "created_at",
"facet.date.gap": "+1MONTH",
"wt": "json",
"facet.date.end": "2015-09-01T00:00:00Z"
}
},
"response": {
"numFound": 3,
"start": 0,
"docs": [
{
"total_amount": 100,
"created_at": "2015-07-08T18:30:00Z"
},
{
"total_amount": 100,
"created_at": "2015-07-08T18:30:00Z"
},
{
"total_amount": 100,
"created_at": "2015-07-08T18:30:00Z"
}
]
},
"facet_counts": {
"facet_queries": {},
"facet_fields": {},
"facet_dates": {
"created_at": {
"2015-04-01T00:00:00Z": 0,
"2015-05-01T00:00:00Z": 0,
"2015-06-01T00:00:00Z": 0,
"2015-07-01T00:00:00Z": 3,
"2015-08-01T00:00:00Z": 0,
"gap": "+1MONTH",
"start": "2015-04-01T00:00:00Z",
"end": "2015-09-01T00:00:00Z"
}
},
"facet_ranges": {},
"facet_intervals": {},
"facet_heatmaps": {}
}

}

最佳答案

试试这个查询:

stats=true&stats.field=total_amount&stats.facet=created_at

这是来自 solr-ref-guide .

The Stats Component accepts the following parameters:

stats | If true, then invokes the Stats component.

stats.field | Specifies a field for which statistics should be generated. This parameter may be invoked multiple times in a query in order to request statistics on multiple fields. (See the example below.)

stats.facet | Returns sub-results for values within the specified facet.

我在运行“java -jar post.jar *.xml”后使用 SOLR_HOME/example/examplesdoc 目录中的数据测试了查询

这是部分结果。

 "belkin":{    "min":11.5,    "max":19.950000762939453,    "count":2,    "missing":0,    "sum":31.450000762939453,    "sumOfSquares":530.2525304412848,    "mean":15.725000381469727,    "stddev":5.975052840505987,    "facets":{}},  "maxtor":{    "min":350.0,    "max":350.0,    "count":1,    "missing":0,    "sum":350.0,    "sumOfSquares":122500.0,    "mean":350.0,    "stddev":0.0,    "facets":{}},  "inc":{    "min":179.99000549316406,    "max":2199.0,    "count":5,    "missing":0,    "sum":3587.8900299072266,    "sumOfSquares":5366417.4268503785,    "mean":717.5780059814454,    "stddev":835.4379769780703,    "facets":{}}}}}}}}

关于mysql - 如何通过对solr中的天数进行分组来获取列的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31429948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com