2

I'm running ElasticSearch on Ubuntu 14.04 and I can't seem to get ES to find a template for a specific index. The documentation is confusing in that it says you should put a templates directory under /etc/elasticsearch/config/, but then later in the documentation it says that configuration should be under /etc/elasticsearch, like the yaml file is at /etc/elasticsearch.

The reason I know its not finding it is I can do a:

curl -XGET 'http://localhost:9200/_template/my_template?pretty'

and get an empty JSON object back.

dvreed77
  • 2,217
  • 2
  • 27
  • 42

1 Answers1

2

According to the config notes for Templates:

Index templates can also be placed within the config location (path.conf) under the templates directory (note, make sure to place them on all master eligible nodes).

In your case, if your main configuration directory is /etc/elasticsearch then you may place templates inside a folder called /etc/elasticsearch/templates. You'll need to place that file onto all of the servers which are running master-eligible nodes. (E.g., for a small cluster, onto all nodes.)

In my experience, it's a little more common to simply POST templates using the HTTP API. That way you can add and remove templates without having to worry about managing and deploying configurations on your servers.

Index Templates

Nick Zadrozny
  • 7,906
  • 33
  • 38
  • placing them under templates still doesn't work, but I've resided to do what you suggest and simply post them. Thanks for the help thoug – dvreed77 Jan 15 '15 at 19:42
  • Yeah, sure thing. Generally speaking with Elasticsearch it's best to embrace the API and avoid server-side configs. – Nick Zadrozny Jan 15 '15 at 19:48
  • 3
    Using the API to POST templates to ES is definitely the way to go. By explicitly adding the mappings yourself, you're in control and don't have to worry about whether the mappings are picked up automatically. But be careful. Unless you proxy all your ES requests through, say, a piece of middleware, you could end up with a race condition whereby one client writes to an ES index before another creates the mappings, in which case ES will choose its default mappings for you. – Mike Johnston Jul 09 '15 at 13:32
  • 1
    The race condition mentioned by @MikeJohnston seems to be a perfect reason to use the config file based approach. I have been trying to get that working, but so far, no luck. When I create an index that matches the template, I still don't get the mappings. – jxstanford Aug 24 '15 at 19:04