How to add new geo_point type mapping to existing index template?


(Joe) #1

We have a single index with new types constantly being created. There is a template that the index used to do the mapping. Now I would like to add a new geo_point mapping to the template so that new types will include the new geo_point mapping.

I tried just updating the existing template via the head plugin. It allowed me to update the template and I can see the changes when doing a GET _template/
eg
"location":{"type":"geo_point", "store":"no"}

But new types will map location to 2 float parameters.

However, if I manually create a type with a dummy document, apply the mapping to the type eg PUT /myindex/_mapping/mynewtype -d ‘{"properties":{"location":{"type":"geo_point","store":"no"}}}’. new documents created under mynewtype will map location as geo_point.

So should I be updating the template? Is applying the mapping directly to a type my only option? I would like to avoid re-indexing if possible.

Thanks.


(Mark Walkom) #2

You should be updating the template, yes.

What does your entire mapping look like?


(Joe) #3

@warkolm thanks for your help. The following is the entire template / mapping we have.

{
  "*": {
    "order": 0,
    "template": "*",
    "settings": {
      "index.number_of_replicas": "3",
      "index.number_of_shards": "5"
    },
    "mappings": {}
  },
  "metadata": {
    "order": 1,
    "template": "metadata:*",
    "settings": {
      "index.number_of_replicas": "4",
      "index.number_of_shards": "1"
    },
    "mappings": {
      "_default_": {
        "dynamic_templates": [
          {
            "metadata": {
              "mapping": {
                "index": "no",
                "store": true,
                "type": "string"
              },
              "path_match": "*"
            }
          }
        ],
        "_all": {
          "enabled": false
        }
      }
    }
  },
  "myindex": {
    "order": 1,
    "template": "myindex*",
    "settings": {
      "index.analysis.analyzer.myindex_analyzer.tokenizer": "whitespace"
    },
    "mappings": {
      "_default_": {
        "dynamic_templates": [
          {
            "targets": {
              "index_name": "target",
              "mapping": {
                "index_name": "{name}",
                "omit_norms": "yes",
                "store": "no",
                "analyzer": "myindex_analyzer",
                "type": "string"
              },
              "match_mapping_type": "string",
              "path_match": "targets.*"
            }
          },
          {
            "metadata": {
              "mapping": {
                "index": "no",
                "store": "yes"
              },
              "path_match": "metadata.*"
            }
          }
        ],
        "properties": {
          "tags": {
            "index_name": "tag",
            "omit_norms": "yes",
            "store": "no",
            "analyzer": "myindex_analyzer",
            "type": "string"
          },
          "height": {
            "store": "yes",
            "type": "integer"
          },
          "location": {
            "store": "no",
            "type": "geo_point"
          },
          "priority": {
            "store": "yes",
            "type": "integer"
          },
          "width": {
            "store": "yes",
            "type": "integer"
          },
          "alwaysIncluded": {
            "store": "no",
            "type": "boolean"
          },
          "html": {
            "store": "yes",
            "type": "string"
          }
        },
        "_all": {
          "enabled": false
        }
      }
    }
  }
}

Regards,


(system) #4