当前位置:  开发笔记 > 前端 > 正文

script_score脚本无法加载[inline]类型的脚本,操作[search]和lang [groovy]被禁用

如何解决《script_score脚本无法加载[inline]类型的脚本,操作[search]和lang[groovy]被禁用》经验,为你挑选了1个好方法。

目前我使用的是Elastisearch 1.5.
我想更新到Elasticsearch 1.7.

然后当我在ES1.7以下运行查询时,我得到了错误

嵌套:QueryParsingException [[my_index] script_score脚本无法加载]; 嵌套:ScriptException [类型为[inline],operation [search]和lang [groovy]的脚本被禁用]; .

此查询肯定适用于ES 1.5环境.我想对ES 1.7使用相同的查询.

{
  "query": {
    "function_score": {
      "query": {
        "filtered": {
          "query": {
            "query_string": {
              "fields": [
                "itemname"
              ],
              "query": "coke"
            }
          }
        }
      },
      "script_score": {
        "script": "_score + doc['myscore'].value"
      }
    }
  }
}

我已经阅读过这份文件了. https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#enable-dynamic-scripting

所以,我已将下面的选项添加到我的elasticsearch.yml中.

script.inline: on  
script.indexed: on 
script.engine.groovy.inline.aggs: on  

我做了重新启动elasticsearch守护进程并再次创建索引,但我仍然得到了错误.

有谁建议我如何解决这个问题?

添加

[root@elasticsearch]# curl -XGET 'http://localhost:9200'
{
  "status" : 200,
  "name" : "Ghost Girl",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "1.7.1",
    "build_hash" : "b88f43fc40b0bcd7f173a1f9ee2e97816de80b19",
    "build_timestamp" : "2015-07-29T09:54:16Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

[root@elasticsearch]# tail -n 10 /etc/elasticsearch/elasticsearch.yml
# http server. With this enabled, it may pose a security risk, so disabling
# it unless you need it is recommended (it is disabled by default).
#
#http.jsonp.enable: true

script.groovy.sandbox.enabled: true
script.inline: on
script.indexed: on
script.search: on
script.engine.groovy.inline.aggs: on

[root@elasticsearch]# /etc/rc.d/init.d/elasticsearch restart
Stopping elasticsearch:                                    [  OK  ]
Starting elasticsearch:                                    [  OK  ]

[root@elasticsearch]# curl -XPOST 'localhost:9200/my_index/_search?pretty' -d '{
>   "query": {
>     "function_score": {
>       "query": {
>         "filtered": {
>           "query": {
>             "query_string": {
>               "fields": [
>                 "itemname"
>               ],
>               "query": "coke"
>             }
>           }
>         }
>       },
>       "script_score": {
>         "script": "_score * 0.5"
>       }
>     }
>   }
> }'
{
  "took" : 3029,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 3,
    "failed" : 2,
    "failures" : [ {
      "index" : "my_index",
      "shard" : 1,
      "status" : 400,
      "reason" : "RemoteTransportException[[Fury][inet[/xx.xx.xx.xx:9300]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[ss][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n  \"query\": {\n    \"function_score\": {\n      \"query\": {\n        \"filtered\": {\n          \"query\": {\n            \"query_string\": {\n              \"fields\": [\n                \"itemname\"\n              ],\n              \"query\": \"coke\"\n            }\n          }\n        }\n      },\n      \"script_score\": {\n        \"script\": \"_score * 0.5\"\n      }\n    }\n  }\n}]]]; nested: QueryParsingException[[my_index] script_score the script could not be loaded]; nested: ScriptException[scripts of type [inline], operation [search] and lang [groovy] are disabled]; "
    }, {
      "index" : "my_index",
      "shard" : 4,
      "status" : 400,
      "reason" : "RemoteTransportException[[Fury][inet[/xx.xx.xx.xx:9300]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[my_index][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n  \"query\": {\n    \"function_score\": {\n      \"query\": {\n        \"filtered\": {\n          \"query\": {\n            \"query_string\": {\n              \"fields\": [\n                \"itemname\"\n              ],\n              \"query\": \"coke\"\n            }\n          }\n        }\n      },\n      \"script_score\": {\n        \"script\": \"_score * 0.5\"\n      }\n    }\n  }\n}]]]; nested: QueryParsingException[[my_index] script_score the script could not be loaded]; nested: ScriptException[scripts of type [inline], operation [search] and lang [groovy] are disabled]; "
    } ]
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

Arthur Xu.. 6

添加script.engine.groovy.inline.update: on到.yml文件



1> Arthur Xu..:

添加script.engine.groovy.inline.update: on到.yml文件

推荐阅读
大大炮
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有