# distanceInKm not working well

**URL:** <https://discuss.elastic.co/t/distanceinkm-not-working-well/68538>\
**Category:** Elasticsearch\
**Created:** [December 9, 2016, 9:10am UTC](https://discuss.elastic.co/t/distanceinkm-not-working-well/68538 "2016-12-09T09:10:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![minniek](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@minniek](https://discuss.elastic.co/u/minniek)\
**Post date:** [December 9, 2016, 9:10am UTC](https://discuss.elastic.co/t/distanceinkm-not-working-well/68538/1 "2016-12-09T09:10:42Z")

</div>

Hello everyone, I know I am using elasticaphp but It happened also in elasticsearch.....

I am using the class GeoDistance in order to get the location around (example : 2km )

$filter = new Elastica\Filter\*_GeoDistance_\*('location', array('lat' =\> $lat, 'lon' =\> $lng), $distance . 'km');

then, I added a script to get the distance in km ('doc[\u0027location\u0027].distanceInKm(lat,lon)')

$script = new Elastica\Script('doc[\u0027location\u0027].distanceInKm(lat,lon)', array('lat' =\> $lat, 'lon' =\> $lng));  
$score-\>setQuery($es\_bool); // other conditions (matches)  
$score-\>setBoostMode('replace');  
$score-\>addScriptScoreFunction($script);

So, I dont know what is going on because I got distances that are greater than 2km for a little bit for example (2,12km)

Additionally, I do not see any variable called distance or something similar but I got a variable called SCORE so i guessed that is the distance between the two geo points and I set boost to replace, Am I right?

Any ideas?  
Thanks

---

<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:** [January 6, 2017, 9:10am UTC](https://discuss.elastic.co/t/distanceinkm-not-working-well/68538/2 "2017-01-06T09:10:42Z")

</div>

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