# How to round a value in an aggregation query?

**URL:** <https://discuss.elastic.co/t/how-to-round-a-value-in-an-aggregation-query/275509>\
**Category:** Elasticsearch\
**Created:** [June 10, 2021, 12:31am UTC](https://discuss.elastic.co/t/how-to-round-a-value-in-an-aggregation-query/275509 "2021-06-10T00:31:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [June 10, 2021, 12:31am UTC](https://discuss.elastic.co/t/how-to-round-a-value-in-an-aggregation-query/275509/1 "2021-06-10T00:31:53Z")

</div>

Hi Im trying to round the value of "forecast\_prediction" in an aggs query, I have tried bucket script aggregation but is not working

```auto
"aggs": {
              "jobid": {
                "terms": {
                  "field": "job_id",
                  "order": {
                    "_key": "desc"
                  },
                  "size": 10
                },
                "aggs": {
                  "fecha": {
                    "terms": {
                      "field": "timestamp",
                      "order": {
                        "_key": "desc"
                      },
                      "size": 10
                    },
                    "aggs": {
                      "host": {
                        "terms": {
                          "field": "partition_field_value",
                          "order": {
                            "_key": "desc"
                          },
                          "size": 10
                        },
                        "aggs": {
                          "fs": {
                            "terms": {
                              "field": "by_field_value",
                              "order": {
                                "_key": "desc"
                              },
                              "size": 10
                            },
                            "aggs": {
                              "prediccion": {
                                "top_hits": {
                                  "docvalue_fields": [
                                    {
                                      "field": "forecast_prediction"
                                    }
                                  ],
                                  "_source": "forecast_prediction",
                                  "size": 1,
                                  "sort": [
                                    {
                                      "timestamp": {
                                        "order": "desc"
                                      }
                                    }
                                  ]
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },`

```

---

<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:** [July 8, 2021, 12:32am UTC](https://discuss.elastic.co/t/how-to-round-a-value-in-an-aggregation-query/275509/2 "2021-07-08T00:32:06Z")

</div>

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