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


(Hossein Yeganeh Markid) #1

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


(Mike Barretta) #2

@hym
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.


(Hossein Yeganeh Markid) #3

@Mike.Barretta
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.

Thanks


(Mike Barretta) #4

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

#!/bin/bash

#start elasticsearch
$ELASTICSEARCH_HOME/bin/elasticsearch

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

#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

(system) #5

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