# Trying to query geo\_distance

**URL:** <https://discuss.elastic.co/t/trying-to-query-geo-distance/8485>\
**Category:** Elasticsearch\
**Created:** [July 23, 2012, 2:39am UTC](https://discuss.elastic.co/t/trying-to-query-geo-distance/8485 "2012-07-23T02:39:46Z")\
**Posts on this page:** 8\
**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:** [July 23, 2012, 2:39am UTC](https://discuss.elastic.co/t/trying-to-query-geo-distance/8485/1 "2012-07-23T02:39:46Z")

</div>

I'm having some issues querying geo\_distance in my ES index. Here's my mapping:  
{  
"Event": {  
"properties" : {  
"docType": {"type": "string", "store":"yes"},  
"description" : {"type" : "string", "store" : "yes"},  
"title" : {"type" : "string", "store" : "yes"},  
"location" : { "type" : "geo\_point", "lat\_lon":  
"true","store":"yes" },  
"startTime" : {"type": "date", "store": "yes"},  
"tags" : {"type" : "string", "index\_name" : "tag"}  
}  
}  
}

I have documents that look like this:

{  
"\_index" : "syncrswim",  
"\_type" : "syncrswim",  
"\_id" : "3e9e9d1f82385af7e01146f8a4063d42",  
"\_score" : 0.13977994, "\_source" : {"docType":"Event",  
"location":{"lon":-110.944703,"lat":32.254652},  
"lastUpdated":"2012-06-08T04:12:51",  
"provider":"eventbrite",  
"externalId":"2487867278",  
"stopTime":"2016-08-19T23:00:00",  
"\_rev":"2-4d5ec9d8fe68689d781493e847600baa",  
"startTime":"2015-04-26T03:00:00",  
"externalUpdatedDate":"2012-06-08T04:12:51",  
"title":"Tucson Young Professionals Membership",  
"\_id":"3e9e9d1f82385af7e01146f8a4063d42",  
"description":"Tucson Young Professionals ...",  
"venueId":"3e9e9d1f82385af7e01146f8a40642a4"}

When I do a query like this it works fine:  
"query": {  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "Aesop",  
"fields" : ["title", "description"]  
}  
},  
"filter" : {  
"term" : {  
"docType" : "event"  
}  
}  
}  
}

I have tried this kind of query:  
{  
"filtered" : {  
"query" : {  
"query\_string" : {  
"query" : "Aesop",  
"fields" : ["title", "description"]  
}  
},  
"filter" : {  
"and" : {  
"filters" : [ {  
"term" : {  
"docType" : "event"  
}  
}, {  
"geo\_distance" : {  
"location" : {  
"lat": 32.2217429,  
"long" : -110.926479  
},  
"distance" : "25.0mi"  
}  
} ]  
}  
}  
}  
}

but that returns zero results. I've tried a different query:  
{"query" : {"filtered" : {"query" : {"query\_string" : {"query" :  
"annual","fields" : ["title", "description"]}},"filter" : {"and" :  
{"filters" : [ {"term" : {"docType" : "event"}}, {"geo\_distance" :  
{"Event.location" : {"lat": 32.2217429,"lon" : -110.926479},"distance"  
: "50mi"}} ]}}}}}

Which also returns zero results.

Here is the full mapping as returned through \_mapping.  
{ "syncrswim" : { "syncrswim" : {  
"properties" : {  
"\_rev" : {  
"type" : "string"  
},  
"address1" : {  
"type" : "string"  
},  
"city" : {  
"type" : "string"  
},  
"description" : {  
"type" : "string"  
},  
"docType" : {  
"type" : "string"  
},  
"externalId" : {  
"type" : "string"  
},  
"externalUpdatedDate" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"lastUpdated" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"links" : {  
"dynamic" : "true",  
"properties" : {  
"image" : {  
"type" : "string"  
},  
"main" : {  
"type" : "string"  
}  
}  
},  
"location" : {  
"dynamic" : "true",  
"properties" : {  
"lat" : {  
"type" : "double"  
},  
"lon" : {  
"type" : "double"  
}  
}  
},  
"name" : {  
"type" : "string"  
},  
"postalCode" : {  
"type" : "string"  
},  
"provider" : {  
"type" : "string"  
},  
"startTime" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"state" : {  
"type" : "string"  
},  
"stopTime" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"tags" : {  
"type" : "string"  
},  
"title" : {  
"type" : "string"  
},  
"venueId" : {  
"type" : "string"  
}  
}  
},  
"Place" : {  
"properties" : {  
"address1" : {  
"type" : "string",  
"store" : "yes"  
},  
"city" : {  
"type" : "string",  
"store" : "yes"  
},  
"docType" : {  
"type" : "string",  
"store" : "yes"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true,  
"store" : "yes"  
},  
"name" : {  
"type" : "string",  
"store" : "yes"  
},  
"state" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
},  
"Event" : {  
"properties" : {  
"description" : {  
"type" : "string",  
"store" : "yes"  
},  
"docType" : {  
"type" : "string",  
"store" : "yes"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true,  
"store" : "yes"  
},  
"startTime" : {  
"type" : "date",  
"store" : "yes",  
"format" : "dateOptionalTime"  
},  
"tags" : {  
"type" : "string",  
"index\_name" : "tag"  
},  
"title" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
}  
}  
}

Any thoughts?

-warner

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [July 23, 2012, 9:27am UTC](https://discuss.elastic.co/t/trying-to-query-geo-distance/8485/2 "2012-07-23T09:27:14Z")

</div>

Hiya

Your 'location' field should of type "geo\_point", not "object" (which is  
what it is now):

> ```
> "location" : {
> "dynamic" : "true",
> "properties" : {
> "lat" : {
> "type" : "double"
> },
> "lon" : {
> "type" : "double"
> }
> }
> },
> 
> ```

See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

clint

---

<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:** [July 23, 2012, 1:30pm UTC](https://discuss.elastic.co/t/trying-to-query-geo-distance/8485/3 "2012-07-23T13:30:31Z")

</div>

Not sure how that got in there, but when I push it in to ES, it is a geo\_point:

"Event" : {  
"properties" : {  
"description" : {  
"type" : "string",  
"store" : "yes"  
},  
"docType" : {  
"type" : "string",  
"store" : "yes"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true,  
"store" : "yes"  
},  
...

That was one of the things I wasn't sure on. The mapping data is in  
the db twice somehow. Not sure if ES does something automatic? But I  
specify the "Event" and "Place" mappings.

-warner

On Mon, Jul 23, 2012 at 2:27 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) wrote:

> Hiya
> 
> Your 'location' field should of type "geo\_point", not "object" (which is  
> what it is now):
> 
> > ```
> > "location" : {
> > "dynamic" : "true",
> > "properties" : {
> > "lat" : {
> > "type" : "double"
> > },
> > "lon" : {
> > "type" : "double"
> > }
> > }
> > },
> > 
> > ```
> 
> See  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html)
> 
> clint

---

<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:** [July 23, 2012, 2:07pm UTC](https://discuss.elastic.co/t/trying-to-query-geo-distance/8485/4 "2012-07-23T14:07:16Z")

</div>

Ok, I wiped out the existing mapping and completely redid it, this  
time adding in "dynamic":false on the location(s) but I'm still not  
getting anything back. Here's the new full \_mapping returned.  
{  
"syncrswim" : {  
"Place" : {  
"properties" : {  
"address1" : {  
"type" : "string",  
"store" : "yes"  
},  
"city" : {  
"type" : "string",  
"store" : "yes"  
},  
"docType" : {  
"type" : "string",  
"store" : "yes"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true,  
"store" : "yes"  
},  
"name" : {  
"type" : "string",  
"store" : "yes"  
},  
"state" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
},  
"syncrswim" : {  
"properties" : {  
"address1" : {  
"type" : "string",  
"store" : "yes"  
},  
"address2" : {  
"type" : "string",  
"store" : "yes"  
},  
"city" : {  
"type" : "string",  
"store" : "yes"  
},  
"description" : {  
"type" : "string",  
"store" : "yes"  
},  
"docType" : {  
"type" : "string",  
"store" : "yes"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true,  
"store" : "yes"  
},  
"name" : {  
"type" : "string",  
"store" : "yes"  
},  
"startTime" : {  
"type" : "date",  
"store" : "yes",  
"format" : "dateOptionalTime"  
},  
"state" : {  
"type" : "string",  
"store" : "yes"  
},  
"tags" : {  
"type" : "string",  
"index\_name" : "tag"  
},  
"title" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
},  
"Event" : {  
"properties" : {  
"description" : {  
"type" : "string",  
"store" : "yes"  
},  
"docType" : {  
"type" : "string",  
"store" : "yes"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true,  
"store" : "yes"  
},  
"startTime" : {  
"type" : "date",  
"store" : "yes",  
"format" : "dateOptionalTime"  
},  
"tags" : {  
"type" : "string",  
"index\_name" : "tag"  
},  
"title" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
}  
}  
}

Do I also have to add back in the properties for lat/lon under the  
location? The examples don't talk about that so I'm not sure if that's  
necessary when I've specified lat\_lon as true.

Thanks!

-warner

On Mon, Jul 23, 2012 at 6:30 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:

> Not sure how that got in there, but when I push it in to ES, it is a geo\_point:
> 
> "Event" : {  
> "properties" : {  
> "description" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "docType" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "location" : {  
> "type" : "geo\_point",  
> "lat\_lon" : true,  
> "store" : "yes"  
> },  
> ...
> 
> That was one of the things I wasn't sure on. The mapping data is in  
> the db twice somehow. Not sure if ES does something automatic? But I  
> specify the "Event" and "Place" mappings.
> 
> -warner
> 
> On Mon, Jul 23, 2012 at 2:27 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) wrote:
> 
> > Hiya
> > 
> > Your 'location' field should of type "geo\_point", not "object" (which is  
> > what it is now):
> > 
> > > ```
> > > "location" : {
> > > "dynamic" : "true",
> > > "properties" : {
> > > "lat" : {
> > > "type" : "double"
> > > },
> > > "lon" : {
> > > "type" : "double"
> > > }
> > > }
> > > },
> > > 
> > > ```
> > 
> > See  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html)
> > 
> > clint

---

<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:** [July 23, 2012, 2:31pm UTC](https://discuss.elastic.co/t/trying-to-query-geo-distance/8485/5 "2012-07-23T14:31:06Z")

</div>

Think I finally got it to work! I ingested a whole batch of new docs  
which got the index working again and now this query works

curl -XGET '[http://localhost:9200/syncrswim/\_search?pretty=tru](http://localhost:9200/syncrswim/_search?pretty=tru)' -d  
'{"query" : {"filtered" : {"query" : {"query\_string" : {"query" :  
"annual","fields" : ["title", "description"]}},"filter" : {"and" :  
{"filters" : [ {"term" : {"docType" : "event"}}, {"geo\_distance" :  
{"location" : {"lat": 32.2217429,"lon" : -110.926479},"distance" :  
"50mi"}} ]}}}}}'

Thank you :).

-warner

On Mon, Jul 23, 2012 at 7:07 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:

> Ok, I wiped out the existing mapping and completely redid it, this  
> time adding in "dynamic":false on the location(s) but I'm still not  
> getting anything back. Here's the new full \_mapping returned.  
> {  
> "syncrswim" : {  
> "Place" : {  
> "properties" : {  
> "address1" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "city" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "docType" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "location" : {  
> "type" : "geo\_point",  
> "lat\_lon" : true,  
> "store" : "yes"  
> },  
> "name" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "state" : {  
> "type" : "string",  
> "store" : "yes"  
> }  
> }  
> },  
> "syncrswim" : {  
> "properties" : {  
> "address1" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "address2" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "city" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "description" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "docType" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "location" : {  
> "type" : "geo\_point",  
> "lat\_lon" : true,  
> "store" : "yes"  
> },  
> "name" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "startTime" : {  
> "type" : "date",  
> "store" : "yes",  
> "format" : "dateOptionalTime"  
> },  
> "state" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "tags" : {  
> "type" : "string",  
> "index\_name" : "tag"  
> },  
> "title" : {  
> "type" : "string",  
> "store" : "yes"  
> }  
> }  
> },  
> "Event" : {  
> "properties" : {  
> "description" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "docType" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "location" : {  
> "type" : "geo\_point",  
> "lat\_lon" : true,  
> "store" : "yes"  
> },  
> "startTime" : {  
> "type" : "date",  
> "store" : "yes",  
> "format" : "dateOptionalTime"  
> },  
> "tags" : {  
> "type" : "string",  
> "index\_name" : "tag"  
> },  
> "title" : {  
> "type" : "string",  
> "store" : "yes"  
> }  
> }  
> }  
> }  
> }
> 
> Do I also have to add back in the properties for lat/lon under the  
> location? The examples don't talk about that so I'm not sure if that's  
> necessary when I've specified lat\_lon as true.
> 
> Thanks!
> 
> -warner
> 
> On Mon, Jul 23, 2012 at 6:30 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:
> 
> > Not sure how that got in there, but when I push it in to ES, it is a geo\_point:
> > 
> > "Event" : {  
> > "properties" : {  
> > "description" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "docType" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "location" : {  
> > "type" : "geo\_point",  
> > "lat\_lon" : true,  
> > "store" : "yes"  
> > },  
> > ...
> > 
> > That was one of the things I wasn't sure on. The mapping data is in  
> > the db twice somehow. Not sure if ES does something automatic? But I  
> > specify the "Event" and "Place" mappings.
> > 
> > -warner
> > 
> > On Mon, Jul 23, 2012 at 2:27 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) wrote:
> > 
> > > Hiya
> > > 
> > > Your 'location' field should of type "geo\_point", not "object" (which is  
> > > what it is now):
> > > 
> > > > ```
> > > > "location" : {
> > > > "dynamic" : "true",
> > > > "properties" : {
> > > > "lat" : {
> > > > "type" : "double"
> > > > },
> > > > "lon" : {
> > > > "type" : "double"
> > > > }
> > > > }
> > > > },
> > > > 
> > > > ```
> > > 
> > > See  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html)
> > > 
> > > clint

---

<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, 2:55am UTC](https://discuss.elastic.co/t/trying-to-query-geo-distance/8485/6 "2012-08-16T02:55:50Z")

</div>

Hi all, after getting this working again I ingested more docs into my  
database and it stopped working. When I look up my mapping it created  
this section all over again, even though I specified location field to  
be not-dynamic.

{  
"syncrswim" : {  
"syncrswim" : {  
"properties" : {  
"\_rev" : {  
"type" : "string"  
},  
"address1" : {  
"type" : "string"  
},  
"city" : {  
"type" : "string"  
},  
"description" : {  
"type" : "string"  
},  
"docType" : {  
"type" : "string"  
},  
"externalId" : {  
"type" : "string"  
},  
"externalUpdatedDate" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"lastUpdated" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"links" : {  
"dynamic" : "true",  
"properties" : {  
"main" : {  
"type" : "string"  
}  
}  
},  
"location" : {  
"dynamic" : "true",  
"properties" : {  
"lat" : {  
"type" : "double"  
},  
"lon" : {  
"type" : "double"  
}  
}  
},  
"name" : {  
"type" : "string"  
},  
"postalCode" : {  
"type" : "string"  
},  
"provider" : {  
"type" : "string"  
},  
"startTime" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"state" : {  
"type" : "string"  
},  
"title" : {  
"type" : "string"  
},  
"venueId" : {  
"type" : "string"  
}  
}  
},  
"Place" : {  
"properties" : {  
"address1" : {  
"type" : "string",  
"store" : "yes"  
},  
"address2" : {  
"type" : "string",  
"store" : "yes"  
},  
"city" : {  
"type" : "string",  
"store" : "yes"  
},  
"docType" : {  
"type" : "string",  
"store" : "yes"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true,  
"store" : "yes"  
},  
"name" : {  
"type" : "string",  
"store" : "yes"  
},  
"state" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
},  
"Event" : {  
"properties" : {  
"description" : {  
"type" : "string",  
"store" : "yes"  
},  
"docType" : {  
"type" : "string",  
"store" : "yes"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true,  
"store" : "yes"  
},  
"startTime" : {  
"type" : "date",  
"store" : "yes",  
"format" : "dateOptionalTime"  
},  
"tags" : {  
"type" : "string",  
"index\_name" : "tag"  
},  
"title" : {  
"type" : "string",  
"store" : "yes"  
}  
}  
}  
}  
}

Now, when I'm pushing my mappings I'm only pushing Event and Place,  
the rest is all done through the dynamic mapping. Now, I don't think I  
want to disable dynamic mapping, but I certainly don't want it  
dynamically create the location as an object.

How do I specify an overall mapping for my documents being ingested so  
that it doesn't do this? My index is syncrswim and my base type is  
syncrswim (when I created my index), under that I created two mappings  
for Event and Place, so do I need create a mapping for syncrswim and  
place location in there as well?

Thanks in advance!

-warner

On Mon, Jul 23, 2012 at 7:31 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:

> Think I finally got it to work! I ingested a whole batch of new docs  
> which got the index working again and now this query works
> 
> curl -XGET '[http://localhost:9200/syncrswim/\_search?pretty=tru](http://localhost:9200/syncrswim/_search?pretty=tru)' -d  
> '{"query" : {"filtered" : {"query" : {"query\_string" : {"query" :  
> "annual","fields" : ["title", "description"]}},"filter" : {"and" :  
> {"filters" : [ {"term" : {"docType" : "event"}}, {"geo\_distance" :  
> {"location" : {"lat": 32.2217429,"lon" : -110.926479},"distance" :  
> "50mi"}} ]}}}}}'
> 
> Thank you :).
> 
> -warner
> 
> On Mon, Jul 23, 2012 at 7:07 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:
> 
> > Ok, I wiped out the existing mapping and completely redid it, this  
> > time adding in "dynamic":false on the location(s) but I'm still not  
> > getting anything back. Here's the new full \_mapping returned.  
> > {  
> > "syncrswim" : {  
> > "Place" : {  
> > "properties" : {  
> > "address1" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "city" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "docType" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "location" : {  
> > "type" : "geo\_point",  
> > "lat\_lon" : true,  
> > "store" : "yes"  
> > },  
> > "name" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "state" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > }  
> > }  
> > },  
> > "syncrswim" : {  
> > "properties" : {  
> > "address1" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "address2" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "city" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "description" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "docType" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "location" : {  
> > "type" : "geo\_point",  
> > "lat\_lon" : true,  
> > "store" : "yes"  
> > },  
> > "name" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "startTime" : {  
> > "type" : "date",  
> > "store" : "yes",  
> > "format" : "dateOptionalTime"  
> > },  
> > "state" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "tags" : {  
> > "type" : "string",  
> > "index\_name" : "tag"  
> > },  
> > "title" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > }  
> > }  
> > },  
> > "Event" : {  
> > "properties" : {  
> > "description" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "docType" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > },  
> > "location" : {  
> > "type" : "geo\_point",  
> > "lat\_lon" : true,  
> > "store" : "yes"  
> > },  
> > "startTime" : {  
> > "type" : "date",  
> > "store" : "yes",  
> > "format" : "dateOptionalTime"  
> > },  
> > "tags" : {  
> > "type" : "string",  
> > "index\_name" : "tag"  
> > },  
> > "title" : {  
> > "type" : "string",  
> > "store" : "yes"  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > Do I also have to add back in the properties for lat/lon under the  
> > location? The examples don't talk about that so I'm not sure if that's  
> > necessary when I've specified lat\_lon as true.
> > 
> > Thanks!
> > 
> > -warner
> > 
> > On Mon, Jul 23, 2012 at 6:30 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:
> > 
> > > Not sure how that got in there, but when I push it in to ES, it is a geo\_point:
> > > 
> > > "Event" : {  
> > > "properties" : {  
> > > "description" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "docType" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "location" : {  
> > > "type" : "geo\_point",  
> > > "lat\_lon" : true,  
> > > "store" : "yes"  
> > > },  
> > > ...
> > > 
> > > That was one of the things I wasn't sure on. The mapping data is in  
> > > the db twice somehow. Not sure if ES does something automatic? But I  
> > > specify the "Event" and "Place" mappings.
> > > 
> > > -warner
> > > 
> > > On Mon, Jul 23, 2012 at 2:27 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) wrote:
> > > 
> > > > Hiya
> > > > 
> > > > Your 'location' field should of type "geo\_point", not "object" (which is  
> > > > what it is now):
> > > > 
> > > > > ```
> > > > > "location" : {
> > > > > "dynamic" : "true",
> > > > > "properties" : {
> > > > > "lat" : {
> > > > > "type" : "double"
> > > > > },
> > > > > "lon" : {
> > > > > "type" : "double"
> > > > > }
> > > > > }
> > > > > },
> > > > > 
> > > > > ```
> > > > 
> > > > See  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html)
> > > > 
> > > > clint

--

---

<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:56am UTC](https://discuss.elastic.co/t/trying-to-query-geo-distance/8485/7 "2012-08-16T03:56:46Z")

</div>

I think I finally figured it out by adding in a type for syncrswim  
(and conversely understanding mappings a bit better).

-warner

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

> Hi all, after getting this working again I ingested more docs into my  
> database and it stopped working. When I look up my mapping it created  
> this section all over again, even though I specified location field to  
> be not-dynamic.
> 
> {  
> "syncrswim" : {  
> "syncrswim" : {  
> "properties" : {  
> "\_rev" : {  
> "type" : "string"  
> },  
> "address1" : {  
> "type" : "string"  
> },  
> "city" : {  
> "type" : "string"  
> },  
> "description" : {  
> "type" : "string"  
> },  
> "docType" : {  
> "type" : "string"  
> },  
> "externalId" : {  
> "type" : "string"  
> },  
> "externalUpdatedDate" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> },  
> "lastUpdated" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> },  
> "links" : {  
> "dynamic" : "true",  
> "properties" : {  
> "main" : {  
> "type" : "string"  
> }  
> }  
> },  
> "location" : {  
> "dynamic" : "true",  
> "properties" : {  
> "lat" : {  
> "type" : "double"  
> },  
> "lon" : {  
> "type" : "double"  
> }  
> }  
> },  
> "name" : {  
> "type" : "string"  
> },  
> "postalCode" : {  
> "type" : "string"  
> },  
> "provider" : {  
> "type" : "string"  
> },  
> "startTime" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> },  
> "state" : {  
> "type" : "string"  
> },  
> "title" : {  
> "type" : "string"  
> },  
> "venueId" : {  
> "type" : "string"  
> }  
> }  
> },  
> "Place" : {  
> "properties" : {  
> "address1" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "address2" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "city" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "docType" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "location" : {  
> "type" : "geo\_point",  
> "lat\_lon" : true,  
> "store" : "yes"  
> },  
> "name" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "state" : {  
> "type" : "string",  
> "store" : "yes"  
> }  
> }  
> },  
> "Event" : {  
> "properties" : {  
> "description" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "docType" : {  
> "type" : "string",  
> "store" : "yes"  
> },  
> "location" : {  
> "type" : "geo\_point",  
> "lat\_lon" : true,  
> "store" : "yes"  
> },  
> "startTime" : {  
> "type" : "date",  
> "store" : "yes",  
> "format" : "dateOptionalTime"  
> },  
> "tags" : {  
> "type" : "string",  
> "index\_name" : "tag"  
> },  
> "title" : {  
> "type" : "string",  
> "store" : "yes"  
> }  
> }  
> }  
> }  
> }
> 
> Now, when I'm pushing my mappings I'm only pushing Event and Place,  
> the rest is all done through the dynamic mapping. Now, I don't think I  
> want to disable dynamic mapping, but I certainly don't want it  
> dynamically create the location as an object.
> 
> How do I specify an overall mapping for my documents being ingested so  
> that it doesn't do this? My index is syncrswim and my base type is  
> syncrswim (when I created my index), under that I created two mappings  
> for Event and Place, so do I need create a mapping for syncrswim and  
> place location in there as well?
> 
> Thanks in advance!
> 
> -warner
> 
> On Mon, Jul 23, 2012 at 7:31 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:
> 
> > Think I finally got it to work! I ingested a whole batch of new docs  
> > which got the index working again and now this query works
> > 
> > curl -XGET '[http://localhost:9200/syncrswim/\_search?pretty=tru](http://localhost:9200/syncrswim/_search?pretty=tru)' -d  
> > '{"query" : {"filtered" : {"query" : {"query\_string" : {"query" :  
> > "annual","fields" : ["title", "description"]}},"filter" : {"and" :  
> > {"filters" : [ {"term" : {"docType" : "event"}}, {"geo\_distance" :  
> > {"location" : {"lat": 32.2217429,"lon" : -110.926479},"distance" :  
> > "50mi"}} ]}}}}}'
> > 
> > Thank you :).
> > 
> > -warner
> > 
> > On Mon, Jul 23, 2012 at 7:07 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:
> > 
> > > Ok, I wiped out the existing mapping and completely redid it, this  
> > > time adding in "dynamic":false on the location(s) but I'm still not  
> > > getting anything back. Here's the new full \_mapping returned.  
> > > {  
> > > "syncrswim" : {  
> > > "Place" : {  
> > > "properties" : {  
> > > "address1" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "city" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "docType" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "location" : {  
> > > "type" : "geo\_point",  
> > > "lat\_lon" : true,  
> > > "store" : "yes"  
> > > },  
> > > "name" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "state" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > }  
> > > }  
> > > },  
> > > "syncrswim" : {  
> > > "properties" : {  
> > > "address1" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "address2" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "city" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "description" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "docType" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "location" : {  
> > > "type" : "geo\_point",  
> > > "lat\_lon" : true,  
> > > "store" : "yes"  
> > > },  
> > > "name" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "startTime" : {  
> > > "type" : "date",  
> > > "store" : "yes",  
> > > "format" : "dateOptionalTime"  
> > > },  
> > > "state" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "tags" : {  
> > > "type" : "string",  
> > > "index\_name" : "tag"  
> > > },  
> > > "title" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > }  
> > > }  
> > > },  
> > > "Event" : {  
> > > "properties" : {  
> > > "description" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "docType" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > },  
> > > "location" : {  
> > > "type" : "geo\_point",  
> > > "lat\_lon" : true,  
> > > "store" : "yes"  
> > > },  
> > > "startTime" : {  
> > > "type" : "date",  
> > > "store" : "yes",  
> > > "format" : "dateOptionalTime"  
> > > },  
> > > "tags" : {  
> > > "type" : "string",  
> > > "index\_name" : "tag"  
> > > },  
> > > "title" : {  
> > > "type" : "string",  
> > > "store" : "yes"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > Do I also have to add back in the properties for lat/lon under the  
> > > location? The examples don't talk about that so I'm not sure if that's  
> > > necessary when I've specified lat\_lon as true.
> > > 
> > > Thanks!
> > > 
> > > -warner
> > > 
> > > On Mon, Jul 23, 2012 at 6:30 AM, Warner Onstine [warnero@gmail.com](mailto:warnero@gmail.com) wrote:
> > > 
> > > > Not sure how that got in there, but when I push it in to ES, it is a geo\_point:
> > > > 
> > > > "Event" : {  
> > > > "properties" : {  
> > > > "description" : {  
> > > > "type" : "string",  
> > > > "store" : "yes"  
> > > > },  
> > > > "docType" : {  
> > > > "type" : "string",  
> > > > "store" : "yes"  
> > > > },  
> > > > "location" : {  
> > > > "type" : "geo\_point",  
> > > > "lat\_lon" : true,  
> > > > "store" : "yes"  
> > > > },  
> > > > ...
> > > > 
> > > > That was one of the things I wasn't sure on. The mapping data is in  
> > > > the db twice somehow. Not sure if ES does something automatic? But I  
> > > > specify the "Event" and "Place" mappings.
> > > > 
> > > > -warner
> > > > 
> > > > On Mon, Jul 23, 2012 at 2:27 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com) wrote:
> > > > 
> > > > > Hiya
> > > > > 
> > > > > Your 'location' field should of type "geo\_point", not "object" (which is  
> > > > > what it is now):
> > > > > 
> > > > > > ```
> > > > > > "location" : {
> > > > > > "dynamic" : "true",
> > > > > > "properties" : {
> > > > > > "lat" : {
> > > > > > "type" : "double"
> > > > > > },
> > > > > > "lon" : {
> > > > > > "type" : "double"
> > > > > > }
> > > > > > }
> > > > > > },
> > > > > > 
> > > > > > ```
> > > > > 
> > > > > See  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html)
> > > > > 
> > > > > clint

--

---

<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/trying-to-query-geo-distance/8485/8 "2017-07-06T03:16:14Z")

</div>


