Skip to content

Instantly share code, notes, and snippets.

@ebuildy
Last active April 16, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebuildy/1b13bcdc27ad71ab088d1a5e79e5444f to your computer and use it in GitHub Desktop.
Save ebuildy/1b13bcdc27ad71ab088d1a5e79e5444f to your computer and use it in GitHub Desktop.
Calcul cumulative sum metric (such as elasticearch node stat query_total) difference between 2 timestamps.
{
"source" : {
"size": 0,
"query": {
"query_string": {
"query": "@timestamp:[{{start_date}}:00+02:00 TO {{end_date}}:59+02:00] AND data.attributes.master:false"
}
},
"aggs": {
"nodes": {
"terms": {
"field": "meta.node.name"
},
"aggs": {
"start": {
"filter": {
"range": {
"@timestamp": {
"gt": "{{start_date}}:00+02:00",
"lt": "{{start_date}}:30+02:00"
}
}
},
"aggs": {
"value": {
"avg": {
"field": "data.indices.search.query_total"
}
}
}
},
"end": {
"filter": {
"range": {
"@timestamp": {
"gt": "{{end_date}}:00+02:00",
"lt": "{{end_date}}:59+02:00"
}
}
},
"aggs": {
"value": {
"avg": {
"field": "data.indices.search.query_total"
}
}
}
},
"diff": {
"bucket_script": {
"buckets_path": {
"end": "end>value",
"start": "start>value"
},
"script": "params.end - params.start"
}
}
}
},
"total" : {
"sum_bucket" : {
"buckets_path" : "nodes>diff"
}
}
}
},
"params" : {
"start_date" : "2018-04-16T15:13",
"end_date" : "2018-04-16T15:25"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment