我想使用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