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

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/d1ac1327-365f-4bcb-a0f9-94dd89580c7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/d1ac1327-365f-4bcb-a0f9-94dd89580c7d%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6B1DC450-AFF8-4F55-B07C-7F5087C1DA98%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.