Enable groovy scripting in Elasticsearch

I am trying to enable groovy scripts on my elastic search.

I have updated my elasticsearch.yml file with following lines

script.inline: true
script.groovy.sandbox.enabled: true
script.inline: on
script.indexed: on
script.search: on
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.search: on
I then craeted a script using this

curl -XPOST localhost:9200/_scripts/groovy/indexedCalculateScore -d '{
"script": "log(_score * 2) + my_modifier"
}'
and tried to access it using :

curl -XPOST localhost:9200/_search -d '{
"query": {
"function_score": {
"query": {
"match": {
"body": "foo"
}
},
"functions": [
{
"script_score": {
"script": {
"id": "indexedCalculateScore",
"lang" : "groovy",
"params": {
"my_modifier": 8
}
}
}
}
]
}
}
}'
I am getting following exception

{"error":{"root_cause":[{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"},{"type":"script_exception","reason":"scripts of type [indexed], operation [search] and lang [groovy] are disabled"}

It seems from the logs that groovy is not enabled.

Can anybody help out with configurations.

Also please help as how can i write dynamic in elasticsearch using groovy?

I am using following link to enable groovy scripting in elasticsearch

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