我想使用ElasticSearch's _update api调用外部脚本。但是,似乎脚本从未实际运行。一个等效的内联脚本确实会进行预期的更新。ElasticSearch _update脚本文件未执行
任何想法为什么这可能是这种情况?
脚本是这样的:
脚本/ update_comments.groovy
"ctx._source.comments+=new_comment"
我的弹性查询看起来是这样的:
POST my_index/blog/1/_update
{
"script": {
"script_file": "update_comments",
"params": {
"new_comment": {
"name": "Jon Snow",
"comment": "Winter is coming"
}
}
}
}
运行GET /my_index/blog/1
返回原始文件,而不是更新即请注意,_version
数字会递增,但没有任何变化。
{
"_index": "my_index",
"_type": "blog",
"_id": "1",
"_version": 2,
"found": true,
"_source": {
"name": "Guy",
"body": "This is a post",
"comments": [
{
"name": "Foo bar",
"comment": "Great article"
}
]
}
}
为了测试,我设置script.groovy.sandbox.enabled: true
并运行相同的查询,只需用一个内嵌的脚本:
{
"script": "ctx._source.comments+=new_comment",
"params": {
"new_comment": {
"name": "Jon Snow",
"comment": "Winter is coming"
}
}
}
,并得到了预期的结果:
{
"_index": "my_index",
"_type": "blog",
"_id": "1",
"_version": 3,
"found": true,
"_source": {
"name": "Guy",
"body": "This is a post",
"comments": [
{
"name": "Foo Bar",
"comment": "Great article"
},
{
"name": "Jon Snow",
"comment": "Winter is coming"
}
]
}
}
它保存在正确的地方,否则我会得到一个错误说,它不能被发现。我也看到在标准输出脚本加载 – funseiki
然后这是不正确的'config/update_comments.groovy'和误导 – Val
你有'script.file:true'在你的配置? – Val