Loading...

Correct type mapping in index template for Elasticsearch

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

If you use Dropwizard Metrics and the Metrics Reporter you might come into the situation, that the max value is not reported as long value. If it is reported as double Elasticsearch will complain you have an invalid mapping type, since a previous one has the type long. To avoid the situation, you can define in the index template, the type Elasticsearch for new indices from that template.

This mapping declares for the document types timer and histogram the field max is of type double. The template field contains the index schema-name. So a new index metrics-2016.09.26 will use this template.

PUT /_template/metrics
{
  "template": "metrics-*",
  "mappings": {
    "timer": {
      "properties": {
        "max": {
          "type": "double"
        }
      }
    },
    "histogram": {
      "properties": {
        "max": {
          "type": "double"
        }
      }
    }
  },
  "settings": {
    "number_of_shards": 1
  },
  "aliases" : {
        "metrics" : {}
  }
}
Please remember the terms for blog comments.