2017-01-06 88 views
-1

當我在Elasticsearch 2.4.0中運行此代碼,並在此我使用腳本和語言作爲groovy.i存儲該文件在config/scripts/test.groovy。無法運行內嵌腳本[測試]使用lang [groovy]

{ 
    "aggs": { 
    "byDays": { 
     "terms": { 
     "script": "test", 
     "params": { 
      "date_field": "created_at", 
      "format": "EEEEEE" 
     } 
     } 
    } 
    } 
} 

它顯示錯誤這樣

{ 
    "error": { 
    "root_cause": [ 
     { 
     "type": "script_exception", 
     "reason": "failed to run inline script [test] using lang [groovy]" 
     } 
    ], 
    "type": "search_phase_execution_exception", 
    "reason": "all shards failed", 
    "phase": "query", 
    "grouped": true, 
    "failed_shards": [ 
     { 
     "shard": 0, 
     "index": "testindex-stats", 
     "node": "DIytd8uRSnaXXlwcq34Dow", 
     "reason": { 
      "type": "script_exception", 
      "reason": "failed to run inline script [test] using lang [groovy]", 
      "caused_by": { 
      "type": "missing_property_exception", 
      "reason": "No such property: test for class: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3" 
      } 
     } 
     } 
    ] 
    }, 
    "status": 500 
} 

,也是我啓用了elasticsearch.yml以下

script.engine.groovy.inline.search: on 
script.engine.groovy.inline.aggs: on 
script.groovy.sandbox.enabled: true 

我test.groovy腳本包含以下代碼

Date date = new Date(doc[date_field].value) ; 
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(format); 
format.format(date) 

回答

0

documentation似乎表明你有你的查詢格式錯

{ 
    "aggs": { 
    "byDays": { 
     "terms": { 
     "script": { 
      "file": "test", 
      "params": { 
       "date_field": "created_at", 
       "format": "EEEEEE" 
      } 
     } 
     } 
    } 
    } 
} 
+0

三江源它真的幫助 – Seeker

+0

但是,這是在ES 2.4.0爲我工作的事情。我認爲您提到的文檔適用於ES 5.1.1。 – Seeker