使用 elasticsearch 中预装的脚本进行更新
update with script pre-installed in elasticsearch
为了安全起见,我想以 [https://www.elastic.co/blog/running-groovy-scripts-without-dynamic-scripting ] 的方式使用脚本。
我在 sense
(chrome 插件)中试过了,效果很好。想知道如何在 elastic4s 中实现这一点。
比如我想从doc中删除一个字段,代码如下:
def replaceWithId(alarmId: String, fieldName: String, fieldValue: Map[String, Any]) = {
client.execute {
update id alarmId in IndexType script """{"file":"removeOperationField"}"""
}}
但是失败了。
您需要设置脚本类型,而不是将其明确包含在 json 中,例如:
def replaceWithId(alarmId: String) = {
client.execute {
update id alarmId in IndexType script("scriptname", ScriptType.File)
}
}
为了安全起见,我想以 [https://www.elastic.co/blog/running-groovy-scripts-without-dynamic-scripting ] 的方式使用脚本。
我在 sense
(chrome 插件)中试过了,效果很好。想知道如何在 elastic4s 中实现这一点。
比如我想从doc中删除一个字段,代码如下:
def replaceWithId(alarmId: String, fieldName: String, fieldValue: Map[String, Any]) = {
client.execute {
update id alarmId in IndexType script """{"file":"removeOperationField"}"""
}}
但是失败了。
您需要设置脚本类型,而不是将其明确包含在 json 中,例如:
def replaceWithId(alarmId: String) = {
client.execute {
update id alarmId in IndexType script("scriptname", ScriptType.File)
}
}