# Add field to search results

**URL:** <https://discuss.elastic.co/t/add-field-to-search-results/272928>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [May 13, 2021, 3:31pm UTC](https://discuss.elastic.co/t/add-field-to-search-results/272928 "2021-05-13T15:31:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fast.fart](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fast.fart](https://discuss.elastic.co/u/fast.fart)\
**Post date:** [May 13, 2021, 3:31pm UTC](https://discuss.elastic.co/t/add-field-to-search-results/272928/1 "2021-05-13T15:31:03Z")

</div>

Hi,  
I want to set field value in search results.  
Let's say for some documents field **xxx** is not so I need to set the value based on other fields.  
I tried to use a simple script below but it only adds **fields** object but not a field inside **\_source**

```auto
    {
        "query": { ... }
        "script_fields": {
            "sample_script": {
                "script": {
                    "lang": "painless",
                    "source": "params._source.title"
                }
            }
        }
    }

```

Is there a way to set value for **\_source.xxx** using script?

---

<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:** [June 10, 2021, 3:31pm UTC](https://discuss.elastic.co/t/add-field-to-search-results/272928/2 "2021-06-10T15:31:19Z")

</div>

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