要执行 Elasticsearch 的模板,可以使用 curl 命令来发送 HTTP 请求。以下是一个示例:

curl -X PUT \"http://localhost:9200/_template/my_template\" -H 'Content-Type: application/json' -d '
{
  \"index_patterns\": [\"my_index*\"],
  \"settings\": {
    \"number_of_shards\": 1
  },
  \"mappings\": {
    \"properties\": {
      \"field1\": {
        \"type\": \"keyword\"
      },
      \"field2\": {
        \"type\": \"text\"
      }
    }
  }
}'

在上述示例中,我们使用 curl 命令发送了一个 PUT 请求来创建一个名为 "my_template" 的模板。模板将应用于所有以 "my_index" 开头的索引。

请求的 URL 是 Elasticsearch 的 API 端点地址,例如 http://localhost:9200/_template/my_template

请求的头部包含 Content-Type: application/json,指定请求体的内容类型为 JSON。

请求体是一个 JSON 对象,包含了模板的定义。在示例中,我们定义了一个索引模式,一个设置(包括分片数量),以及一个映射(字段定义)。

注意,示例中的单引号用于在命令行中引用请求体。如果你在脚本中使用 curl,你可能需要使用双引号。

执行以上命令后,Elasticsearch 会将模板保存在集群中,并在创建新索引时自动应用该模板。

使用 Curl 命令执行 Elasticsearch 模板 (不读取文件)

原文地址: https://www.cveoy.top/t/topic/pVFH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录