# Object property not showing up in index (unable to access in the doc variable in a script)

**URL:** <https://discuss.elastic.co/t/object-property-not-showing-up-in-index-unable-to-access-in-the-doc-variable-in-a-script/13286>\
**Category:** Elasticsearch\
**Created:** [August 21, 2013, 5:07pm UTC](https://discuss.elastic.co/t/object-property-not-showing-up-in-index-unable-to-access-in-the-doc-variable-in-a-script/13286 "2013-08-21T17:07:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicktackes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicktackes/32/1174_2.png) [@nicktackes](https://discuss.elastic.co/u/nicktackes)\
**Post date:** [August 21, 2013, 5:07pm UTC](https://discuss.elastic.co/t/object-property-not-showing-up-in-index-unable-to-access-in-the-doc-variable-in-a-script/13286/1 "2013-08-21T17:07:35Z")

</div>

Hello,

I have a property of type object within a mapping definition but when i  
attempt to access it within a script, it is not available in the doc  
variable. it is in \_source... what do i need to specify in order to always  
have the property of type object appear in the index?

this is the sub object mapping ... I tried adding type:'object',  
enable:true, include\_in\_all:true..... my objective is to compute the  
distance of the nearest location, so my script is enumerating through the  
locations and computing distance for each geo point....

....  
"location":{  
"properties":{  
"facility":{  
"properties":{  
"name":{"type":"string",  
index:"not\_analyzed"},  
"address":{  
"properties":{  
"city":{"type":"string",  
index:"not\_analyzed"},  
"state":{"type":"string",  
index:"not\_analyzed"},  
"zip":{"type":"string",  
index:"not\_analyzed"},  
"country":{"type":"string",  
index:"not\_analyzed"}  
}  
},  
"geo":{  
"type":"geo\_point"  
}  
}  
}  
}  
},

{"query":{  
"custom\_score":{  
"query":{  
"match\_all":{}  
},  
"script":"\_score + doc['mboost'].value"  
}  
}, "filter":{

```
"query":{
    "match_phrase":{
        "status":"Recruiting"
    }
}

```

}, "fields":"\_source",  
"script\_fields":{  
"distance":{  
"params":{  
"lat":42.3788774,  
"lon":-72.032366  
},  
"script": "c=doc[\u0027location\u0027].empty ? null :  
doc[\u0027location\u0027]; nearest\_distance=java.lang.Double.MAX\_VALUE;  
if(c!=null){for(cur : c) {if(cur["facility"]!=null &&  
cur["facility"]["geo"]!=null){dist=cur["facility"]["geo"].distance(lat,  
lon); if(dist \< nearest\_distance){ nearest\_distance = dist}}}};  
nearest\_distance"  
}  
},  
"sort":{  
"\_score":"desc"  
}, "from":"0", "size":"10"  
}

--  
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:20am UTC](https://discuss.elastic.co/t/object-property-not-showing-up-in-index-unable-to-access-in-the-doc-variable-in-a-script/13286/2 "2017-07-06T02:20:19Z")

</div>

Closed on July 6, 2017, 2:20am UTC


