Elasticsearch unable to find scripts in the script folder


(Vaibhav Yadav) #1

Hi,
I am trying to do scripted metric aggregation by following the example given at:
https://www.elastic.co/guide/en/elasticsearch/reference/2.0/search-aggregations-metrics-scripted-metric-aggregation.html

The issue I am facing is that elasticsearch is unable to find the script in the scripts folder.
The various paths are:
Elasticsearch home: /usr/share/elasticsearch/
Elasticsearch config: /etc/elasticsearch
Elasticsearch script folder: /etc/elasticsearch/scripts

I have tried adding the path.config setting as:
path.config: /etc/elasticsearch/

The .sh file I am using for curl is as follows:

curl -XGET 'localhost:9200/transactions/stock/_search' -d '{
"aggs": {
"profit": {
"scripted_metric": {
"init_script" : {
"script_file": "my_init_script",
"lang": "groovy"
},
"map_script" : {
"script": "my_map_script",
"lang": "groovy"
},
"combine_script" : {
"script": "my_combine_script",
"lang": "groovy"
},
"params": {
"field": "amount"
},
"reduce_script" : {
"script": "my_reduce_script",
"lang": "groovy"
}
}
}
}
}'

The error I receive is as follows:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Unable to find on disk file script [my_init_script] using lang [groovy]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"transactions","node":"Z2yd_WbOQKGdAjK1J8b_MA","reason":{"type":"illegal_argument_exception","reason":"Unable to find on disk file script [my_init_script] using lang [groovy]"}}]},"status":400}

It would be great if anyone could help me figure out what I am doing wrong here?


(Mark Walkom) #2

It should be /etc/elasticsearch/config/scripts.


(David Pilato) #3

Also check that the filename extension is .groovy


(Jay Greenberg) #4

Seems obvious, but this can also happen if your ES conf directory is incorrect.

root$ ls /etc/elasticsearch
elasticsearch.yml  logging.yml	scripts

root$ elasticsearch -Des.default.path.conf=/etc/elasticsearch

Also, the permissions on all the config files, including the scripts, must be readable by the ES user.


(system) #5