# Mapping: How to do your own calculations

**URL:** <https://discuss.elastic.co/t/mapping-how-to-do-your-own-calculations/280641>\
**Category:** Kibana\
**Created:** [August 6, 2021, 11:11am UTC](https://discuss.elastic.co/t/mapping-how-to-do-your-own-calculations/280641 "2021-08-06T11:11:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoobUser404](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@NoobUser404](https://discuss.elastic.co/u/NoobUser404)\
**Post date:** [August 6, 2021, 11:11am UTC](https://discuss.elastic.co/t/mapping-how-to-do-your-own-calculations/280641/1 "2021-08-06T11:11:47Z")

</div>

How can we do our own calculations through mappings? I've try this configuration but I get an error:

```auto
PUT nameIndex/_mapping
{
  "runtime": {
    "cpuIndex": {
      "type": "long",
      "script": {
        "source": "emit(doc['system.cpu.cores'].value + doc['system.cpu.system.pct'].value) / doc['system.cpu.cores'].value)"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)\
**Post date:** [August 6, 2021, 6:16pm UTC](https://discuss.elastic.co/t/mapping-how-to-do-your-own-calculations/280641/2 "2021-08-06T18:16:54Z")

</div>

Can you share what error you're getting?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [August 6, 2021, 9:59pm UTC](https://discuss.elastic.co/t/mapping-how-to-do-your-own-calculations/280641/3 "2021-08-06T21:59:45Z")

</div>

Hi @NoobUser404

> [@NoobUser404](#):
>
> `"source": "emit(doc['system.cpu.cores'].value + doc['system.cpu.system.pct'].value) / doc['system.cpu.cores'].value)"`

Well for 1 you have a syntax error and extra `)` here `doc['system.cpu.system.pct'].value)` \<!---

Also I am not sure if that is just a sample calc but it really does not make sense adding the normalized CPU % to the number of cores.

3rd that will probably result in a double and you have a `long` defined

---

<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:** [September 3, 2021, 10:00pm UTC](https://discuss.elastic.co/t/mapping-how-to-do-your-own-calculations/280641/4 "2021-09-03T22:00:38Z")

</div>

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