Using dynamic templates, I have a "locations" mapping for "location" field with mapping type "geo_point". Some visualizations need this field to be a "geo_shape", however. I would like to extend the mapping similar to how we'd add "fields": { "raw" ... } to support both but unsure how best to define a single mapping that can include both "geo_shape" and "geo_point".
Guess is something like:
"dynamic_templates": [
{
"locations": {
"match": "location",
"mapping": {
???
}
}
}
]
I'm not sure if you can just set mapping type to "geo_point" and have fields with both types or better to define two completely separate mappings and matches with different field naming.
I want both point
and shape
:
"type": "geo_point"
and
"type": "geo_shape",
"tree": "quadtree",
"precision": "50m"
Would something like this work or better yet, is there a way to use copy_to
to copy the lat/lon to both on single insert?
"dynamic_templates": [
{
"locations": {
"match": "location",
"mapping": {
"type": "geo_shape",
"tree": "quadtree",
"precision": "50m",
"fields": {
"point": {
"type": "geo_point"
}
}
}
}
}
]
Appreciate tips on best practice here.
After some trial/error I learned the following so wonder if conclusion is you have to add different fields and types and populate them all redundantly on insert.
-
copy_to
will not copy to a multi-field type (geo_point) -
mapping
will not allow nested fields
So far I got this to work (all separate fields) but there has to be a more elegant way to store these without the redundant entry. https://github.com/mikesparr/elasticsearch-geo-template