# Script fields returning 0 for half\_float field

**URL:** <https://discuss.elastic.co/t/script-fields-returning-0-for-half-float-field/160371>\
**Category:** Elasticsearch\
**Created:** [December 11, 2018, 12:01pm UTC](https://discuss.elastic.co/t/script-fields-returning-0-for-half-float-field/160371 "2018-12-11T12:01:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [December 11, 2018, 12:01pm UTC](https://discuss.elastic.co/t/script-fields-returning-0-for-half-float-field/160371/1 "2018-12-11T12:01:27Z")

</div>

Hi there,

I have the following `nested` mapping:

```
my_object_nested_field, type: nested {
    my_inner_object {
        my_field, type: half_float
    }
}

```

My \_source clause contains the 'my\_object\_nested\_field.my\_inner\_object.my\_field' and almost all returned docs contain some value on it.

I declared the following `script_field`, JUST TO TEST IT:

```
script_fields: {
   my_script_field: {
         script: {
              inline: "doc['my_object_nested_field.my_inner_object.my_field'].value"
         }
   }
}

```

But all `my_script_field`, from all documents, are returned '0'.

Does anybody know what am I doing wrong? Does it have to do with my scrip declaration?  
Does it have to do with the fact that it's a nested field? I've tried with a another field that is outside the nested structure, and it worked!

Thanks in advance!

Guilherme

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [December 11, 2018, 12:13pm UTC](https://discuss.elastic.co/t/script-fields-returning-0-for-half-float-field/160371/2 "2018-12-11T12:13:06Z")

</div>

Hi!

I've solved it with params['\_source']['my\_object\_nested\_field']['my\_inner\_object']['my\_field'].

It seems it isn't possible to use doc[...].value for nested fields.

thanks!

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [December 11, 2018, 10:02pm UTC](https://discuss.elastic.co/t/script-fields-returning-0-for-half-float-field/160371/3 "2018-12-11T22:02:57Z")

</div>

> It seems it isn't possible to use doc[...].value for nested fields.

That is correct. See

> <https://github.com/elastic/elasticsearch/issues/23719>
>
> When trying to access a nested or object field within a script, the behavior is …different depending on the method called. When trying to retrieve the value of the field, an exception is thrown saying the field does not exist (when it fact it is simply not a field mapper). If you try to check if the doc contains the field, it simply returns false, again incorrectly since the field does exist, just not as a field mapper. I think we should throw an error in both these cases, but with a good message that indicates the field exists but is not accessible in scripts. Note that I'm not sure what happens when trying to access a concrete field that is parented by a nested field. I believe I have seen issues for it before where the field just comes back as no values. I think we should throw an error in this case as well.

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [December 12, 2018, 11:13am UTC](https://discuss.elastic.co/t/script-fields-returning-0-for-half-float-field/160371/4 "2018-12-12T11:13:12Z")

</div>

Thank you, @rjernst

---

<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:** [January 9, 2019, 11:13am UTC](https://discuss.elastic.co/t/script-fields-returning-0-for-half-float-field/160371/5 "2019-01-09T11:13:26Z")

</div>

Closed on January 9, 2019, 11:13am UTC

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