在弹性文档中说如果我使用script
(reference),我可以执行多项聚合。我不清楚这是如何完成的。基本上我以后是count(*) ... group by logsource,pid
。没有脚本,似乎我只能做一组。如何使用脚本执行MultiTerms聚合?
有人可以给我看一个例子吗?
在弹性文档中说如果我使用script
(reference),我可以执行多项聚合。我不清楚这是如何完成的。基本上我以后是count(*) ... group by logsource,pid
。没有脚本,似乎我只能做一组。如何使用脚本执行MultiTerms聚合?
有人可以给我看一个例子吗?
使用脚本可以是昂贵的,但要回答你的问题,
POST /_search
{
"size": 0,
"aggs": {
"test": {
"terms": {
"script": "doc['logsource'].value+\":\"+doc['pid'].value",
"size": 0
}
}
}
}
都行!
我想用子聚集,我可以得到想要的结果,举个例子:
{
"query" : {
"match": {
"message": "error"
}
},
"aggs": {
"g_logsource": {
"terms": {
"field": "logsource"
},
"aggs": {
"g_pid": {
"terms": {
"field": "pid"
},
"aggs" : {
"ts" : {
"date_histogram" : {
"field" : "@timestamp",
"interval" : "1h"
}
}
}
}
}
}
}
}
返回:
"aggregations": {
"g_logsource": {
"doc_count_error_upper_bound": 0,
"buckets": [
{
"key": "nyhq",
"doc_count": 2129,
"g_pid": {
"doc_count_error_upper_bound": 5,
"buckets": [
{
"key": "5641",
"doc_count": 9,
"ts": {
"buckets": [
{
"key_as_string": "2014-12-07T04:00:00.000Z",
"key": 1417924800000,
"doc_count": 2
},
{
"key_as_string": "2014-12-07T08:00:00.000Z",
"key": 1417939200000,
"doc_count": 4
},
{
"key_as_string": "2014-12-07T18:00:00.000Z",
"key": 1417975200000,
"doc_count": 1
},
{
"key_as_string": "2014-12-07T20:00:00.000Z",
"key": 1417982400000,
"doc_count": 2
}
]
}
},
{
"key": "14839",
"doc_count": 3,
"ts": {
"buckets": [
{
"key_as_string": "2014-12-07T09:00:00.000Z",
"key": 1417942800000,
"doc_count": 1
},
{
"key_as_string": "2014-12-07T20:00:00.000Z",
"key": 1417982400000,
"doc_count": 2
}
]
}
}
在我的代码,然后我就可以结合组为{logsource: nyhq, pid: 5641}
作为每个时间序列的标识符。我认为这与SQL中的GROUP BY
相同。希望有任何意见可以证实这一点。
@progrrammer这条路怎么样,这是做我认为是什么? – 2014-12-08 17:28:55