# Not able to execute painless scripts

**URL:** <https://discuss.elastic.co/t/not-able-to-execute-painless-scripts/197339>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [August 29, 2019, 12:48pm UTC](https://discuss.elastic.co/t/not-able-to-execute-painless-scripts/197339 "2019-08-29T12:48:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manish\_kakoti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manish_kakoti/32/53285_2.png) [@manish\_kakoti](https://discuss.elastic.co/u/manish_kakoti)\
**Post date:** [August 29, 2019, 12:48pm UTC](https://discuss.elastic.co/t/not-able-to-execute-painless-scripts/197339/1 "2019-08-29T12:48:10Z")

</div>

I am quite new to painless or any kind of scripting in elastic.

I wanted to know how do i execute a script in elastic.

Scenario: I have a `mapping.json`, with all the fields to be indexed in elastic. I am using elasticsearchjs npm module as my code is in typescript. So to execute the script which is basically adding a new field to an existing document. Looks somewhat like this `"ctx._source.name = SZ_MK.pdf"`.

Now my question is where do i add --\>

```auto
      "inline": "ctx._source.name = SZ_MK.pdf",
      "lang": "painless"
    }

```

so that it gets executed is it within `mappings` or somewhere else?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [August 30, 2019, 5:52pm UTC](https://discuss.elastic.co/t/not-able-to-execute-painless-scripts/197339/2 "2019-08-30T17:52:01Z")

</div>

It depends on what you are trying to do. If you want to update a single document, you can use the [update api](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html). If you are trying to update all of your documents, then look at [update\_by\_query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html). And if you want to modify documents as they are indexed then look at [ingest scripts](https://www.elastic.co/guide/en/elasticsearch/reference/master/script-processor.html).

---

<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 27, 2019, 5:52pm UTC](https://discuss.elastic.co/t/not-able-to-execute-painless-scripts/197339/3 "2019-09-27T17:52:07Z")

</div>

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