# Native script unable to get values, perhaps because it's a child doc? ES v1.1.1

**URL:** <https://discuss.elastic.co/t/native-script-unable-to-get-values-perhaps-because-its-a-child-doc-es-v1-1-1/20874>\
**Category:** Elasticsearch\
**Created:** [November 20, 2014, 7:38pm UTC](https://discuss.elastic.co/t/native-script-unable-to-get-values-perhaps-because-its-a-child-doc-es-v1-1-1/20874 "2014-11-20T19:38:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Foy](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jonathan\_Foy](https://discuss.elastic.co/u/Jonathan_Foy)\
**Post date:** [November 20, 2014, 7:38pm UTC](https://discuss.elastic.co/t/native-script-unable-to-get-values-perhaps-because-its-a-child-doc-es-v1-1-1/20874/1 "2014-11-20T19:38:30Z")

</div>

Hello

I have a native script that I'm using to score/sort queries and it is not  
working properly for one of my three types.

All three types have the same nested field, and I'm using the script to  
check values and score/sort by an externally defined order. However, for  
one of the three types the values pulled from the doc fields are always  
zero/null (using docFieldLongs("fieldName").getValue() or  
docFieldStrings("stringValue").getValue()). I can check for the fields to  
be present using doc().containsKey(), and it seems to see them, but it  
never actually sees any values. I've pulled a few records manually and  
verified that the data looks good.

The only think I can think of that's different is that this one type is a  
child of one of the other two, but I'm querying it completely independently  
of the parent in this case. Does this sound familiar to anyone by any  
chance?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5fb79559-7d9f-4a32-a8e1-743876c9a152%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5fb79559-7d9f-4a32-a8e1-743876c9a152%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Shiwen\_Cheng](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Shiwen\_Cheng](https://discuss.elastic.co/u/Shiwen_Cheng)\
**Post date:** [November 20, 2014, 9:00pm UTC](https://discuss.elastic.co/t/native-script-unable-to-get-values-perhaps-because-its-a-child-doc-es-v1-1-1/20874/2 "2014-11-20T21:00:56Z")

</div>

Hi, did you index the field you want to use in the native script?

Shiwen

On Thursday, 20 November 2014 11:38:30 UTC-8, Jonathan Foy wrote:

> Hello
> 
> I have a native script that I'm using to score/sort queries and it is not  
> working properly for one of my three types.
> 
> All three types have the same nested field, and I'm using the script to  
> check values and score/sort by an externally defined order. However, for  
> one of the three types the values pulled from the doc fields are always  
> zero/null (using docFieldLongs("fieldName").getValue() or  
> docFieldStrings("stringValue").getValue()). I can check for the fields to  
> be present using doc().containsKey(), and it seems to see them, but it  
> never actually sees any values. I've pulled a few records manually and  
> verified that the data looks good.
> 
> The only think I can think of that's different is that this one type is a  
> child of one of the other two, but I'm querying it completely independently  
> of the parent in this case. Does this sound familiar to anyone by any  
> chance?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8b01edba-1d36-427d-abfe-48a03f4104a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8b01edba-1d36-427d-abfe-48a03f4104a3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jonathan\_Foy](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jonathan\_Foy](https://discuss.elastic.co/u/Jonathan_Foy)\
**Post date:** [November 20, 2014, 9:24pm UTC](https://discuss.elastic.co/t/native-script-unable-to-get-values-perhaps-because-its-a-child-doc-es-v1-1-1/20874/3 "2014-11-20T21:24:07Z")

</div>

Yep, and I can search on it in other queries.

After testing most of the afternoon, I finally seem to have gotten it to  
work by pulling the field using the full name, including the nested path:

Long value = docFieldLongs("nestedPath.propertyName").getValue();

This seems to work in all three places, including the two types that also  
worked without the nested path, which is good. Afterwords I came across this  
SO post  
[http://stackoverflow.com/questions/21289149/trouble-with-has-parent-query-containing-scripted-function-score?rq=1](http://stackoverflow.com/questions/21289149/trouble-with-has-parent-query-containing-scripted-function-score?rq=1)  
which sounds like a similar problem, though I'm not in a  
has\_parent/has\_child query (though I AM in a child type). Sounds like it  
may be a bug.

On Thursday, November 20, 2014 4:00:56 PM UTC-5, Shiwen Cheng wrote:

> Hi, did you index the field you want to use in the native script?
> 
> Shiwen
> 
> On Thursday, 20 November 2014 11:38:30 UTC-8, Jonathan Foy wrote:
> 
> > Hello
> > 
> > I have a native script that I'm using to score/sort queries and it is not  
> > working properly for one of my three types.
> > 
> > All three types have the same nested field, and I'm using the script to  
> > check values and score/sort by an externally defined order. However, for  
> > one of the three types the values pulled from the doc fields are always  
> > zero/null (using docFieldLongs("fieldName").getValue() or  
> > docFieldStrings("stringValue").getValue()). I can check for the fields to  
> > be present using doc().containsKey(), and it seems to see them, but it  
> > never actually sees any values. I've pulled a few records manually and  
> > verified that the data looks good.
> > 
> > The only think I can think of that's different is that this one type is a  
> > child of one of the other two, but I'm querying it completely independently  
> > of the parent in this case. Does this sound familiar to anyone by any  
> > chance?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/42ed3e0c-e5a9-4673-afb6-9a65213b91c1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/42ed3e0c-e5a9-4673-afb6-9a65213b91c1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:48am UTC](https://discuss.elastic.co/t/native-script-unable-to-get-values-perhaps-because-its-a-child-doc-es-v1-1-1/20874/4 "2017-07-06T00:48:31Z")

</div>


