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

[ML] Painless code in Watcher syntax created by ML throws IOException #18376

Closed
elasticmachine opened this issue Mar 30, 2018 · 1 comment
Closed
Assignees

Comments

@elasticmachine
Copy link
Contributor

Original comment by @richcollier:

Customer discovered the following error upon watch execution for the code that the ML builds for the user automatically when the user creates a watch from the ML UI:

unchecked_i_o_exception: java.io.IOException: can not write type [class java.time.LocalDateTime]

The error originates from the following scripts within the watch:

                    "script_fields": {
                      "start": {
                        "script": {
                          "lang": "painless",
                          "inline": "LocalDateTime.ofEpochSecond((doc[\"timestamp\"].date.getMillis()-((doc[\"bucket_span\"].value * 1000)\n * params.padding)) / 1000, 0, ZoneOffset.UTC)",
                          "params": {
                            "padding": 10
                          }
                        }
                      },
                      "end": {
                        "script": {
                          "lang": "painless",
                          "inline": "LocalDateTime.ofEpochSecond((doc[\"timestamp\"].date.getMillis()+((doc[\"bucket_span\"].value * 1000)\n * params.padding)) / 1000, 0, ZoneOffset.UTC)",
                          "params": {
                            "padding": 10
                          }
                        }
                      },

To make it work, we need to add the .toString() to cast the LocalDateTime object into a String.:

                    "script_fields": {
                      "start": {
                        "script": {
                          "lang": "painless",
                          "inline": "LocalDateTime.ofEpochSecond((doc[\"timestamp\"].date.getMillis()-((doc[\"bucket_span\"].value * 1000)\n * params.padding)) / 1000, 0, ZoneOffset.UTC).toString()",
                          "params": {
                            "padding": 10
                          }
                        }
                      },
                      "end": {
                        "script": {
                          "lang": "painless",
                          "inline": "LocalDateTime.ofEpochSecond((doc[\"timestamp\"].date.getMillis()+((doc[\"bucket_span\"].value * 1000)\n * params.padding)) / 1000, 0, ZoneOffset.UTC).toString()",
                          "params": {
                            "padding": 10
                          }
                        }
                      },

I think this might only show up in certain situations (multi-node clusters?) since I couldn't replicate this on my 1-node setup.

The customer has confirmed that the above modification avoids the error and thus it should be incorporated into the build.

@jeffrey-e
Copy link

Hi, just confirmed this solution as I was searching for this issue. I came across the issue after upgrading my All in 1 machine to 6.3.1. Hopefully this gets fixed in the next version as it seems as a very minor change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants