# Cant access a nested field when using distance script

**URL:** https://discuss.elastic.co/t/cant-access-a-nested-field-when-using-distance-script/14650
**Category:** Elasticsearch
**Created:** [November 30, 2013, 7:18pm UTC](https://discuss.elastic.co/t/cant-access-a-nested-field-when-using-distance-script/14650 "2013-11-30T19:18:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Levon\_Tamrazov](https://avatars.discourse-cdn.com/v4/letter/l/f0a364/32.png) [@Levon\_Tamrazov](https://discuss.elastic.co/u/Levon_Tamrazov)
#### Post date: [November 30, 2013, 7:18pm UTC](https://discuss.elastic.co/t/cant-access-a-nested-field-when-using-distance-script/14650/1 "2013-11-30T19:18:34Z")

</div>

My index in elastic search has the following mapping:

"couchbaseDocument": {  
"properties": {  
"doc": {  
"properties": {  
"properties": {  
"properties": {  
"location": {  
"type": "geo\_point"  
}}}}}}}

The source document is as follows:

{"properties" : {"location":"43.706596,-79.4030464"}}

I am trying to use the distance script to calculate the distance based on geo-points. I am trying to get all results,filter by radius 1km, get the distance, and sort on geo\_point. The query is constructed as follows:

{  
"query": {  
"match\_all": {}  
},  
"filter": {  
"geo\_distance": {  
"distance": "1km",  
"doc.properties.location": {  
"lat": 43.710323,  
"lon": -79.395284  
}  
}  
},

```
"script_fields": {
   "distancePLANE": {
        "params": {
           "lat": 43.710323,
           "lon": -79.395284
       }, 
      "script": "doc['properties.location'].distanceInKm(lat, lon)"
   }, 
   "distanceARC" :{
       "params": {
           "lat": 43.710323,
           "lon": -79.395284
       }, 
       "script": "doc[properties]['location'].arcDistanceInKm(lat,lon)"
   }
}, 

"sort": [
   {
       "_geo_distance":{
           "doc.properties.location": [-79.395284,43.710323],
            "order": "desc",
            "unit": "km"
       }
   }
],
"track_scores": true

```

}  
I get the following error with status 500:  
"CompileException[[Error: No field found for [properties.location] in mapping with types [couchbaseDocument]]\n[Near : {... doc['properties.location'].arc ....}]\n ^\n[Line: 1, Column: 1]]; nested: ElasticSearchIllegalArgumentException[No field found for [properties.location] in mapping with types [couchbaseDocument]]; "

I tried rewriting the query in this way:

..."script": "doc['properties']['location'].arcDistanceInKm(lat,lon)"...

Got the same error. Then tried this :

..."script": "doc.properties['location'].arcDistanceInKm(lat,lon)"...

Then I get this error:

"PropertyAccessException[[Error: could not access: properties; in class: org.elasticsearch.search.lookup.DocLookup]\n[Near : {... doc.properties['location'].arc ....}]\n ^\n[Line: 1, Column: 1]]"

When I remove the script part from the query all together, the sorting and filtering works just fine (so I can access doc.properties.location). Is there a different syntax to access nested fields when using scripts? Any insights would be really appreciated!

Thank you!

---

<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:04am UTC](https://discuss.elastic.co/t/cant-access-a-nested-field-when-using-distance-script/14650/2 "2017-07-06T02:04:03Z")

</div>


