# Accessing \_source from script search in 5.0

**URL:** <https://discuss.elastic.co/t/accessing--source-from-script-search-in-5-0/64358>\
**Category:** Elasticsearch\
**Created:** [October 29, 2016, 10:45pm UTC](https://discuss.elastic.co/t/accessing--source-from-script-search-in-5-0/64358 "2016-10-29T22:45:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_Garfinkiel](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@Nicolas\_Garfinkiel](https://discuss.elastic.co/u/Nicolas_Garfinkiel)\
**Post date:** [October 29, 2016, 10:45pm UTC](https://discuss.elastic.co/t/accessing--source-from-script-search-in-5-0/64358/1 "2016-10-29T22:45:24Z")

</div>

Hey all, I think I'm going crazy... Could someone tell me why I fail to access the \_source field on this query?

```
{
  "size": 0,
  "query": {
    "constant_score": {
      "filter": {
        "script": {
          "script": {
            "inline": "_source.lab_tests.length > 0"
          }
        }
      }
    }
  }
}

```

I get...

```
{
    "type": "script_exception",
    "reason": "compile error",
    "caused_by": {
    "type": "illegal_argument_exception",
    "reason": "Variable [_source] is not defined."
 }

```

Thank you in advance

---

<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:** [October 30, 2016, 2:27am UTC](https://discuss.elastic.co/t/accessing--source-from-script-search-in-5-0/64358/2 "2016-10-30T02:27:46Z")

</div>

`_source` isn't supported in Painless.... You can get it with groovy still.

It isn't supported because it is so, so, so much slowed than loading fields from doc values. Like several orders of magnitude slower in most cases.

---

<div class="post-metadata">

**Author:** ![Nicolas\_Garfinkiel](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@Nicolas\_Garfinkiel](https://discuss.elastic.co/u/Nicolas_Garfinkiel)\
**Post date:** [October 30, 2016, 3:09pm UTC](https://discuss.elastic.co/t/accessing--source-from-script-search-in-5-0/64358/3 "2016-10-30T15:09:13Z")

</div>

I see... Didn't see it in the docs though. Is it there?

Anyways, I understand `doc_values` access is way faster than `_source`, that most use cases deal with values already in `doc_values`, and some features require hard limits for safety's sake.

What I don't understand is the call for blocking a feature because it is not as performant as another feature. Painless works inline as is, and it is very useful for ad\_hoc querying. It is stupid to store a groovy query for a quick question and unsafe to allow it to run inline. I needed a quick answer from a field that is not indexed because I don't need it at query time for my application.

Why don't let the user worry about the consequences? In a SQL database you can easily blow it by issuing a simple `SELECT`, but you can issue it anyways.

My two cents, and thanks alot nick BTW.

Cheers.

---

<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:** [July 5, 2017, 10:08pm UTC](https://discuss.elastic.co/t/accessing--source-from-script-search-in-5-0/64358/4 "2017-07-05T22:08:28Z")

</div>


