# The Closer, The Better - nested geo\_distance and scoring

**URL:** https://discuss.elastic.co/t/the-closer-the-better-nested-geo-distance-and-scoring/82473
**Category:** Elasticsearch
**Created:** [April 15, 2017, 2:15pm UTC](https://discuss.elastic.co/t/the-closer-the-better-nested-geo-distance-and-scoring/82473 "2017-04-15T14:15:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zzvara](https://avatars.discourse-cdn.com/v4/letter/z/50afbb/32.png) [@zzvara](https://discuss.elastic.co/u/zzvara)
#### Post date: [April 15, 2017, 2:15pm UTC](https://discuss.elastic.co/t/the-closer-the-better-nested-geo-distance-and-scoring/82473/1 "2017-04-15T14:15:16Z")

</div>

Is it feasible to do a `geo_distance` query with an efficient scoring, in the following way?

Each document might have up to 10 nested objects with a field "location" as type `geo_point`included. I'd like to retrieve, sort and score documents based on the "location", but the scoring should be done based on the "closest" of all the nested objects that each document have. I might not getting valid results, since it seems that all the results have very, very similar scores.

Please take a look onto my query:

GET /whatever/couchbaseDocument/\_search  
{  
"size": 1000,  
"query": {  
"nested": {  
"path": "doc.inheritedProperties.places",  
"query": {  
"function\_score": {  
"functions": [  
{  
"linear": {  
"doc.inheritedProperties.places.location.coordinates": {  
"origin": {  
"lat": 43.000,  
"lon": 46.000  
},  
"scale": "1km",  
"offset": "0km",  
"decay": 0.5  
}  
},  
"weight": 3  
}  
],  
"query": {  
"bool": {  
"must": {  
"match\_all": {}  
},  
"filter": {  
"geo\_distance": {  
"distance": "100km",  
"doc.inheritedProperties.places.location.coordinates": {  
"lat": 43.0000,  
"lon": 46.0000  
}  
}  
}  
}  
},  
"score\_mode": "multiply"  
}  
}  
}  
}  
}

I've got 10000 documents indexed with coordinates uniformly random between 40.0 - 50.0 as for lon and lat.

The score is `"_score": 0.5936181` for the first 50 retrieved documents, and then `"_score": 0.026814064` for the next 50. I've also tried to tweak the parameters of the scoring functions as well as trying out different decays. Same results, but with different scores: top 50 or so documents have the same score.

---

<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: [May 13, 2017, 2:22pm UTC](https://discuss.elastic.co/t/the-closer-the-better-nested-geo-distance-and-scoring/82473/2 "2017-05-13T14:22:58Z")

</div>

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