Regression ES 6.2 -> 6.5: Watch condition "Cannot cast from [java.util.HashMap] to [boolean]."


(Robin Schneider) #1

I found a regression when testing ES 6.5. Refer to the following watch script condition:

---

# yamllint disable rule:line-length rule:comments-indentation

condition:
  script:
    inline: |
      HashMap test = ['test': 23];                                                                                                                           
      if (params.getOrDefault('return_boolean', false)) {
        return false;
      } else {
        return test;
      }
    params:
      return_boolean: True

transform:
  script:
    inline: |
      HashMap test = ['test': 23];
      if (params.getOrDefault('return_boolean', false)) {
        return false;
      } else {
        return test;
      }

Yes, YAML is awesome, also for watch definitions. Ref: https://github.com/elastic/examples/pull/239. Note that the example does not make much sense as it is posted here. I just want to demonstrate the behaviour. This is not a working watch definition as it is missing some required options which are not relevant for this example.

The idea behind this is to have one stored script being used to evaluate if the watch actions should run (watch condition) and do the watch transformation with the same code. This can come in handy when the watch condition is quite complicated where we only learn as part of the transform if actions need to be performed.

This works/worked on ES 6.2. On 6.5.3 I get:

curl -u 'elastic:changeme' 'http://localhost:9200/_xpack/watcher/watch/log_issues' -H 'Content-Type: application/yaml' --data-binary @aggregated_issues_in_logs/watch.yaml
---
error:
  root_cause:
  - type: "script_exception"
    reason: "compile error"
    script_stack:
    - "... false;\n} else {\n  return test;\n}\n"
    - "                             ^---- HERE"
    script: "HashMap test = ['test': 23];\nif (params.getOrDefault('return_boolean',\
      \ false)) {\n  return false;\n} else {\n  return test;\n}\n"
    lang: "painless"
  type: "script_exception"
  reason: "compile error"
  script_stack:
  - "... false;\n} else {\n  return test;\n}\n"
  - "                             ^---- HERE"
  script: "HashMap test = ['test': 23];\nif (params.getOrDefault('return_boolean',\
    \ false)) {\n  return false;\n} else {\n  return test;\n}\n"
  lang: "painless"
  caused_by:
    type: "class_cast_exception"
    reason: "Cannot cast from [java.util.HashMap] to [boolean]."
status: 500

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.