# Histogram aggregation on calculated field by script

**URL:** <https://discuss.elastic.co/t/histogram-aggregation-on-calculated-field-by-script/290829>\
**Category:** Elasticsearch\
**Created:** [December 2, 2021, 8:53pm UTC](https://discuss.elastic.co/t/histogram-aggregation-on-calculated-field-by-script/290829 "2021-12-02T20:53:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladpov](https://avatars.discourse-cdn.com/v4/letter/v/8c91f0/32.png) [@Vladpov](https://discuss.elastic.co/u/Vladpov)\
**Post date:** [December 2, 2021, 8:53pm UTC](https://discuss.elastic.co/t/histogram-aggregation-on-calculated-field-by-script/290829/1 "2021-12-02T20:53:16Z")

</div>

Hey everyone!

We have index with products and every product (document in index) has several prices fields. We have query with script that calculates us finalPrice field because we do not know how many prices a document could have in advance.

We'd like to create Histogram aggregation on final prices of our products. Is there any option we calculate final price inside the Histogram aggregation and use it as input for Histogram aggregation?

Any idea is appreciated!

---

<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:** [December 30, 2021, 8:53pm UTC](https://discuss.elastic.co/t/histogram-aggregation-on-calculated-field-by-script/290829/2 "2021-12-30T20:53:22Z")

</div>

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