# Sum aggs returning scientific value

**URL:** <https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861>\
**Category:** Elasticsearch\
**Created:** [March 19, 2021, 8:42pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861 "2021-03-19T20:42:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![leela\_kumili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leela_kumili/32/85841_2.png) [@leela\_kumili](https://discuss.elastic.co/u/leela_kumili)\
**Post date:** [March 19, 2021, 8:42pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861/1 "2021-03-19T20:42:48Z")

</div>

Sum aggs gives scientific value as result as shown below.  
Expected value 11111108.6789  
Actual value : 1.1111108625E7

Index Mapping

```auto
{
  "sample-tx" : {
    "mappings" : {
      "properties" : {
        "Id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "price" : {
          "type" : "float"
        },
        "promotion" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "publishedDate" : {
          "type" : "date"
        },
        "source" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "status" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "subType" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "transactionDate" : {
          "type" : "date"
        },
        "type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

Added below data into index

```auto
POST /_bulk
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "1" } }
{"Id" : "M-90010402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "2" } }
{"Id" : "M-90020402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "3" } }
{"Id" : "M-90030402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "4" } }
{"Id" : "M-90040402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "5" } }
{"Id" : "M-90050402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "6" } }
{"Id" : "M-90060402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "7" } }
{"Id" : "M-90070402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "8" } }
{"Id" : "M-90080402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}
{ "index" : { "_index" : "sample-tx", "_type" : "_doc", "_id" : "9" } }
{"Id" : "M-90090402224464143","type" : "E","source" : "mobile", "status" : "Processed","transactionDate" : "2021-03-18T21:12:00Z","price" : "1234567.6789", "promotion" : "Test1"}

```

When created alert using ES query:

```auto
GET /sample-tx/_search
{
  "size": 0, 
  "aggs": {
    "total": {
      "sum": {
        "field": "price"
        
      }
    }
  }
}

```

It gives results

```auto
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 9,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "total" : {
      "value" : 1.1111108625E7
    }
  }
}

```

But , when I use same index to create visualization and use sum metric value is displayed correctly.

Wondering how? Is this a way to use sum metric in ES query to get correct value as shown in visualization?

---

<div class="post-metadata">

**Author:** ![Supermathie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/supermathie/32/44936_2.png) [@Supermathie](https://discuss.elastic.co/u/Supermathie)\
**Post date:** [March 19, 2021, 9:30pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861/2 "2021-03-19T21:30:22Z")

</div>

That _is_ a correct value; it's a valid JSON literal.

```auto
○ → ipython3
In [1]: import json

In [2]: doc = '''
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 9,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "total" : {
      "value" : 1.1111108625E7
    }
  }
}
'''

In [3]: json.loads(doc)['aggregations']['total']['value']
Out[3]: 11111108.625

```

---

<div class="post-metadata">

**Author:** ![leela\_kumili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leela_kumili/32/85841_2.png) [@leela\_kumili](https://discuss.elastic.co/u/leela_kumili)\
**Post date:** [March 22, 2021, 8:40pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861/3 "2021-03-22T20:40:18Z")

</div>

Hi Michael,

I am using the above ES query as part of monitor query. It does not allow json import.

---

<div class="post-metadata">

**Author:** ![leela\_kumili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leela_kumili/32/85841_2.png) [@leela\_kumili](https://discuss.elastic.co/u/leela_kumili)\
**Post date:** [March 22, 2021, 8:55pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861/4 "2021-03-22T20:55:28Z")

</div>

Refer to below screenshots where in visualization and monitor sample message value is shown correctly but in slack message goes scientific value.

 ![Screen Shot 2021-03-22 at 1.51.14 PM](https://us1.discourse-cdn.com/elastic/original/3X/f/6/f6ea6a1d2ebb01d7523ec6977402b48404b02515.png) ![Screen Shot 2021-03-22 at 1.52.11 PM](https://us1.discourse-cdn.com/elastic/original/3X/2/7/2753d6a72122ec17a092a62a0ae384b46c3fce38.png) ![Screen Shot 2021-03-22 at 1.52.27 PM](https://us1.discourse-cdn.com/elastic/original/3X/1/f/1f381b271104fe87565056f44704a84ae80d44ef.png)

---

<div class="post-metadata">

**Author:** ![Supermathie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/supermathie/32/44936_2.png) [@Supermathie](https://discuss.elastic.co/u/Supermathie)\
**Post date:** [March 22, 2021, 9:58pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861/5 "2021-03-22T21:58:58Z")

</div>

This looks like a problem with the Alerting tool.

---

<div class="post-metadata">

**Author:** ![leela\_kumili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leela_kumili/32/85841_2.png) [@leela\_kumili](https://discuss.elastic.co/u/leela_kumili)\
**Post date:** [March 23, 2021, 6:38pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861/6 "2021-03-23T18:38:23Z")

</div>

Any idea or thoughts on how to overcome this limitation from alerting tool?

---

<div class="post-metadata">

**Author:** ![Supermathie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/supermathie/32/44936_2.png) [@Supermathie](https://discuss.elastic.co/u/Supermathie)\
**Post date:** [March 23, 2021, 8:57pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861/7 "2021-03-23T20:57:44Z")

</div>

I'm not familiar with the tool you're using; you'll likely have to get in touch with the developers.

---

<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:** [April 20, 2021, 8:57pm UTC](https://discuss.elastic.co/t/sum-aggs-returning-scientific-value/267861/8 "2021-04-20T20:57:46Z")

</div>

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