Elasticsearch Dynamic Scripting Disabled
Asked Answered
D

1

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

Dialectics answered 12/7, 2014 at 8:34 Comment(1)
For Elasticsearch 2.x.x use script.inline: on script.indexed: onDoityourself
D
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

Dialectics answered 12/7, 2014 at 8:58 Comment(5)
That setting is no longer recognised in elasticsearch 2.0. Instead, use: script.inline: on script.indexed: onRisser
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?Ephrem
Maybe #23474716. 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.Dialectics
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 ?Anthurium
@Anthurium ElasticSearch 1.4.4? My idea would be to upgrade!Andrus

© 2022 - 2024 — McMap. All rights reserved.