29

I am trying the following query on aggregation:

aggs:{
    total:{
        sum:{
            script: "doc['comments'].value + doc['likes'].value + doc['shares'].value"
        }   
    }
}

and it throws the following exception:

ScriptException[dynamic scripting disabled]

Any idea how can I fix this. Refer:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html

1
  • For Elasticsearch 2.x.x use script.inline: on script.indexed: on Commented Jun 24, 2016 at 9:47

1 Answer 1

54

By default dynamic scripting is disabled in elasticsearch, we need to add the following line in elasticsearch.yml file:

script.disable_dynamic: false

Refer: http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.5/modules-scripting.html#_enabling_dynamic_scripting

Also we need to make sure when we are enabling dynamic scripting, the elasticsearch ports are not public. specially the port used by nodes for communication. (9300 by default) Otherwise it has security vulnerability and allows attackers to join the cluster and do port scanning or make DDOS attacks.

UPDATE

For ES Version 1.6+

It is possible to enable scripts based on their source, for every script engine, through the following settings that need to be added to the config/elasticsearch.yml file on every node.

script.inline: on
script.indexed: on

Refer: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#enable-dynamic-scripting

Sign up to request clarification or add additional context in comments.

5 Comments

That setting is no longer recognised in elasticsearch 2.0. Instead, use: script.inline: on script.indexed: on
Im still not able to run function_score queries even with these changes, I am always getting the following error: Parse Failure [No parser for element [function_score]]. Any ideas?
Maybe stackoverflow.com/questions/23474216/…. Could you share your specific query? Better if you post a new question about it and add a link to that question in the comments.
I use ElasticSearch 1.4.4: I added the three lines (script.disable_dynamic: false, script.inline: on, script.indexed: on) but it still does not work. Error message : scripts of type [inline], operation [search] and lang [python] are disabled ... Any idea ?
@cherah30 ElasticSearch 1.4.4? My idea would be to upgrade!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.