2015-06-29 19 views
0

我正在將ElasticSearch版本從1.3升級到1.5。我們大量使用Java API。在ES查詢下面的腳本:ElasticSearch 1.5升級:JodaTime轉換腳本錯誤

{ 
    "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([email protected]65)],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) 

什麼是解決這個問題的最好方法是什麼?

+1

你可以嘗試在括號中?看起來它正在做'contains(int)'即:'values.contains((int)doc ['timestamp']。date.toDateTime(DateTimeZone.forID('America/New_York'))。getMonthOfYear())' –

+0

@ tim_yates我會添加這個答案。我測試了它,它工作。 –

回答

1

這看起來像是一個括號問題,因此它認爲你傳遞的是包含int。嘗試添加括號來幫助解析器:

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

這就是它!我已經測試和確認。非常感謝你。 –