问题
I'm attempting to automate the usage of index templates in Elasticsearch, so I've started creating the files in the "[ES_CONFIG_DIR]/templates/" directory (http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#config) with the proper format (sample file: http://pastebin.com/waKCBGgW). My Chef cookbook performs the following steps:
1.Create the JSON template file in the "[ES_CONFIG_DIR]/templates/tpl_misc.json" directory 2.Restart the elasticsearch service
The block of chef code to complete this is:
Related Attributes:
default['elasticsearch']['index_templates'] = [
"tpl_misc"
]
Relate Recipe Code:
directory "#{node['elasticsearch']['path']['conf']}/templates" do
owner 'elasticsearch'
group 'elasticsearch'
mode '0755'
action :create
end
node['elasticsearch']['index_templates'].each do |tpl|
template "#{node['elasticsearch']['path']['conf']}/templates/#{tpl}.json" do
source "#{tpl}.erb"
owner 'elasticsearch'
group 'elasticsearch'
mode '0644'
notifies :restart, 'service[elasticsearch]'
end
end
I can confirm the template files are being created where they should (in /usr/local/etc/elasticsearch/templates) although when I check to see exists in ES (curl -iL http://localhost:9200/_template/tpl_misc) and i always get a 404. Does anyone have any advice on what my issue might be?
I appreciate the help!
回答1:
I've learned that index templates added as files in the "[CONFIG]/templates/" directory do not currently appear in the results of the "/_template/"* API method. Someone refers to that in the following email thread:
http://elasticsearch-users.115913.n3.nabble.com/Loading-of-index-settings-template-from-file-in-config-templates-td4024923.html#d1366317284000-941
Although it was not documented in the official index templates documentation on the Elasticsearch website. I've since then created a pull request to have the documentation updated which has also lead to an issue being opened in order to have ability added to the "/_template/" API method.
回答2:
Templates from config files are no longer supported. Use a PUT request to the api instead.
https://www.elastic.co/guide/en/elasticsearch/reference/2.1/breaking_20_index_api_changes.html#_file_based_index_templates
https://github.com/elastic/elasticsearch/issues/10193
This can be automated using curl for those trying to use ansible or something to provision their nodes. The main drawback being that you have to wait for your node to be up before you can curl.
来源:https://stackoverflow.com/questions/29105061/elasticsearch-file-based-index-templates-not-showing-up-in-template-api-call