【问题标题】:How to create Elasticsearch data stream template on a python's client?如何在 python 客户端上创建 Elasticsearch 数据流模板?
【发布时间】:2022-12-25 18:43:29
【问题描述】:

我怎样才能在 python 的客户端上调用这个索引模板 PUT ?

Elastic 控制台上有效的 PUT 请求示例:

    PUT _index_template/ts_event_template
    {
      "index_patterns": [
        "ts-events"
      ],
      "data_stream": {},
      "template": {
        "settings": {
          "number_of_shards": 1,
          "number_of_replicas": 1,
          "index": {
            "lifecycle": {
              "name": "ts_policy_v1",
              "rollover_alias": "ts_events_alias"
            }
          }
        },
        "aliases": {
          "ts_events_alias": {}
        }
      }
    }

与客户端 put_template 函数一起使用时失败索引模板的示例:

resp = client.indices.put_template(
    name="datastream",
    body={
        "index_patterns": ["ts-events"],
        "data_stream": {},
        "settings": {
            "number_of_shards": 1,
            "index": {
              "lifecycle": {
                "name": "ts_policy_v1",
                "rollover_alias": "ts_events_alias"
              }
           }
         },
         "aliases": {
            "ts_events_alias": {}
         }
      }
   }
)
print(resp)

这引发了一个解析错误数据流场地。

我怎样才能让它作为数据流索引模板工作?

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    旧索引 put_template 使用旧索引模板版本。

    为了使用最新的索引模板,您应该使用:

    es_client.indices.put_index_template(name="index template name", body={template json here...})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 2021-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多