# Doc count per day and avearge

**URL:** <https://discuss.elastic.co/t/doc-count-per-day-and-avearge/302317>\
**Category:** Elasticsearch\
**Tags:** vega\
**Created:** [April 13, 2022, 10:46am UTC](https://discuss.elastic.co/t/doc-count-per-day-and-avearge/302317 "2022-04-13T10:46:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![meyer1](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@meyer1](https://discuss.elastic.co/u/meyer1)\
**Post date:** [April 13, 2022, 10:46am UTC](https://discuss.elastic.co/t/doc-count-per-day-and-avearge/302317/1 "2022-04-13T10:46:25Z")

</div>

hello everyone

is it possible to get the number of documents that we have in our index per day? and then, after getting that (which I have already done) get the average of that, ie doc\_count per day.

I aim to integrate it into a vega kibana visualization, can you help me with that too?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![anime\_lover](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anime_lover/32/100265_2.png) [@anime\_lover](https://discuss.elastic.co/u/anime_lover)\
**Post date:** [April 13, 2022, 11:45am UTC](https://discuss.elastic.co/t/doc-count-per-day-and-avearge/302317/2 "2022-04-13T11:45:20Z")

</div>

hi there ,

i don't know much about vega but other than that can be done using aggregation . for your understanding i am giving example so take it as reference:

```auto

GET indexname/_search?size=0
{
  "aggs": {
    "hist": {
      "date_histogram": {
        "field": "date",
        "interval": "day"
      },
      "aggs": {
        "count": {
          "value_count": {
            "field": "date"
          }
        }
      }
    },
    "avg": {
      "avg_bucket": {
        "buckets_path": "hist>count"
      }
    }
  }
}

```

I hope it will help you ...you might find better way too ...If you find you can replay with another solutions.

---

<div class="post-metadata">

**Author:** ![meyer1](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@meyer1](https://discuss.elastic.co/u/meyer1)\
**Post date:** [April 14, 2022, 8:53am UTC](https://discuss.elastic.co/t/doc-count-per-day-and-avearge/302317/3 "2022-04-14T08:53:55Z")

</div>

Thank you very much for your answer, it's exactly what I wanted!

Now I'm trying to adapt it for a Vega visualization, the result I want is a graph over time of the documents I have, with an overlay of the average of my documents, a straight line that intersects my curve.

If someone can help me, I'd be happy !

---

<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 12, 2022, 8:54am UTC](https://discuss.elastic.co/t/doc-count-per-day-and-avearge/302317/4 "2022-05-12T08:54:33Z")

</div>

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