写个shell脚本判断index状态是不是黄色 如果是 elasticsearch使用curl调整索f副本分片为0
时间: 2024-12-10 08:38:18 浏览: 14
当你需要编写一个Shell脚本来检查Elasticsearch索引的状态是否为"yellow",并在满足条件时通过`curl`命令调整其副本数为0,可以参考以下脚本示例:
```bash
#!/bin/bash
# 定义检查索引状态的函数
check_index_status() {
local index="$1"
local status=$(curl -s "http://localhost:9200/$index/_stats" | jq '.indices.$index.stats.shards.replica_shards.current')
if [[ $status == "yellow" ]]; then
echo "Index $index is yellow, adjusting replica count to 0..."
else
echo "Index $index is not yellow."
fi
}
# 指定你想检查的索引名称
INDEX_NAME="your_index_name"
# 调用函数并检查状态
check_index_status "$INDEX_NAME"
# 如果状态为yellow,则调整副本数
if [ $? -H 'Content-Type: application/json' -d'
{
"index.blocks.write": null,
"number_of_replicas": "0"
}'
echo "Adjusted replica count for $INDEX_NAME to 0."
else
echo "No need to adjust replica count."
fi
阅读全文