# Native script custom scoring: accessing nested document fields

**URL:** <https://discuss.elastic.co/t/native-script-custom-scoring-accessing-nested-document-fields/12507>\
**Category:** Elasticsearch\
**Created:** [June 21, 2013, 10:03am UTC](https://discuss.elastic.co/t/native-script-custom-scoring-accessing-nested-document-fields/12507 "2013-06-21T10:03:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maciej\_Kula](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Maciej\_Kula](https://discuss.elastic.co/u/Maciej_Kula)\
**Post date:** [June 21, 2013, 10:03am UTC](https://discuss.elastic.co/t/native-script-custom-scoring-accessing-nested-document-fields/12507/1 "2013-06-21T10:03:30Z")

</div>

Hello,

I am trying to use a native (Java) script to perform custom scoring of  
documents in my index, using the CustomScore query.

One of the fields I am trying to access in Java is a nested document field  
--- if I try to access it using

DocLookup doc = doc();  
doc.get("pins.date\_added");

I get an ElasticSearchIllegalArgumentException at /: No field found for []  
in mapping with types []]; } exception, suggesting that the pins.date added  
field is inaccessible --- even though I have set the store\_in\_parent  
property to true.

What is the correct way of going about accessing such fields? Where, if  
anywhere, should the include\_in\_parent property be declared (at the  
property or type level?)

Here's the relevant part of my mapping:

'pins': {  
'type': 'nested',

```
'include_in_parent': 'true',                                           
                                 
'properties': {                                                         
                                
     'date_added': {u'index': 'not_analyzed',                           
                                
                      'omit_norms': 'true',                             
                                
                      u'store': 'no',                                   
                                
                      u'term_vector': 'no',                             
                                
                      u'type': 'date',                                 
                                 
                      'include_in_parent': 'true',                     
                                 
                      u'format': u'dateOptionalTime'},                 
                                 
     'id': {u'index': 'not_analyzed',                                   
                                
              'omit_norms': 'true',                                     
                                
              u'store': 'yes',                                         
                                 
              u'term_vector': 'no',                                     
                                
              u'type': 'string'},                                       
                                
     'owner_id': {u'index': 'not_analyzed',                             
                                
                  'omit_norms': 'true',                                 
                                
                  u'store': 'yes',                                     
                                 
                  u'term_vector': 'no',                                 
                                
                  u'type': 'long'},                            

```

}

Thanks!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Maciej\_Kula](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Maciej\_Kula](https://discuss.elastic.co/u/Maciej_Kula)\
**Post date:** [June 21, 2013, 11:25am UTC](https://discuss.elastic.co/t/native-script-custom-scoring-accessing-nested-document-fields/12507/2 "2013-06-21T11:25:01Z")

</div>

Update: the above is indeed the correct way to retrieve nested document  
values (they will be returned as arrays). My problem was caused by an  
unrelated mapping change.

The include\_in\_parent/include\_in\_root property should be set at the type  
level, not at the property level.

Maciej

On Friday, June 21, 2013 11:03:30 AM UTC+1, Maciej Kula wrote:

> Hello,
> 
> I am trying to use a native (Java) script to perform custom scoring of  
> documents in my index, using the CustomScore query.
> 
> One of the fields I am trying to access in Java is a nested document field  
> --- if I try to access it using
> 
> DocLookup doc = doc();  
> doc.get("pins.date\_added");
> 
> I get an ElasticSearchIllegalArgumentException at /: No field found for   
> in mapping with types ]; } exception, suggesting that the pins.date added  
> field is inaccessible --- even though I have set the store\_in\_parent  
> property to true.
> 
> What is the correct way of going about accessing such fields? Where, if  
> anywhere, should the include\_in\_parent property be declared (at the  
> property or type level?)
> 
> Here's the relevant part of my mapping:
> 
> 'pins': {  
> 'type': 'nested',
> 
> ```
> 'include_in_parent': 'true',                                           
>                                  
> 'properties': {                                                       
>                                   
> 'date_added': {u'index': 'not_analyzed',                         
>                                   
> 'omit_norms': 'true',                           
>                                   
> u'store': 'no',                                 
>                                   
> u'term_vector': 'no',                           
>                                   
> u'type': 'date',                                 
>                                  
> 'include_in_parent': 'true',                     
>                                  
> u'format': u'dateOptionalTime'},                 
>                                  
> 'id': {u'index': 'not_analyzed',                                 
>                                   
> 'omit_norms': 'true',                                   
>                                   
> u'store': 'yes',                                         
>                                  
> u'term_vector': 'no',                                   
>                                   
> u'type': 'string'},                                     
>                                   
> 'owner_id': {u'index': 'not_analyzed',                           
>                                   
> 'omit_norms': 'true',                               
>                                   
> u'store': 'yes',                                     
>                                  
> u'term_vector': 'no',                               
>                                   
> u'type': 'long'},                            
> 
> ```
> 
> }
> 
> Thanks!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:30am UTC](https://discuss.elastic.co/t/native-script-custom-scoring-accessing-nested-document-fields/12507/3 "2017-07-06T02:30:01Z")

</div>


