2015-06-25 57 views
0

出於安全目的,我想以[https://www.elastic.co/blog/running-groovy-scripts-without-dynamic-scripting]的方式使用腳本。用elasticsearch預安裝的腳本更新

我在sense(chrome插件)中試過,效果很好。想知道如何在elastic4s中實現這一點。

例如,我想刪除從文檔的字段,這樣的代碼:

def replaceWithId(alarmId: String, fieldName: String, fieldValue: Map[String, Any]) = { 
client.execute { 
    update id alarmId in IndexType script """{"file":"removeOperationField"}""" 

}} 

,但失敗了。

+0

是您的文件實際上是所謂的「removeOperationField」或「removeOperationField.groovy」什麼? – monkjack

+0

文件名是removeOperationField,因爲它的類型是groovy,所以我們不必聲明lang。 –

+0

java客戶端可以通過'client.prepareUpdate(「index」,「type」,「id」)做到這一點 .setScript(「removeIpField」,ScriptService.ScriptType.FILE) .get' –

回答

0

您需要設置腳本類型,而不是把它放置在JSON明確,如:

def replaceWithId(alarmId: String) = { 
    client.execute { 
    update id alarmId in IndexType script("scriptname", ScriptType.File) 
    } 
} 
+0

升級到elastic4s 1.6.0後,我終於看到了這個功能。我在1.3.3腳本(字符串)不能指定腳本類型。 –