简体   繁体   中英

enable groovy scripting on 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 .

更新配置后,您需要重新启动elasticsearch。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM