# The sum of my Elastic i coming as a whole number and that field had values that had decimals

**URL:** <https://discuss.elastic.co/t/the-sum-of-my-elastic-i-coming-as-a-whole-number-and-that-field-had-values-that-had-decimals/363351>\
**Category:** Elastic Search\
**Created:** [July 18, 2024, 1:26pm UTC](https://discuss.elastic.co/t/the-sum-of-my-elastic-i-coming-as-a-whole-number-and-that-field-had-values-that-had-decimals/363351 "2024-07-18T13:26:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Collins\_Mbathi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/collins_mbathi/32/122082_2.png) [@Collins\_Mbathi](https://discuss.elastic.co/u/Collins_Mbathi)\
**Post date:** [July 18, 2024, 1:26pm UTC](https://discuss.elastic.co/t/the-sum-of-my-elastic-i-coming-as-a-whole-number-and-that-field-had-values-that-had-decimals/363351/1 "2024-07-18T13:26:16Z")

</div>

in my elastic Cost field has decimals but when doing aggregation of it , its coming as whole number, am expecting the aggregation sum to come as decimals also

here is my query

````auto
        aggregation: { "dateAggs": { "terms": { "field": "Date", "format": "MMM YYYY", "order": { "_key": "asc" } }, "aggs": { "costSum": { "sum": { "field": "Cost" } } } } },```
````

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [July 18, 2024, 7:33pm UTC](https://discuss.elastic.co/t/the-sum-of-my-elastic-i-coming-as-a-whole-number-and-that-field-had-values-that-had-decimals/363351/2 "2024-07-18T19:33:55Z")

</div>

Hi there @Collins_Mbathi, welcome to the Elastic community and thanks for posting!

Could you please provide a little more information - perhaps the mappings in your index and more information on the data you've indexed, more information on the query you're running, and what you're getting back?

I put the snippet you provided into a simple test indexing using Elasticsearch 8.14.1:

```auto
PUT /test
{
  "mappings": {
    "properties": {
      "Date": {
        "type": "date"
      },
      "Cost": {
        "type": "float"
      }
    }
  }
}

POST test/_doc/
{
  "Date": "2024-06-01",
  "Cost": 12.34
}
POST test/_doc
{
  "Date": "2024-07-02",
  "Cost": 56.78
}

GET test/_search
{
  "size": 0,
  "aggs": {
    "dateAggs": {
      "terms": {
        "field": "Date",
        "format": "MMM YYYY",
        "order": {
          "_key": "asc"
        }
      },
      "aggs": {
        "costSum": {
          "sum": {
            "field": "Cost"
          }
        }
      }
    }
  }
}

```

Using this script, I see that `costSum` is returning floating point values.

```auto
{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "dateAggs": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": 1717200000000,
          "key_as_string": "Jun 2024",
          "doc_count": 1,
          "costSum": {
            "value": 12.34000015258789
          }
        },
        {
          "key": 1719878400000,
          "key_as_string": "Jul 2024",
          "doc_count": 1,
          "costSum": {
            "value": 56.779998779296875
          }
        }
      ]
    }
  }
}

```

More information about what you're seeing vs. what you expect, and how to reproduce it, will be helpful for us to help you.

Thanks!

---

<div class="post-metadata">

**Author:** ![RainTown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raintown/32/140206_2.png) [@RainTown](https://discuss.elastic.co/u/RainTown)\
**Post date:** [July 19, 2024, 3:43pm UTC](https://discuss.elastic.co/t/the-sum-of-my-elastic-i-coming-as-a-whole-number-and-that-field-had-values-that-had-decimals/363351/3 "2024-07-19T15:43:11Z")

</div>

agreed it would be helpful to see more information here.

Terminology is a bit wrong, you with "decimals" when I think you mean a floating point numbers. So one thing to be sure of is your mapping for the cost field.

Also, precisely _ **where** _ are you seeing the aggrgation "coming as whole number", in some other tool/UI, or within the actual json response?

Please post the actual aggregation query and the actual response from elasticsearch.

---

<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:** [August 16, 2024, 3:43pm UTC](https://discuss.elastic.co/t/the-sum-of-my-elastic-i-coming-as-a-whole-number-and-that-field-had-values-that-had-decimals/363351/4 "2024-08-16T15:43:22Z")

</div>

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