es索引相关操作

一、实践

需求:将生产环境指定的es索引导入到测试环境

思路:

1、查询prod环境要导入的索引,导入到txt文件
2、删除test环境所有索引(依据实际情况)
3、编写脚本
4、查看进度

步骤:

1、查看索引
查看prod环境索引

curl -s -XGET --user "用户名:密码" -H "Content-Type: application/json" 'es地址/_cat/indices?v' |grep ka_budget_spu-

保存索引名

curl -s -XGET --user "用户名:密码" -H "Content-Type: application/json" 'es地址/_cat/indices?v' |grep ka_budget_spu- |awk '{print $3}' | sort > prd_index_name.txt

2、删除索引
删除指定索引

curl -XDELETE -u "用户名:密码" 'es地址/索引名称'

删除所有索引

curl -X DELETE 'http://localhost:9200/_all'
# 一般不建议,最好是将要删除的索引放入txt文件,通过for循环遍历删除

3、编写脚本

[root@node01 es]# cat import_pro_to_dev_index.sh
#!/bin/bash
for line in `cat prd_index_name.txt`
do
    echo -------- $line --- $uat_index_name ----------------
    echo "开始导入 $line -> $uat_index_name [mapping]"
    elasticdump --input=https://账户:密码@es地址/$line --output=https://账户:密码@es地址/$uat_index_name --type=mapping
    echo "开始导入 $line -> $uat_index_name [data]"
    # --limit=20000依据实际情况调整
    elasticdump --limit=20000 --input=https://账户:密码@es地址/$line --output=https://账户:密码@es地址/$uat_index_name --type=data
    echo "导入结束 $line -> $uat_index_name"
done

查看进度
查看test环境目前导入索引的情况

curl -s -XGET --user "xxx:xxx" -H "Content-Type: application/json" 'https://xxx/_cat/indices?v' |grep ka_budget_spu

推荐:ES 索引查询与删除

二、索引相关操作

2.1、导出索引到文件

elasticdump --input=https://账号:密码@es地址/索引名  --output=./索引名.json

举例:

elasticdump --input=https://mpc:kZfxxxj2xo@es01-prd.xxx.net.cn:9200/mpc_behavior_log  --output=./mpc_behavior_log.json

2.2、查看索引

curl -s -XGET --user "账号:密码" -H "Content-Type: application/json" 'es地址/_cat/indices?v'|grep xxx

举例:

curl -s -XGET --user "shmall:EqPexxxxxppe" -H "Content-Type: application/json" 'https://elk-uat.xxxx.net.cn:9200/_cat/indices?v'|grep recipe_dev

2.3、克隆索引

curl -XPOST --user "账号:密码" -H "Content-Type: application/json" -d '{
  "source": {
    "index": "索引名称"
  },
  "dest": {
    "index": "克隆后的索引名称"
  }
}' 'es地址/_reindex'  

举例:

curl -XPOST --user "shmall:EqPxxxxxCppe" -H "Content-Type: application/json" -d '{
  "source": {
    "index": "syj_recipe_dev"
  },
  "dest": {
    "index": "shmall_recipe_dev"
  }
}' 'https://elk-uat.xxxx.net.cn:9200/_reindex'  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

这个手刹不太灵儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值