ElasticSearch获取Groovy脚本中的时间 [英] ElasticSearch Get Time in Groovy Script
问题描述
我的应用程序正在使用此脚本来提升索引中的更新项目:
(5 /((3.16 * pow (10,-11))* abs(time() - doc [\'date\']。date.getMillis())+ 0.2))+ 1.0
pre>
它是用MVEL编写的,但从1.3开始,对于Groovy,MVEL已被弃用。脚本现在引发了这个错误:
GroovyScriptExecutionException [MissingMethodException] [没有方法的签名:Script4.time()适用于参数类型:()values:[] \\\
Possible solutions:find(),dump(),find(groovy.lang.Closure),use([Ljava.lang.Object;))是(java.lang.Object),with (groovy.lang.Closure)]]
这听起来像是获得毫秒时间戳的功能在Groovy不同。我试过
System.currentTimeMillis()
,但它又提出了不支持导入的错误。
所以如何修复
time()
函数与Groovy一起使用?解决方案p>如您已经发现的,您需要在Groovy中重写脚本,而不是MVEL。而不是时间,您需要使用
DateTime.now()。getMillis()
。以下是您使用它的示例: http:// writequit。 org / org / es / index.html#time-in-groovy-scriptMy application is using this script for boosting more recent items in the index:
(5 / ((3.16*pow(10,-11)) * abs(time() - doc[\'date\'].date.getMillis()) + 0.2)) + 1.0
It's written in MVEL, but as of 1.3, MVEL is deprecated for Groovy. The script throws this error now:
GroovyScriptExecutionException[MissingMethodException[No signature of method: Script4.time() is applicable for argument types: () values: []\nPossible solutions: find(), dump(), find(groovy.lang.Closure), use([Ljava.lang.Object;), is(java.lang.Object), with(groovy.lang.Closure)]]
This sounds to me like the function for getting a millisecond timestamp is different in Groovy. I tried
System.currentTimeMillis()
, but it gave another error saying it didn't support imports.So how can I fix the
time()
function to work with Groovy?解决方案As you already have discovered, you need to rewrite your script in Groovy instead of MVEL. Instead of time you need to use
DateTime.now().getMillis()
. Here's an example of how you use it: http://writequit.org/org/es/index.html#time-in-groovy-script这篇关于ElasticSearch获取Groovy脚本中的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!