-1

When i run this code in Elasticsearch 2.4.0 and in this i used script and language as groovy.i stored the file in config/scripts/test.groovy.

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

It is showing error like this

{
  "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
}

And also i enabled the following in elasticsearch.yml

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

My test.groovy script contains the following code

Date date = new Date(doc[date_field].value) ;
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(format);
format.format(date)
Private
  • 1,661
  • 1
  • 20
  • 51

1 Answers1

0

The documentation seems to show you have your query format wrong

{
   "aggs": {
    "byDays": {
      "terms": {
        "script": {
            "file": "test",
            "params": {
                "date_field": "created_at",
                "format": "EEEEEE"
            }
        }
      }
    }
  }
}
tim_yates
  • 167,322
  • 27
  • 342
  • 338