使用jq批量修改es index template的lifecycle配置
来自三线的随记
aka: use jq tool to modify es index template lifecycle setting in bulk
#!/bin/bash #set -exu set -ue #172.31.45.236 host="127.0.0.1:9200" username="elastic" password="elastic" ilm_name="sw-default-ilm" curl_options=( "-u" "$username:$password" "-s" ) es_sw_templates=`curl ${curl_options[@]} "$host/_cat/templates/sw*?s=name" | awk '{print $1}'` # bak curl ${curl_options[@]} "${host}/_index_template?pretty" > es-${host}-sw-*-templates_`date +%F%T`.bak.json for template in ${es_sw_templates[@]} do echo PUT /_index_template/${template} new_template="" new_template=`curl ${curl_options[@]} "${host}/_index_template/${template}" | jq '.index_templates[0].index_template | .template.settings.index.lifecycle.name |= "'${ilm_name}'"'` curl -X PUT -H "Content-Type: application/json" ${curl_options[@]} "${host}/_index_template/${template}" -d "${new_template}" echo done