# Use script field based on field of type string

**URL:** <https://discuss.elastic.co/t/use-script-field-based-on-field-of-type-string/45786>\
**Category:** Elasticsearch\
**Created:** [March 30, 2016, 11:56am UTC](https://discuss.elastic.co/t/use-script-field-based-on-field-of-type-string/45786 "2016-03-30T11:56:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [March 30, 2016, 11:56am UTC](https://discuss.elastic.co/t/use-script-field-based-on-field-of-type-string/45786/1 "2016-03-30T11:56:14Z")

</div>

I have the following document:

```
 {
   "parts": ["a", "b", "c"]
 }

```

I want to use the script field feature to add another field to the result, so the final result will look like this:

Not empty value:

```
_source: {
   "parts":["a", "b", "c"]
},
"fields": {
   "isEmpty": false
}

```

Empty value:

this:

```
_source: {
   "parts":[] // or null
},
"fields": {
   "isEmpty": true
}

```

I tried to do with with the following query:

```
{
   "query": {
       "match_all": {}
   },
   "script_fields" : {
        "isEmpty" : {
            "script" : {
                "lang": "expression",
                "inline": "doc['parts'].empty"
            }
        }
    }
}

```

But I get the following exception:

> "reason": "Only the member variable [value] or member methods may be accessed on a field when not accessing the field directly"

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![tpraizler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tpraizler/32/46271_2.png) [@tpraizler](https://discuss.elastic.co/u/tpraizler)\
**Post date:** [April 5, 2016, 10:16am UTC](https://discuss.elastic.co/t/use-script-field-based-on-field-of-type-string/45786/2 "2016-04-05T10:16:47Z")

</div>

Anyone? ☹

---

<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:02pm UTC](https://discuss.elastic.co/t/use-script-field-based-on-field-of-type-string/45786/3 "2017-07-05T23:02:18Z")

</div>


