2017-01-06 3 views
-1

Когда я запускаю этот код в Elasticsearch 2.4.0, и в этом я использовал скрипт и язык как groovy.i, сохранил файл в config/scripts/test.groovy.Не удалось запустить встроенный скрипт [test] с помощью 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

Thankyou это действительно помогло – Seeker

+0

Но, это вещь, которая работала для меня в ES 2.4.0. Я думаю, что документация, о которой вы говорили, относится к ES 5.1.1. – Seeker

Смежные вопросы