I want to apply index templates in config/templates dir in es docker container.
I tried it in following way , but it did not works well.
Please tell me how to do this.
Not sure I can say if it's the best practice or not, this really depends on your use case and your environment. Who control the template, do you want to change it without restarting your logstash container, etc.
Beats also have those feature and they can be configured to load either default or custom index templates into elasticsearch. So a container running something like filebeat could be used, with the proper configuration it could be tasked with loading your index template into elasticsearch. It could even execute only once, load the template then die once it's finished via the "setup" command that Beats have.
For Beats you can't point them at a template file, you need to give the beat a path to a fields.yml file which represent the index template if you will, the Beat will generate an index template from the fields.yml file and load it into elasticsearch.
Of course you can also use simple curl command to load index template json file into elasticsearch. So it's possible to build a docker container whose sole purpose is to load index templates into elasticsearch once it is started and healthy. But if you do that the "orchestration" of it is left for you to figure out and organize. You can obvisouly fail to load an index template into elasticsearch if you do it while elasticsearch is not yet available for example... So you would need to account for that if you use a sidecar container tasked with loading index templates.
Many ways...
I think the best practice you're looking for because you want the thing to work after a docker-compose up is to consider that Elastic has made the Beats and Logstash capable of handling and loading index template into Elasticsearch when they are about to start sending events into ES. Like if the clients were in charge of loading the template they need for the events they will send.
That works for many but it can have some drawbacks depending on your goal and setup that would lead you to use other more custom methods or less automatic methods.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.