无法使用lang [groovy]运行内联脚本[test]

时间:2017-01-06 12:39:52

标签: elasticsearch groovy

当我在Elasticsearch 2.4.0中运行此代码时,我使用的脚本和语言如groovy.i将文件存储在config / scripts / test.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)

1 个答案:

答案 0 :(得分:0)

documentation似乎表明您的查询格式错误

$ list_without_colours = ['hurley', 'maladroit']
$ if approved_colours.intersection(list_without_colours):
$     print("There are colours present")
$ else:
$     print("There are no colours present")
> "There are no colours present"