本文共 947 字,大约阅读时间需要 3 分钟。
ES 版本:2.3.5
安装执行如下命令:DELETE testPUT test/doc/1{ "num": 1.0}PUT test/doc/2{ "num": 2.0}POST test/_search{ "query": { "function_score": { "script_score": { "script": { "inline": "doc[\"num\"].value * factor", "lang": "javascript", "params": { "factor": 2 } } } } }}
返回错误结果如下:
"caused_by": {"type": "illegal_argument_exception","reason": "script_lang not supported [javascript]"}
网上很多解决方法都说是没有开启es的脚本功能,需要在elasticsearch.yml中加如下配置:
script.inline: onscript.indexed: onscript.groovy.sandbox.enabled: truescript.engine.groovy.inline.update: on
加入配置后还是报同样的错误。
后来发现要支持javascript,除了加入上述配置外,还需要给es安装插件
在ES安装目录下执行如下命令安装插件:
./bin/plugin install lang-javascript
这样问题就解决了。
1、在elasticsearch.yml中加如下配置:
script.inline: onscript.indexed: onscript.groovy.sandbox.enabled: truescript.engine.groovy.inline.update: on
2、在ES安装目录下执行如下命令安装插件:
./bin/plugin install lang-javascript
3、重启es
转载地址:http://bwydn.baihongyu.com/