# Script processor not adding a new field using ingest pipeline

**URL:** https://discuss.elastic.co/t/script-processor-not-adding-a-new-field-using-ingest-pipeline/343165
**Category:** Elasticsearch
**Tags:** painless, ingest-pipeline
**Created:** [September 15, 2023, 9:54pm UTC](https://discuss.elastic.co/t/script-processor-not-adding-a-new-field-using-ingest-pipeline/343165 "2023-09-15T21:54:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rubhamra](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rubhamra](https://discuss.elastic.co/u/rubhamra)
#### Post date: [September 15, 2023, 9:54pm UTC](https://discuss.elastic.co/t/script-processor-not-adding-a-new-field-using-ingest-pipeline/343165/1 "2023-09-15T21:54:23Z")

</div>

I am trying to compare values with already data already indexed with some user input values  
through script processor,  
script is running successfully but its not creating a new field which actually stores the result.

```auto
		{
	  "script": {
    "source": """
      if (!ctx.containsKey('manager-list.keyword') || ctx['manager-list.keyword'].size() == 0) {
    return;
}
if (ctx.containsKey('manager-list.keyword')) {
def managerName = ctx['manager-list.keyword'].value;
      def givenValues = ['xyz@gmail.com', 'yyy@gmail.com'];
      
      for (String value : givenValues) {
        if (managerName == value) {
          ctx.result = value;
          break;
        }
      }
}
    """,
  "lang": "painless"
		}
	}

```

I want to store the output in a field so I guess result variable would be added as new field but it's not working.

After that I am running update\_by\_query to update the data. but no success  
could you please check.

---

<div class="post-metadata">

### Author: ![rubhamra](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rubhamra](https://discuss.elastic.co/u/rubhamra)
#### Post date: [September 18, 2023, 1:49pm UTC](https://discuss.elastic.co/t/script-processor-not-adding-a-new-field-using-ingest-pipeline/343165/2 "2023-09-18T13:49:17Z")

</div>

Could you please check why its not creating a new field 'result'

---

<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: [October 16, 2023, 1:50pm UTC](https://discuss.elastic.co/t/script-processor-not-adding-a-new-field-using-ingest-pipeline/343165/3 "2023-10-16T13:50:03Z")

</div>

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