ES使用脚本进行局部更新的排错记录 推荐
2016-05-19 23:25
525 查看
初学Elasticsearch,在按照《Elasticsearch服务器开发(第2版)》进行学习的过程中,在P17页中
由于默认Elasticsearch没有打开Groovy的update权限,因此我们无法通过Groovy进行更新操作,通过上述配置打开权限之后,就可以进行更新操作了。
1.4.5 更新文档小节,使用脚本对文档进行局部更新的时候遇到了如下报错:
~ curl -XPOST http://127.0.0.1:9200/blog/article/1/_update -d '{"script": "ctx._source.content=\"new content\""}' { "error":{ "root_cause":[{ "type":"remote_transport_exception", "reason":"[Lady Mandarin][127.0.0.1:9300][indices:data/write/update[s]]" } ], "type":"illegal_argument_exception", "reason":"failed to execute script", "caused_by":{ "type":"script_exception", "reason":"scripts of type [inline], operation [update] and lang [groovy] are disabled"}}, "status":400 }%我根据提示中的原因
"scripts of type [inline], operation [update] and lang [groovy] are disabled"进行了查询,查到了官网文档关于对脚本更新的介绍(介绍链接)。通过粗略查看文档,我发现要解决这个问题,需要在Elasticsearch的配置文件
elasticsearch.yml中添加如下配置:script.engine.groovy.inline.update: on由于Elasticsearch默认使用的是Groovy语言。Groovy语言一个快速且功能丰富的脚本语言,语法类似于Javascript。它在一个沙盒(sandbox)中运行,以防止恶意用户毁坏Elasticsearch或攻击服务器。
由于默认Elasticsearch没有打开Groovy的update权限,因此我们无法通过Groovy进行更新操作,通过上述配置打开权限之后,就可以进行更新操作了。
~ curl -XPOST http://127.0.0.1:9200/blog/article/1/_update -d '{"script": "ctx._source.content=\"new content\""}' { "_index":"blog", "_type":"article", "_id":"1", "_version":2, "_shards":{ "total":2, "successful":1, "failed":0 } }%
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法