# How to check for key exist script query parameters?

**URL:** <https://discuss.elastic.co/t/how-to-check-for-key-exist-script-query-parameters/290514>\
**Category:** Elasticsearch\
**Created:** [November 30, 2021, 6:12am UTC](https://discuss.elastic.co/t/how-to-check-for-key-exist-script-query-parameters/290514 "2021-11-30T06:12:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hyun/32/97630_2.png) [@hyun](https://discuss.elastic.co/u/hyun)\
**Post date:** [November 30, 2021, 6:12am UTC](https://discuss.elastic.co/t/how-to-check-for-key-exist-script-query-parameters/290514/1 "2021-11-30T06:12:12Z")

</div>

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.

```auto
"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.

```auto
"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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 28, 2021, 6:12am UTC](https://discuss.elastic.co/t/how-to-check-for-key-exist-script-query-parameters/290514/2 "2021-12-28T06:12:32Z")

</div>

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