Sure,
scripting has to be enabled in your elasticsearch instance. So add e.g. the following two lines to your elasticsearch.yml :
script.inline: true
script.stored: true
See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-scripting-security.html#enable-dynamic-scripting for more details.