在Elasticsearch中使用配置文件管理模板的方法是什么?

通常情况下,将上述模板注册到elasticsearch时,会发送如下的http请求。

curl -XPUT localhost:9200/_template/template1 -d `cat template1.json`'

然而,当使用ansible等工具时,如果尝试使用curl注册模板,可能会遇到”因为elasticsearch尚未准备就绪,所以无法接受请求”的情况,因此我们将介绍通过文件管理模板的方法。

Elasticsearch的模板是什么?

在Elasticsearch中,您可以定义模板(相当于数据库中的模式)。
如果要保存URL等信息,Elasticsearch会自动解析URL并将其拆分为协议、域名等部分,这可能会影响解析。
此时,我认为您需要定义如下的模板,以防止URL字段被自动解析。

{
  "template":"{{ index名 }}-*",
  "mappings":{
    "{{ タイプ名 }}":{
      "_source": { "compress": true },
      "properties":{
        "url":{"type":"multi_field",
          "fields":{
            "url":{"type":"string","index":"analyzed"},
            "full":"type":"string","index":"not_analyzed"}
          }
        }
      }
    }
  }
}

如何通过配置文件管理模板。

我们在/etc/elasticsearch/elasticsearch.yml中定义了path.conf。

# Path to directory containing configuration (this file and logging.yml):
# ↓アンコメント
path.conf: /usr/share/elasticsearch/config

将刚才的template1.json文件放在/usr/share/elasticsearch/config/templates目录中。

bannerAds