2

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.

1

1 Answer 1

-1

You need to restart elasticsearch after updating the config.

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

1 Comment

Encountering this exact same problem after many permutations of settings and restarts. I don't think failing to reload the config file is the issue.

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.