# How to loop over aggregated search?

**URL:** <https://discuss.elastic.co/t/how-to-loop-over-aggregated-search/122692>\
**Category:** Elasticsearch\
**Created:** [March 6, 2018, 10:16am UTC](https://discuss.elastic.co/t/how-to-loop-over-aggregated-search/122692 "2018-03-06T10:16:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Pisl](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@Jan\_Pisl](https://discuss.elastic.co/u/Jan_Pisl)\
**Post date:** [March 6, 2018, 10:16am UTC](https://discuss.elastic.co/t/how-to-loop-over-aggregated-search/122692/1 "2018-03-06T10:16:03Z")

</div>

I have the following query:

```
  query = {
        "aggs" : {
            "by_minute" : {
                "date_histogram" : {
                    "field" : "@timestamp",
                    "interval" : "minute"
                },
                "aggs":{
                    "max": { "max": { "field": "duration" } },
                    "min": { "min": { "field": "duration" } },
                    "avg": { "avg": { "field": "duration" } },
                }
            }
        },
        "query" : {
            "bool" : {
                "filter": [
                    { "query_string" : { "query" : "audit_type:REQ AND req_backend_name:service" } },
                    { "range" : { "@timestamp" : { "gte" : "now-24h", "lt" : "now" } } },
                ]
            }
        }
    } 

```

What is does now is that it fetches data from last 24 hours and then groups them by minute. What I need, however, is this type of data for every 24 hours for the last year separately.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 3, 2018, 10:16am UTC](https://discuss.elastic.co/t/how-to-loop-over-aggregated-search/122692/2 "2018-04-03T10:16:17Z")

</div>

Closed on April 3, 2018, 10:16am UTC

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