# Boosting on geo data

**URL:** <https://discuss.elastic.co/t/boosting-on-geo-data/7350>\
**Category:** Elasticsearch\
**Created:** [April 16, 2012, 2:32pm UTC](https://discuss.elastic.co/t/boosting-on-geo-data/7350 "2012-04-16T14:32:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Schroder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_schroder/32/2513_2.png) [@Peter\_Schroder](https://discuss.elastic.co/u/Peter_Schroder)\
**Post date:** [April 16, 2012, 2:32pm UTC](https://discuss.elastic.co/t/boosting-on-geo-data/7350/1 "2012-04-16T14:32:39Z")

</div>

is it possible to provide some filter or query that allows me to boost on  
geo-distance?

i.e. if there is a document with a location that is within 100km i want to  
boost it to the top. if it isn't within the range, i don't want to boost it  
at all.

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 16, 2012, 3:49pm UTC](https://discuss.elastic.co/t/boosting-on-geo-data/7350/2 "2012-04-16T15:49:43Z")

</div>

I think you achieve it by combining Custom Filters Score Query  
([http://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query.html))  
with Geo Distance Filter  
([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-filter.html))

On Monday, April 16, 2012 10:32:39 AM UTC-4, Peter Schröder wrote:

> is it possible to provide some filter or query that allows me to boost on  
> geo-distance?
> 
> i.e. if there is a document with a location that is within 100km i want to  
> boost it to the top. if it isn't within the range, i don't want to boost it  
> at all.

---

<div class="post-metadata">

**Author:** ![Peter\_Schroder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_schroder/32/2513_2.png) [@Peter\_Schroder](https://discuss.elastic.co/u/Peter_Schroder)\
**Post date:** [April 16, 2012, 4:12pm UTC](https://discuss.elastic.co/t/boosting-on-geo-data/7350/3 "2012-04-16T16:12:46Z")

</div>

yeah, had the same idea.

this kinda works:

{  
"query": {  
"custom\_filters\_score": {  
"query": {  
"match\_all": {}  
},  
"filters": [  
{  
"filter": {  
"geo\_distance\_range": {  
"from": "0km",  
"to": "100km",  
"location": {  
"lat": "47.16104233",  
"lon": "8.42149815"  
}  
}  
},  
"boost": "3"  
}  
],  
"score\_mode": "first"  
}  
},  
"filter": {  
"term": {  
"ck\_names": "software"  
}  
}  
}

but this gives me an error:

{  
"query": {  
"term": {  
"ck\_names": "software"  
},  
"custom\_filters\_score": {  
"query": {  
"match\_all": {}  
},  
"filters": [  
{  
"filter": {  
"geo\_distance\_range": {  
"from": "0km",  
"to": "100km",  
"location": {  
"lat": "47.16104233",  
"lon": "8.42149815"  
}  
}  
},  
"boost": "3"  
}  
],  
"score\_mode": "first"  
}  
}  
}

Caused by: org.elasticsearch.search.SearchParseException:  
[development-companies-v3.8.1-218-gf575086-2012-04-02-112352][0]:  
query[ConstantScore(NotDeleted(_:_))],from[-1],size[-1]: Parse Failure [No  
parser for element [filters]]

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 16, 2012, 4:35pm UTC](https://discuss.elastic.co/t/boosting-on-geo-data/7350/4 "2012-04-16T16:35:07Z")

</div>

In the second case you cannot have two queries: "term" and  
"custom\_filter\_score" queries on the same level. If you want the term query  
to affect the score just replace match\_all with term.

On Monday, April 16, 2012 12:12:46 PM UTC-4, Peter Schröder wrote:

> yeah, had the same idea.
> 
> this kinda works:
> 
> {  
> "query": {  
> "custom\_filters\_score": {  
> "query": {  
> "match\_all": {}  
> },  
> "filters": [  
> {  
> "filter": {  
> "geo\_distance\_range": {  
> "from": "0km",  
> "to": "100km",  
> "location": {  
> "lat": "47.16104233",  
> "lon": "8.42149815"  
> }  
> }  
> },  
> "boost": "3"  
> }  
> ],  
> "score\_mode": "first"  
> }  
> },  
> "filter": {  
> "term": {  
> "ck\_names": "software"  
> }  
> }  
> }
> 
> but this gives me an error:
> 
> {  
> "query": {  
> "term": {  
> "ck\_names": "software"  
> },  
> "custom\_filters\_score": {  
> "query": {  
> "match\_all": {}  
> },  
> "filters": [  
> {  
> "filter": {  
> "geo\_distance\_range": {  
> "from": "0km",  
> "to": "100km",  
> "location": {  
> "lat": "47.16104233",  
> "lon": "8.42149815"  
> }  
> }  
> },  
> "boost": "3"  
> }  
> ],  
> "score\_mode": "first"  
> }  
> }  
> }
> 
> Caused by: org.elasticsearch.search.SearchParseException:  
> [development-companies-v3.8.1-218-gf575086-2012-04-02-112352][0]:  
> query[ConstantScore(NotDeleted(_:_))],from[-1],size[-1]: Parse Failure [No  
> parser for element [filters]]

---

<div class="post-metadata">

**Author:** ![Peter\_Schroder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_schroder/32/2513_2.png) [@Peter\_Schroder](https://discuss.elastic.co/u/Peter_Schroder)\
**Post date:** [April 17, 2012, 6:09am UTC](https://discuss.elastic.co/t/boosting-on-geo-data/7350/5 "2012-04-17T06:09:11Z")

</div>

d'oh!

---

<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, 3:32am UTC](https://discuss.elastic.co/t/boosting-on-geo-data/7350/6 "2017-07-06T03:32:24Z")

</div>


