# Not able to use scripting\_field to show distance: ES\_6.1

**URL:** <https://discuss.elastic.co/t/not-able-to-use-scripting-field-to-show-distance-es-6-1/116033>\
**Category:** Elasticsearch\
**Created:** [January 18, 2018, 11:46am UTC](https://discuss.elastic.co/t/not-able-to-use-scripting-field-to-show-distance-es-6-1/116033 "2018-01-18T11:46:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![neha\_sharma](https://avatars.discourse-cdn.com/v4/letter/n/ac91a4/32.png) [@neha\_sharma](https://discuss.elastic.co/u/neha_sharma)\
**Post date:** [January 18, 2018, 11:46am UTC](https://discuss.elastic.co/t/not-able-to-use-scripting-field-to-show-distance-es-6-1/116033/1 "2018-01-18T11:46:05Z")

</div>

Hi I am new to Elastic search. I want to show distance in result while using "\_search" where "location" field is of type : geopoint; I found we can use script\_fields but this is not working.  
To mention : I am using 6.1 ES version.

```
    {
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "200km",
                    "location" : {
                        "lat" : 28.6139,
                        "lon" : 77.209
                    }
                }
            }
        }
    },
  "script_fields" : {
      "distance" : {
         "lang": "painless",
         "params" : {
            "lat" : 47.1,
            "lon" : 8.1
         },
         "script" : "doc['location'].DistanceInKm(lat,lon)"
      }
   }
        
    }

```

##### 

```
"error": {
    "root_cause": [
        {
            "type": "parsing_exception",
            "reason": "Unknown key for a VALUE_STRING in [lang].",
            "line": 20,
            "col": 18
        }
    ],
    "type": "parsing_exception",
    "reason": "Unknown key for a VALUE_STRING in [lang].",
    "line": 20,
    "col": 18
},
"status": 400

```

}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 18, 2018, 1:54pm UTC](https://discuss.elastic.co/t/not-able-to-use-scripting-field-to-show-distance-es-6-1/116033/2 "2018-01-18T13:54:43Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```
````

---

<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:** [February 15, 2018, 1:54pm UTC](https://discuss.elastic.co/t/not-able-to-use-scripting-field-to-show-distance-es-6-1/116033/3 "2018-02-15T13:54:47Z")

</div>

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