I am using ES 1.6.0.
Suppose we have following documents indexed under type "t" in index "test":
[
{
// ...
"_source": {
"id": "t2",
"ts": "2015-07-20T08:30"
}
},
{
"_source": {
"id": "t1",
"ts": "2015-07-20T08:00"
}
},
{
"_source": {
"id": "t1",
"ts": "2015-07-20T09:00"
}
},
{
"_source": {
"id": "t2",
"ts": "2015-07-20T09:30"
}
}
]
I want to bucketize it by "id" and for each distinct id figure out the difference between min and max value of "ts" field. Aggregation itself is easy:
{
"aggs": {
"id": {
"terms": {
"field": "id"
},
"aggs": {
"mit": {
"min": {
"field": "ts"
}
},
"mat": {
"max": {
"field": "ts"
}
}
}
}
}
}
But now I need to do actual subtraction and I did not find a way so far. Is it possible? How?
OK, I might not provide the details why I need it. I want to graph it in Kibana, so if can be done in Kibana instead, it is fine, too.