# How to get ES to autodetect geo\_point type and if it can't, where should I define the mapping?

**URL:** <https://discuss.elastic.co/t/how-to-get-es-to-autodetect-geo-point-type-and-if-it-cant-where-should-i-define-the-mapping/21092>\
**Category:** Elasticsearch\
**Created:** [December 4, 2014, 9:44pm UTC](https://discuss.elastic.co/t/how-to-get-es-to-autodetect-geo-point-type-and-if-it-cant-where-should-i-define-the-mapping/21092 "2014-12-04T21:44:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![am1](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@am1](https://discuss.elastic.co/u/am1)\
**Post date:** [December 4, 2014, 9:44pm UTC](https://discuss.elastic.co/t/how-to-get-es-to-autodetect-geo-point-type-and-if-it-cant-where-should-i-define-the-mapping/21092/1 "2014-12-04T21:44:50Z")

</div>

Hello, I am using ES js wrapper in a nodejs application. I would like to  
get ES to do some geospatial searches, so from what I understand, I need to  
set the following options on mylocation field:

mylocation: {  
properties: {  
type: 'geo\_point',  
lat\_lon: true  
}  
}

I am inserting the data like so:

// In my nodejs insert()  
client.index({  
index: 'myapp',  
type: 'user',  
id: user.id,  
body: {  
name: user.name,  
mylocation: { lat: mylat, lon: mylon}  
}  
});

This inserts the lat,lon as doubles though. To counter this, I have a  
declared a mapping:

client.indicies.putMappings({  
index: 'myapp',  
type: 'user',  
body: {  
'user': {  
properties: {  
mylocation: { type: 'geo\_point', lat\_lon: true }  
}  
}  
}  
});

This all works, but it is it possible to supply ES a certain format so that  
ES will automatically create a geo\_point type with lat\_lon set to true?

If not, could someone clarify where I should declare the mappings? Should  
mappings be declared each time before an insert/update happens in ES or is  
it just one time? If it's just one time, do I put the mapping inside my  
root nodejs application? What happens if I restart the nodejs application:  
would the mapping attempt to go through all ES documents and reindex the  
mylocation field to geo\_point even though it's already been set from the  
previous reboot of the app?

Thanks!

--  
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/d1ac1327-365f-4bcb-a0f9-94dd89580c7d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1ac1327-365f-4bcb-a0f9-94dd89580c7d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 5, 2014, 6:12am UTC](https://discuss.elastic.co/t/how-to-get-es-to-autodetect-geo-point-type-and-if-it-cant-where-should-i-define-the-mapping/21092/2 "2014-12-05T06:12:51Z")

</div>

You basically define a mapping once and you're done.  
Have a look at templates. They could help you using naming convention for fields. Like all \*location field names will be geo\_point.

David

> Le 4 déc. 2014 à 22:44, am [aplmsn@gmail.com](mailto:aplmsn@gmail.com) a écrit :
> 
> Hello, I am using ES js wrapper in a nodejs application. I would like to get ES to do some geospatial searches, so from what I understand, I need to set the following options on mylocation field:
> 
> mylocation: {  
> properties: {  
> type: 'geo\_point',  
> lat\_lon: true  
> }  
> }
> 
> I am inserting the data like so:
> 
> // In my nodejs insert()  
> client.index({  
> index: 'myapp',  
> type: 'user',  
> id: user.id,  
> body: {  
> name: user.name,  
> mylocation: { lat: mylat, lon: mylon}  
> }  
> });
> 
> This inserts the lat,lon as doubles though. To counter this, I have a declared a mapping:
> 
> client.indicies.putMappings({  
> index: 'myapp',  
> type: 'user',  
> body: {  
> 'user': {  
> properties: {  
> mylocation: { type: 'geo\_point', lat\_lon: true }  
> }  
> }  
> }  
> });
> 
> This all works, but it is it possible to supply ES a certain format so that ES will automatically create a geo\_point type with lat\_lon set to true?
> 
> If not, could someone clarify where I should declare the mappings? Should mappings be declared each time before an insert/update happens in ES or is it just one time? If it's just one time, do I put the mapping inside my root nodejs application? What happens if I restart the nodejs application: would the mapping attempt to go through all ES documents and reindex the mylocation field to geo\_point even though it's already been set from the previous reboot of the app?
> 
> ## Thanks!
> 
> 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/d1ac1327-365f-4bcb-a0f9-94dd89580c7d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d1ac1327-365f-4bcb-a0f9-94dd89580c7d%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/6B1DC450-AFF8-4F55-B07C-7F5087C1DA98%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/6B1DC450-AFF8-4F55-B07C-7F5087C1DA98%40pilato.fr).  
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, 12:45am UTC](https://discuss.elastic.co/t/how-to-get-es-to-autodetect-geo-point-type-and-if-it-cant-where-should-i-define-the-mapping/21092/3 "2017-07-06T00:45:39Z")

</div>


