Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with inline script using Joda DateTimeZone. #18017

Closed
deanobarnett opened this issue Apr 27, 2016 · 7 comments · Fixed by #18609
Closed

Issue with inline script using Joda DateTimeZone. #18017

deanobarnett opened this issue Apr 27, 2016 · 7 comments · Fixed by #18609
Assignees
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache :Search/Mapping Index mappings, including merging and defining field types

Comments

@deanobarnett
Copy link

Using the offical Elasticsearch Docker image for 2.3.1

Elasticsearch version: 2.3.1

JVM version: java:8-jre

OS version: debian jessie

Description of the problem including expected versus actual behavior:

Actual

Using DateTimeZone with an inline script results in an error.

java.io.IOException: Resource not found: "org/joda/time/tz/data/America/New_York"

Expected

The Correct DateTimeZone instance to be returned.

Steps to reproduce:

  1. Start elasticsearch 2.3.1.
  2. Pass the startup param -Des.script.engine.groovy.inline.aggs=true
  3. Create index and mapping with a date_time_no_millis field.
  4. Run a search query like the one in Appendix: A
  5. Notice an error like The datetime zone id 'America/New_York' is not recognised
  6. Run a Date Histogram query like the one in Appendix: B
  7. The same error will occur
  8. Restart the elasticsearch instance
  9. Re-run Appendix A and B, they now both work.

Appendix

A: Aggregate Query

{
  "size": 0,
  "aggs": {
    "group_by_hour": {
      "terms": {
        "script": "def opDate = new DateTime(doc['operation_date'].date); opDate.withZone(DateTimeZone.forID('America/New_York')).getHourOfDay()",
        "order": {
          "_term": "asc"
        }
      }
    }
  }
}

B: Date Histogram Query

{
  "size": 0,
  "aggs": {
    "group_by_hour": {
      "date_histogram": {
        "field": "date_field",
        "interval": "hour",
        "format": "H",
        "time_zone": "America/New_York"
      }
    }
  }
}
@clintongormley clintongormley added >bug help wanted adoptme :Dates :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache labels Apr 29, 2016
@clintongormley
Copy link

Whether this fails or not depends on the order of requests, eg given this document:

PUT t/t/1
{
  "operation_date": "2001/10/10"
}

If you run a non-scripting agg which refers to the time zone first:

GET _search
{
  "aggs": {
    "NAME": {
      "date_histogram": {
        "field": "operation_date",
        "interval": "hour",
        "time_zone": "America/New_York"
      }
    }
  }
}

then this request succeeds, and so do the scripting request:

GET _search
{
  "size": 0,
  "aggs": {
    "group_by_hour": {
      "terms": {
        "script": "def opDate = new DateTime(doc['operation_date'].date); opDate.withZone(DateTimeZone.forID('America/New_York')).getHourOfDay()",
        "order": {
          "_term": "asc"
        }
      }
    }
  }
}

If you reverse the order of the searches, then both fail.

@gmoskovicz
Copy link
Contributor

If you don't have an aggregation, there is currently no way to get timezones and work with scripts. Any ETA on fixing this? Any workaround that can be defined inside the script?

I tried modifying the java.policy file but doesn't look like it works. Isn't this related to #14524? Is there any workaround other than performing a fake search operation before running the script?

@jasontedor
Copy link
Member

Modifying the java.policy file will not help, the issue is in Joda Time.

@gmoskovicz
Copy link
Contributor

gmoskovicz commented May 13, 2016

Thanks for the quick answer @jasontedor . So there isn't a real workaround? Is it related to JodaOrg/joda-time#327? Until this is not fixed, one cannot do this operation?

Is there something that we can do for this? Looks like the Joda Time issue has been opened for a while already.

@jasontedor jasontedor self-assigned this May 19, 2016
@jasontedor jasontedor removed the help wanted adoptme label May 19, 2016
@jasontedor
Copy link
Member

I opened JodaOrg/joda-time#375. When we can incorporate a new release of Joda Time that contains this into Elasticsearch we will be able to close this bug out.

@gmoskovicz
Copy link
Contributor

@jasontedor is this going to be added in a 2.3.x release for ES?

@jasontedor
Copy link
Member

jasontedor commented May 19, 2016

is this going to be added in a 2.3.x release for ES?

I don't know; we have to see if JodaOrg/joda-time#375 is accepted into Joda Time first, and if it is, the timeline under which a bug fix release of Joda Time is made that includes it that we can incorporate into Elasticsearch.

@clintongormley clintongormley added :Search/Mapping Index mappings, including merging and defining field types and removed :Dates labels Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache :Search/Mapping Index mappings, including merging and defining field types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants