# Relevancy with location

**URL:** https://discuss.elastic.co/t/relevancy-with-location/17961
**Category:** Elasticsearch
**Created:** [June 6, 2014, 5:43pm UTC](https://discuss.elastic.co/t/relevancy-with-location/17961 "2014-06-06T17:43:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Scott\_Vickers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/scott_vickers/32/1494_2.png) [@Scott\_Vickers](https://discuss.elastic.co/u/Scott_Vickers)
#### Post date: [June 6, 2014, 5:43pm UTC](https://discuss.elastic.co/t/relevancy-with-location/17961/1 "2014-06-06T17:43:59Z")

</div>

I am trying to wire up a search that gives documents near a location a  
higher ranking. Pretty simple but in our case some of the documents won't  
always have a location associated with them. When using a function\_score  
query the documents with no location always get scored higher than the ones  
with a location, even if I search with the exact coordinates. Here is an  
example:

Documents:  
PUT /test/colors/1  
{  
"name":"red"  
}

PUT /test/colors/2  
{  
"name":"red",  
"location":{"lat":47,"lon":-122}  
}

Mapping:  
"mappings" : {  
"colors" : {  
"properties" : {  
"location" : {  
"lat\_lon" : true,  
"type" : "geo\_point",  
"geohash" : true  
},  
"name" : {  
"type" : "string"  
}  
}  
}  
}

Query:  
{  
"query":{  
"function\_score":{  
"query":{  
"multi\_match":{  
"type":"phrase",  
"query":"red",  
"fields":["name"],  
"tie\_breaker":0.3  
}  
},  
"functions":[  
{  
"gauss": {  
"location": {  
"origin": "47,-122",  
"scale": "10mi"  
}  
}  
}  
]  
}

}  
}

Results:  
{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 2,  
"successful": 2,  
"failed": 0  
},  
"hits": {  
"total": 2,  
"max\_score": 0.30685282,  
"hits": [  
{  
"\_index": "test",  
"\_type": "colors",  
"\_id": "1",  
"\_score": 0.30685282,  
"\_source": {  
"name": "red"  
}  
},  
{  
"\_index": "test",  
"\_type": "colors",  
"\_id": "2",  
"\_score": 0.30685282,  
"\_source": {  
"name": "red",  
"location": {  
"lat": 47,  
"lon": -122  
}  
}  
}  
]  
}  
}

Is there any way to factor proximity in for some results and not others?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/59f8e2e1-856a-432b-a034-b71e31110ae9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/59f8e2e1-856a-432b-a034-b71e31110ae9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:24am UTC](https://discuss.elastic.co/t/relevancy-with-location/17961/2 "2017-07-06T01:24:08Z")

</div>


