These are the records inserted in my index
{
{
"_index": "device_beacon_log_test",
"_type": "device_beacon_log_test",
"_id": "AWIJlB6WpDisa0DNP7rG",
"_score": 1,
"_source": {
"place_id": 61,
"device_time": "2018-02-12T14:22:59Z"
}
},
{
"_index": "device_beacon_log_test",
"_type": "device_beacon_log_test",
"_id": "AWIJlB6WpDisa0DNP7rG",
"_score": 1,
"_source": {
"place_id": 61,
"device_time": "2018-02-12T14:23:59Z"
}
},
{
"_index": "device_beacon_log_test",
"_type": "device_beacon_log_test",
"_id": "AWIJlB6WpDisa0DNP7rG",
"_score": 1,
"_source": {
"place_id": 61,
"device_time": "2018-02-12T14:45:59Z"
}
}
}
I want to calculate the difference between device time for each consecutive records
here is my query
{
"size": 0,
"aggs": {
"sales_per_month": {
"date_histogram": {
"field": "device_time",
"format": "dd-MM-yyyy",
"interval": "day"
},
"aggs": {
"a1": {
"terms": {
"field": "device_time",
"size": 500,
"order": {
"the_sum": "asc"
}
},
"aggs": {
"the_sum": {
"sum": {
"field": "device_time"
}
},
"derivative": {
"derivative": {
"buckets_path": "the_sum"
}
}
}
}
}
}
}
}
I want to calculate the difference between the_sum bucket .but query is failed to produce the result??can anyone help me to solve this
this is the output that I needed
{
"key_as_string": "12-02-2018",
"key": 1518393600000,
"doc_count": 14,
"a1": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 1518444239000,
"key_as_string": "2018-02-12T14:03:59.000Z",
"doc_count": 1,
"device_time": {
"value": 1518444239000
}
},
{
"key": 1518444359000,
"key_as_string": "2018-02-12T14:05:59.000Z",
"doc_count": 1,
"device_time": {
"value": 1518444359000
},
"derivative": {
"value": 120000
}
},
{
"key": 1518445319000,
"key_as_string": "2018-02-12T14:21:59.000Z",
"doc_count": 1,
"device_time": {
"value": 1518445319000
},
"derivative": {
"value": 960000
}
},
{
"key": 1518445379000,
"key_as_string": "2018-02-12T14:22:59.000Z",
"doc_count": 1,
"device_time": {
"value": 1518445379000
},
"derivative": {
"value": 60000
}
}
]
}
}
but when I am trying to execute query it's giving error as a ,derivative aggregation [derivative] must have a histogram or date_histogram as parent.So can I perform derivative aggregation without date_histogram??or there is any other way to perform this operation