# Scripted field failed to create

**URL:** <https://discuss.elastic.co/t/scripted-field-failed-to-create/139698>\
**Category:** Kibana\
**Created:** [July 12, 2018, 8:48am UTC](https://discuss.elastic.co/t/scripted-field-failed-to-create/139698 "2018-07-12T08:48:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyzhang6639](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hyzhang6639/32/32515_2.png) [@hyzhang6639](https://discuss.elastic.co/u/hyzhang6639)\
**Post date:** [July 12, 2018, 8:48am UTC](https://discuss.elastic.co/t/scripted-field-failed-to-create/139698/1 "2018-07-12T08:48:42Z")

</div>

I have created the scripted field as the following. I hope to perform a divide calculation for the sum of field1 and field2 with field3. But the below scripted fields can't be calculated. What's wrong with the below script?

(doc['field1'].value + doc['field2'].value) / doc['field3'].value

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 12, 2018, 3:54pm UTC](https://discuss.elastic.co/t/scripted-field-failed-to-create/139698/2 "2018-07-12T15:54:00Z")

</div>

What are the types for field1, field2, and field3? What error message is getting returned?

The best way to debug scripted fields is in the `Dev tools` application. Below is an example search command that uses scripted fields like your example

```auto
GET logstash-0/_search
{
  "query": {
    "match_all": {}
  },
  "script_fields" : {
    "myScriptedField" : {
      "script" : {
        "lang": "painless",
        "source": "(doc['bytes'].value + doc['bytes'].value) / doc['bytes'].value"
      }
    }
  }
}

```

---

<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 9, 2018, 3:54pm UTC](https://discuss.elastic.co/t/scripted-field-failed-to-create/139698/3 "2018-08-09T15:54:03Z")

</div>

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