How to check for key exist script query parameters?

Is there any way to return null if there is no corresponding value?

example) Since params do not have a field4 value, I want the null value to be returned to the syn variable.

"aggs": {
    "countries": {
      "terms": {
        "script": {
          "params": {
            "field1": "country",
            "field2": "test",
            "field3": "test"
          },
          "inline": "def syn = field4; if (syn == null) doc[country].value;"
        }
      }
    }
  }

Currently, errors always occur if there is no corresponding value.

"caused_by": {
   "type": "missing_property_exception",
   "reason": "No such property: field1 for class: e5ce2464b456f9c0fa360269abc927e65998ecf7"
}

I am using groovy and Elasticsearch version 2.2

I can't use Python or JavaScript, which requires additional plug-ins to be installed.

How can I get a null value without causing an error if there is no value?

Thanks

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