0

我正在尝试在 Elasticsearch 中自动使用索引模板,因此我开始在“[ES_CONFIG_DIR]/templates/”目录中创建文件(http://www.elastic.co/guide/en/elasticsearch/ reference/current/indices-templates.html#config)具有正确的格式(示例文件: http: //pastebin.com/waKCBGgW)。我的 Chef 食谱执行以下步骤:

1.在“[ES_CONFIG_DIR]/templates/tpl_misc.json”目录下创建JSON模板文件 2.重启elasticsearch服务

完成此操作的厨师代码块是:

相关属性:

    default['elasticsearch']['index_templates'] = [
      "tpl_misc"
    ]

相关配方代码:

    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

我可以确认正在创建模板文件的位置(在 /usr/local/etc/elasticsearch/templates 中),尽管当我检查是否存在于 ES 中时(curl -iL http://localhost:9200/_template/tpl_misc)我总是得到 404。有人对我的问题有什么建议吗?

感谢您的帮助!

4

2 回答 2

1

我了解到,作为文件添加到“[CONFIG]/templates/”目录中的索引模板当前不会出现在“/_template/ ”* API 方法的结果中。有人在以下电子邮件线程中提到了这一点:

http://elasticsearch-users.115913.n3.nabble.com/Loading-of-index-settings-template-from-file-in-config-templates-td4024923.html#d1366317284000-941

尽管Elasticsearch 网站上的官方索引模板文档中没有记录它。从那以后,我创建了一个拉取请求来更新文档,这也导致了一个问题被打开,以便将能力添加到“/_template/”API 方法中。

于 2015-03-23T11:40:38.400 回答
0

不再支持来自配置文件的模板。改为使用对 api 的 PUT 请求。

https://www.elastic.co/guide/en/elasticsearch/reference/2.1/break_20_index_api_changes.html#_file_based_index_templates

https://github.com/elastic/elasticsearch/issues/10193

对于那些试图使用 ansible 或其他东西来配置其节点的人,这可以使用 curl 自动化。主要缺点是您必须等待节点启动才能卷曲。

于 2018-03-16T17:46:29.517 回答