Any way to run some scripts (elastic valid commands) in start time?

Hi All,
Looking for a way to initialize ELS instance (need more than elasticsearch.yml params).
I want to put some restrictions as some templates at start time.

My problem is this may you have a better solution:
I want to disable dynamic mapping because I want to have my own mapping. I provide an endpoint in my application for this and if a user calls that endpoint before inserting any document, we will have our own mapping and that is ok. But the problem, that there is no guarantee for that. Because of that I first decided to globally put this to false
index.mapper.dynamic = false
But it is a global limitation which I don't want for some other Indices in the same ELS instance.

Then I thought maybe there is a way to run some scripts on elasticsearch (adding some templates applicable just for some indices not all) at start time. Is there something like that?

Sorry for the long story
Thanks in advance

Addressing just the issue with dynamic mapping: you can set dynamic mapping on an index by index level, so that your existing indices have it disabled, but others have it enabled.

And with index templates you can set default enable/disable behavior for new indices with pattern-matching names.

Thanks for your reply. What about the possibility to run a script on starting my elastic instance to put the template in Elasticsearch just like a configuration.


Simplest thing to do would be to wrap the bin/elasticsearch script with one of your own. Something like:


#start elasticsearch

#wait for elasticsearch to come up
until $(curl --output /dev/null --silent --head --fail http://localhost:9200); do
    printf '.'
    sleep 5

#insert templates
curl -X PUT -H 'Content-Type: application/json' http://localhost:9200/_template/my_template -d @my_template.json
curl -X PUT -H 'Content-Type: application/json' http://localhost:9200/_template/my_other_template -d @my_other_template.json
1 Like

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