# Elasticsearch date histogram aggregations with min/max/avg

**URL:** <https://discuss.elastic.co/t/elasticsearch-date-histogram-aggregations-with-min-max-avg/81355>\
**Category:** Elasticsearch\
**Created:** [April 5, 2017, 5:46pm UTC](https://discuss.elastic.co/t/elasticsearch-date-histogram-aggregations-with-min-max-avg/81355 "2017-04-05T17:46:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roma\_Rush](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roma_rush/32/17110_2.png) [@Roma\_Rush](https://discuss.elastic.co/u/Roma_Rush)\
**Post date:** [April 5, 2017, 5:46pm UTC](https://discuss.elastic.co/t/elasticsearch-date-histogram-aggregations-with-min-max-avg/81355/1 "2017-04-05T17:46:54Z")

</div>

I am using elasticsearch 5.3 and trying to receive min/max/avg aggregations by date.

```
curl -XPOST localhost:9200/avtostat/ads/_search -d

{
"size":0,
"aggs":{
    "prices_per_month":{
        "date_histogram":{
            "field":"state_date",
            "interval":"week"
        },
        "aggs":{
            "prices":{
                "sum":{
                    "field":"price_usd"
                }
            }
        }
    },
    "avg_monthly_prices":{
        "avg_bucket":{
            "buckets_path":"prices_per_month>prices"
        }
    }
}
}

```

It returns next data:

```
{
"took":12,
"timed_out":false,
"_shards":{
    "total":1,
    "successful":1,
    "failed":0
},
"hits":{
    "total":38627,
    "max_score":0.0,
    "hits":[

    ]
},
"aggregations":{
    "prices_per_month":{
        "buckets":[
            {
                "key_as_string":"2017-01-02",
                "key":1483315200000,
                "doc_count":11918,
                "prices":{
                    "value":5.6471833E7
                }
            },
            {
                "key_as_string":"2017-01-09",
                "key":1483920000000,
                "doc_count":0,
                "prices":{
                    "value":0.0
                }
            },
            {
                "key_as_string":"2017-01-16",
                "key":1484524800000,
                "doc_count":6322,
                "prices":{
                    "value":3.0116144E7
                }
            },
            {
                "key_as_string":"2017-01-23",
                "key":1485129600000,
                "doc_count":20386,
                "prices":{
                    "value":9.3860144E7
                }
            },
            {
                "key_as_string":"2017-01-30",
                "key":1485734400000,
                "doc_count":1,
                "prices":{
                    "value":2900.0
                }
            }
        ]
    },
    "avg_monthly_prices":{
        "value":4.511275525E7
    }
}
}

```

It returns aggregation for one month only, but i have data for february and march. How to get it.

More info here [https://stackoverflow.com/questions/43227101/elasticsearch-date-histogram-aggregations-with-min-max-avg](https://stackoverflow.com/questions/43227101/elasticsearch-date-histogram-aggregations-with-min-max-avg)

---

<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:** [May 3, 2017, 5:46pm UTC](https://discuss.elastic.co/t/elasticsearch-date-histogram-aggregations-with-min-max-avg/81355/2 "2017-05-03T17:46:57Z")

</div>

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