# Using geodistancefilter

**URL:** <https://discuss.elastic.co/t/using-geodistancefilter/8755>\
**Category:** Elasticsearch\
**Created:** [August 16, 2012, 3:46am UTC](https://discuss.elastic.co/t/using-geodistancefilter/8755 "2012-08-16T03:46:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Warner\_Onstine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warner_onstine/32/1086_2.png) [@Warner\_Onstine](https://discuss.elastic.co/u/Warner_Onstine)\
**Post date:** [August 16, 2012, 3:46am UTC](https://discuss.elastic.co/t/using-geodistancefilter/8755/1 "2012-08-16T03:46:06Z")

</div>

Ok, been trying to get the geo distance filter working properly, after  
dealing with several mapping issues I finally got a manual query  
working:

```
     {
      "geo_distance" : {
        "location" : { "lat":32.2217429, "lon":-110.926479},
        "distance" : "25.0mi"
      }

```

But, when I use the java api:  
geoDistanceFilter("location").lat(coordinates[0]).lon(coordinates[1])  
.distance(25, org.elasticsearch.common.unit.DistanceUnit.MILES)

This generates json code that won't work:  
{  
"geo\_distance" : {  
"location" : [32.2217429,-110.926479],  
"distance" : "25.0mi"  
}

How do I tell ES to generate the first type (where lat and lon are  
spelled out as fields) and not the second type?

Thanks!

-warner

--

---

<div class="post-metadata">

**Author:** ![Warner\_Onstine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warner_onstine/32/1086_2.png) [@Warner\_Onstine](https://discuss.elastic.co/u/Warner_Onstine)\
**Post date:** [August 16, 2012, 3:59am UTC](https://discuss.elastic.co/t/using-geodistancefilter/8755/2 "2012-08-16T03:59:15Z")

</div>

Ok, I found this in the javadocs:  
GeoPointFieldMapper

but I'm not sure exactly how to configure this and inject it into the  
GeoDistanceFilter, any pointers?

-warner

On Wed, Aug 15, 2012 at 8:46 PM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:

> Ok, been trying to get the geo distance filter working properly, after  
> dealing with several mapping issues I finally got a manual query  
> working:
> 
> ```
> {
> "geo_distance" : {
> "location" : { "lat":32.2217429, "lon":-110.926479},
> "distance" : "25.0mi"
> }
> 
> ```
> 
> But, when I use the java api:  
> geoDistanceFilter("location").lat(coordinates[0]).lon(coordinates[1])  
> .distance(25, org.elasticsearch.common.unit.DistanceUnit.MILES)
> 
> This generates json code that won't work:  
> {  
> "geo\_distance" : {  
> "location" : [32.2217429,-110.926479],  
> "distance" : "25.0mi"  
> }
> 
> How do I tell ES to generate the first type (where lat and lon are  
> spelled out as fields) and not the second type?
> 
> Thanks!
> 
> -warner

--

---

<div class="post-metadata">

**Author:** ![Warner\_Onstine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warner_onstine/32/1086_2.png) [@Warner\_Onstine](https://discuss.elastic.co/u/Warner_Onstine)\
**Post date:** [August 16, 2012, 4:36am UTC](https://discuss.elastic.co/t/using-geodistancefilter/8755/3 "2012-08-16T04:36:46Z")

</div>

Ahh, looks like I was bitten by the reverse lat/lon stuff in my  
hand-written query. I reversed the order and my manual query works now  
(and the generated query code should also work as well).

Never mind!

-warner

On Wed, Aug 15, 2012 at 8:59 PM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:

> Ok, I found this in the javadocs:  
> GeoPointFieldMapper
> 
> but I'm not sure exactly how to configure this and inject it into the  
> GeoDistanceFilter, any pointers?
> 
> -warner
> 
> On Wed, Aug 15, 2012 at 8:46 PM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:
> 
> > Ok, been trying to get the geo distance filter working properly, after  
> > dealing with several mapping issues I finally got a manual query  
> > working:
> > 
> > ```
> > {
> > "geo_distance" : {
> > "location" : { "lat":32.2217429, "lon":-110.926479},
> > "distance" : "25.0mi"
> > }
> > 
> > ```
> > 
> > But, when I use the java api:  
> > geoDistanceFilter("location").lat(coordinates[0]).lon(coordinates[1])  
> > .distance(25, org.elasticsearch.common.unit.DistanceUnit.MILES)
> > 
> > This generates json code that won't work:  
> > {  
> > "geo\_distance" : {  
> > "location" : [32.2217429,-110.926479],  
> > "distance" : "25.0mi"  
> > }
> > 
> > How do I tell ES to generate the first type (where lat and lon are  
> > spelled out as fields) and not the second type?
> > 
> > Thanks!
> > 
> > -warner

--

---

<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:16am UTC](https://discuss.elastic.co/t/using-geodistancefilter/8755/4 "2017-07-06T03:16:13Z")

</div>


