How to create a time-based query grouped by days?


(Jan Pišl) #1

I need a query that would return data from the last year, grouped by days. So far I have written a query that returns data for the entire year (I hope its correct), but I dont know how to group the data by day.

"query" : {
			"range" : {
                    "timestamp" : {
                                 "gt" : "2017-01-01 00:00:00",
                                 "lt" : "2018-01-01 00:00:00"
                       }
               }
		}

Any help would be much appreciated.

I am using Elasticsearch 6.2.2.


(David Pilato) #2

You need to add a date_histogram aggregation and ask for a day interval.
This will compute buckets per day on the resultset.


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.