# \_index not accessible inside external script file?

**URL:** <https://discuss.elastic.co/t/-index-not-accessible-inside-external-script-file/35794>\
**Category:** Elasticsearch\
**Created:** [November 28, 2015, 12:22am UTC](https://discuss.elastic.co/t/-index-not-accessible-inside-external-script-file/35794 "2015-11-28T00:22:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cshah](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cshah](https://discuss.elastic.co/u/cshah)\
**Post date:** [November 28, 2015, 12:22am UTC](https://discuss.elastic.co/t/-index-not-accessible-inside-external-script-file/35794/1 "2015-11-28T00:22:10Z")

</div>

I am able to run the following query successfully

```auto
{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "stadt": {
      "sum": {
        "script": "_index['title']['energy'].tf()"
      }
    }
  },
  "size": 0
}

```

But I dont want to enable `dynamic scripting` so I put the content of script into external file inside `es/config/scripts/tfscript.groovy`

Now the following query throws exception

```auto
{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "stadt": {
      "sum": {
        "script": {
          "file": "tfscript"
        }
      }
    }
  },
  "size": 0
}

```

The exception is

```auto
	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:747)
	at org.elasticsearch.search.SearchService.createContext(SearchService.java:572)
	at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:544)
	at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:385)
	at org.elasticsearch.search.action.SearchServiceTransportAction$11.call(SearchServiceTransportAction.java:333)
	at org.elasticsearch.search.action.SearchServiceTransportAction$11.call(SearchServiceTransportAction.java:330)
	at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.search.SearchParseException: [enerknol][0]: query[ConstantScore(*:*)],from[-1],size[0]: Parse Failure [Unexpected token START_OBJECT in [stadt].]
	at org.elasticsearch.search.aggregations.metrics.NumericValuesSourceMetricsAggregatorParser.parse(NumericValuesSourceMetricsAggregatorParser.java:61)
	at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:148)
	at org.elasticsearch.search.aggregations.AggregatorParsers.parseAggregators(AggregatorParsers.java:78)
	at org.elasticsearch.search.aggregations.AggregationParseElement.parse(AggregationParseElement.java:60)
	at org.elasticsearch.search.SearchService.parseSource(SearchService.java:731)

```

I searched for `Unexpected token START_OBJECT in [stadt]` but could not figure out anything.  
Am I missing something basic here?

---

<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, 11:35pm UTC](https://discuss.elastic.co/t/-index-not-accessible-inside-external-script-file/35794/2 "2017-07-05T23:35:15Z")

</div>

Closed on July 5, 2017, 11:35pm UTC


