groovy - ElasticSearch 1.5升级:JodaTime转换脚本错误

标签 groovy elasticsearch jodatime

我正在努力将ElasticSearch版本从1.3升级到1.5。我们大量使用Java API。 ES查询中的以下脚本:

 {
  "script" : {
    "script" : "values contains (int)doc['timestamp'].date.toDateTime(DateTimeZone.forID('America/New_York')).getMonthOfYear()",
    "params" : {
      "values" : [ 1 ]
    },
    "lang" : "groovy"
  }
}

这适用于1.3,但在1.5中给出以下错误:
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query_fetch], all shards failed; shardFailures {[XwOu9zq0TMi2uOptdfIS7w][eventdata][0]: QueryPhaseExecutionException[[eventdata][0]: query[filtered(ConstantScore(ScriptFilter(values contains (int)doc['timestamp'].date.toDateTime(DateTimeZone.forID('America/New_York')).getMonthOfYear().toString())))->cache(org.elasticsearch.index.search.nested.NonNestedDocsFilter@2a8c0465)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingMethodException[No signature of method: Script1.contains() is applicable for argument types: (java.lang.Class) values: [int]
Possible solutions: toString(), toString(), notify()]]; }
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:238)
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:184)
    at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:565)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

解决此问题的最佳方法是什么?

最佳答案

这看起来像是强制转换的括号问题,因此它认为您正在将int传递给contains。尝试添加方括号以帮助解析器:

values.contains((int)doc['timestamp'].date.toDateTime(DateTimeZone.forID('Ameri‌​ca/New_York')).getMonthOfYear())

关于groovy - ElasticSearch 1.5升级:JodaTime转换脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31123994/

相关文章:

Groovy:在运行时检查对象是否为字符串

groovy - 如何在 : new XmlSlurper(). parse(URL) 中设置用户代理

elasticsearch - 为什么 Logstash 不会基于 grok'd 字段合并行?

csv - 如何在logstash中将 `include_headers => true`添加到csv编解码器以进行s3输出?

java - 字符串到 LocalDate 的 Joda 时间解析不正确

java - 使用继承的 Groovy 命令无法在 Spring Boot 远程 shell 中编译

database - Grails动态数据库连接?

php - Elasticsearch - 2019 年按嵌套字段排序

java - 从 joda 时间到 java.time 的 `w` 符号格式不一致

java - Joda 时间的 LocalDate 间隔