Help with Elasticsearch template definition


Hi, reading the documentation about index templates, I have some doubts on which should be the best practice to define a new template.
My particular situation is very simple, I would like to:

  • Define only one template (for Logstash)
  • Restrict Elasticsearch to use only 2 shards and 1 replicas
  • Add some field mappings directly on the template, if needed

So far I've used the default template generated by Logstash:


Should I keep this template and simply add:

PUT _template/logstash
  "template": "logstash",
  "settings": {
    "number_of_shards": 2,
    "number_of_replicas": 1

For the mappings, which is the best option:

  1. Adding them into the index template (like shown above)
  2. Adding them per index using a PUT my_index as shown here
  3. Leaving Logstash assign the correct mapping provided that its configuration contains them

Also, as an alternative to the REST API, which is the proper way to assign an index template to Elasticsearch at startup time?

Thank you

(Mark Walkom) #2

No because that will only ever match indices called logstash, that is what the value of template means.

You would be better off copying the existing mapping file, make the changes, then explicitly defining it in the output.


Hi @warkolm thanks.
For the moment I have copied the whole logstash template and PUT it with my changes to Elasticsearch.
And obviously now my indexes have new replicas & shards.
However, from your answer I didn't catch if I should take another action. Is there any way to change default template settings prior to starting Elasticsearch?

(Mark Walkom) #4


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.