# How to refer doc\_count in MovingFunctions.ewma aggregation bucket path?

**URL:** https://discuss.elastic.co/t/how-to-refer-doc-count-in-movingfunctions-ewma-aggregation-bucket-path/353602
**Category:** Elasticsearch
**Tags:** aggregations
**Created:** [February 19, 2024, 1:48pm UTC](https://discuss.elastic.co/t/how-to-refer-doc-count-in-movingfunctions-ewma-aggregation-bucket-path/353602 "2024-02-19T13:48:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Abinash\_Raja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abinash_raja/32/131685_2.png) [@Abinash\_Raja](https://discuss.elastic.co/u/Abinash_Raja)
#### Post date: [February 19, 2024, 1:48pm UTC](https://discuss.elastic.co/t/how-to-refer-doc-count-in-movingfunctions-ewma-aggregation-bucket-path/353602/1 "2024-02-19T13:48:34Z")

</div>

Hi,

Is there a way to directly refer the **doc\_count** of date histogram(over `time_millis` field) bucket(s) in **MovingFunctions.ewma** `bucket path`, instead of creating a separate **value\_count** aggregation (for the same field `time_millis`)?

Sample Query:

```auto
{
  "explain": false,
  "size": 0,
  "aggregations": {
    "time_millis_histogram": {
      "date_histogram": {
        "field": "time_millis",
        "offset": 0,
        "interval": "1m",
        "keyed": false,
        "min_doc_count": 1,
        "order": {
          "_key": "asc"
        }
      },
      "aggregations": {
        "time_value_count": {
          "value_count": {
            "field": "time_millis"
          }
        },
        "ewma": {
          "moving_fn": {
            " **buckets_path**": "time_value_count",
            "window": 10,
            "script": "MovingFunctions.ewma(values, 0.3)"
          }
        }
      }
    }
  }
}

```

Sample Response:

 ![image (1)](https://us1.discourse-cdn.com/elastic/original/3X/b/e/bec21b7665fdc8d654902ea069a133b530c84f4b.png)

---

<div class="post-metadata">

### Author: ![Abinash\_Raja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abinash_raja/32/131685_2.png) [@Abinash\_Raja](https://discuss.elastic.co/u/Abinash_Raja)
#### Post date: [February 20, 2024, 10:47am UTC](https://discuss.elastic.co/t/how-to-refer-doc-count-in-movingfunctions-ewma-aggregation-bucket-path/353602/2 "2024-02-20T10:47:32Z")

</div>

**Resolved!** Found that the `doc_count` can be directly referred in the `MovingFunctions.ewma` bucket path of a date histogram as `_count`.

Sample Query:

```auto
{
  "explain": false,
  "size": 0,
  "aggregations": {
    "time_millis_histogram": {
      "date_histogram": {
        "field": "time_millis",
        "offset": 0,
        "interval": "1m",
        "keyed": false,
        "min_doc_count": 1,
        "order": {
          "_key": "asc"
        }
      },
      "aggregations": {
        "ewma": {
          "moving_fn": {
            "buckets_path": "_count",
            "window": 10,
            "script": "MovingFunctions.ewma(values, 0.3)"
          }
        }
      }
    }
  }
}

```

---

<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: [March 19, 2024, 10:48am UTC](https://discuss.elastic.co/t/how-to-refer-doc-count-in-movingfunctions-ewma-aggregation-bucket-path/353602/3 "2024-03-19T10:48:21Z")

</div>

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