# Painless script\_field returns just that field in query result?

**URL:** <https://discuss.elastic.co/t/painless-script-field-returns-just-that-field-in-query-result/240852>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 12, 2020, 6:07pm UTC](https://discuss.elastic.co/t/painless-script-field-returns-just-that-field-in-query-result/240852 "2020-07-12T18:07:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![teebu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/teebu/32/10119_2.png) [@teebu](https://discuss.elastic.co/u/teebu)\
**Post date:** [July 12, 2020, 6:07pm UTC](https://discuss.elastic.co/t/painless-script-field-returns-just-that-field-in-query-result/240852/1 "2020-07-12T18:07:24Z")

</div>

I don't see any mention in the docs about this.

When using a script\_field, only that field is returned in the results, not with the rest of the document, I have to add includes to get the rest of the fields?

```auto
 GET data/_search
 {
   //"_source": { "includes": ["*"]},
   "query": {"match_all": {}},
   "script_fields" : {
         "new_field" : {
             "script" : {
                 "source": "'hello'"
             }
         }
   }
 }

```

Results:

```auto
 {
         "_index" : "data",
         "_type" : "_doc",
         "_id" : "1",
         "_score" : 1.0,
         "fields" : {
           "new_field" : [
             "hello"
           ]
         }
       },

```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [July 12, 2020, 7:07pm UTC](https://discuss.elastic.co/t/painless-script-field-returns-just-that-field-in-query-result/240852/2 "2020-07-12T19:07:08Z")

</div>

We should certainly document that. I think the idea is that we default to fetching source but if you ask for something we figure you ask for everything you want.

Could you file an issue asking to update the docs? Or open a PR of you are feeling adventurous.

---

<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, 2020, 7:07pm UTC](https://discuss.elastic.co/t/painless-script-field-returns-just-that-field-in-query-result/240852/3 "2020-08-09T19:07:10Z")

</div>

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