# Ruby scripts with 'nil'?

**URL:** <https://discuss.elastic.co/t/ruby-scripts-with-nil/29433>\
**Category:** Elasticsearch\
**Created:** [September 16, 2015, 5:58pm UTC](https://discuss.elastic.co/t/ruby-scripts-with-nil/29433 "2015-09-16T17:58:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![klahnakoski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klahnakoski/32/3679_2.png) [@klahnakoski](https://discuss.elastic.co/u/klahnakoski)\
**Post date:** [September 16, 2015, 5:58pm UTC](https://discuss.elastic.co/t/ruby-scripts-with-nil/29433/1 "2015-09-16T17:58:24Z")

</div>

I am trying to use `nil` in a script field, but I get an error

```auto
GroovyScriptExecutionException[MissingPropertyException[No such property: nil for class: b5366a2d2ac98dae978423083f8b09e5cddc705d]]

```

Here is a demonstration script.

```auto
{
  "query": {
    "match_all": {}
  },
  "script_fields": {
    "test": {
      "script": "nil"
    }
  },
  "size": 10
}

```

Really, any script with `nil` will return this error (also scripts with `begin` and `end` also fail)

What type of Ruby is Elasticsearch using as a scripting language? Must I import `nil` first? How do I do use `nil` in a script?

Thanks

PS: For the pedantic, my real script is trying to get the length of a string:

```auto
doc["name"].empty ? nil : doc["name"].value.length()

```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 16, 2015, 6:04pm UTC](https://discuss.elastic.co/t/ruby-scripts-with-nil/29433/2 "2015-09-16T18:04:25Z")

</div>

Judging by the first word of the error message it's a Groovy script, in which case "null" is what you're looking for.

---

<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:** [July 5, 2017, 11:49pm UTC](https://discuss.elastic.co/t/ruby-scripts-with-nil/29433/3 "2017-07-05T23:49:57Z")

</div>


