我有很多的文件,如下下Elasticsearch指数:Elasticsearch如何和值聚合结果后
{
"_index": "f2016-07-17",
"_type": "trkvjadsreqpxl.gif",
"_id": "AVX2N3dl5siG6SyfyIjb",
"_score": 1,
"_source": {
"time": "1468714676424",
"meta": {
"cb_id": 25681,
"mt_id": 649,
"c_id": 1592,
"revenue": 2.5,
"mt_name": "GMS-INAPP-EN-2.5",
"c_description": "COULL-INAPP-EN-2.5",
"domain": "wv.inner-active.mobi",
"master_domain": "649###wv.inner-active.mobi",
"child_domain": "1592###wv.inner-active.mobi",
"combo_domain": "25681###wv.inner-active.mobi",
"ip": "52.42.87.73"
}
}
}
我要让日期直方图/范围聚集在多个领域和结果存储在其他集合/索引。 因此,我可以使用小时范围之间的查询/聚合来制作doc_count总和。
聚集是:
{
"aggs": {
"hour":{
"date_histogram": {
"field": "time",
"interval": "hour"
},
"aggs":{
"hourly_M_TAG":{
"terms":{
"field":"meta.mt_id"
}
}
}....
}
}
}
结果不出所料:
"aggregations": {
"hour": {
"buckets": [
{
"key_as_string": "2016-07-17T00:00:00.000Z",
"key": 1468713600000,
"doc_count": 94411750,
"hourly_M_TAG": {
"doc_count_error_upper_bound": 1485,
"sum_other_doc_count": 30731646,
"buckets": [
{
"key": 10,
"doc_count": 10175501
},
{
"key": 649,
"doc_count": 200000
}....
]
}
},
{
"key_as_string": "2016-07-17T01:00:00.000Z",
"key": 1468717200000,
"doc_count": 68738743,
"hourly_M_TAG": {
"doc_count_error_upper_bound": 2115,
"sum_other_doc_count": 22478590,
"buckets": [
{
"key": 559,
"doc_count": 8307018
},
{
"key": 649,
"doc_count" :100000
}...
让我们假设我解析响应,并尝试存储在其他指数/托收结果。
我的问题
什么是存储汇总结果, 这样我就可以让其他查询/汇聚,总结不同时间范围之间的“doc_count”的最佳方式?
例如:与 “2016-07-17T00:00:00.000Z” - “2016-07-17T01:00:00.000Z” 希望看到每个按键上
预期的结果总doc_count:
{
"range_sum": {
"buckets": [
{
"key": 649,
"doc_count": 300000 // (200000+100000)
},
{
"key": 588,
"doc_count": 2928548 // ... + ...
}....
]
}
}
谢谢!
Mic987:我已经明确地添加了预期的结果。我需要存储结果,因为来自用户的请求可能是从任何小时到任何小时,另一个问题是我没有剩余存储空间,所以我每天汇总数据,在1天后没有进行聚合,存储空间问题就会发生。 – VitalyT
我已经更新了我的答案,希望它有一些用处,我想有很多不同的方法可以实现你想要的。 – Mic987