elasticsearch保存在一个索引中数据量太大无法查询,现在需要将索引按照天来建,查询的时候关联查询即可
有时候es集群创建了很多索引,删不掉,如果是测试环境或者初始化es集群(清空所有数据),可以直接关掉elastic进程,然后删除nodes下面的所有数据,再次启动集群即可,记录一下避免忘记
导出mapping信息放到/root/index_mapping目录下
1.导出的语句
yum install epel-release -y
yum install nodejs -y
yum install nodejs npm -y
npm install elasticdump -y
/root/node_modules/elasticdump/bin/elasticdump --ignore-errors=true --scrollTime=120m --bulk=true --input=http://10.30.138.62:9200/.kibana --output=mapping.json --type=mapping
2.创建索引的脚本如下
#!/bin/bash
# .创建今天和明天的索引
# .删除3天以前的索引
today_date=`date '+%Y%m%d'`
tomorrow_date=`date -d tomorrow +%Y%m%d`
# 需要导入索引的es集群服务器ip
es_ip=10.10.33.84
# 找到具体的index目录和index,对这个index进行处理
# start log
echo "${today_date} create index start">> /data/scripts/create_index.log
for FULLPATH in `ls /root/index_mapping/*.json`;
do
# 文件名
FILE=${FULLPATH##*/}
# 去掉文件名后缀
FILE_NAME=${FILE%%.*}
# 找到类似push:user:req的索引名称
FILE_INDEX=`echo $FILE_NAME|sed 's/_/:/g'`
FILE_INDEX_NAME=${FILE_INDEX%:*}
echo "create index ${FILE_INDEX_NAME} start" >> /data/scripts/create_index.log
/root/node_modules/elasticdump/bin/elasticdump --input=${FULLPATH} --output=http://${es_ip}:9200/${FILE_INDEX_NAME}:${today_date} --type=mapping
/root/node_modules/elasticdump/bin/elasticdump --input=${FULLPATH} --output=http://${es_ip}:9200/${FILE_INDEX_NAME}:${tomorrow_date} --type=mapping
# /root/node_modules/elasticdump/bin/elasticdump --input=${FULLPATH} --output=http://${es_ip}:9200/${FILE_INDEX_NAME}:20170905 --type=mapping
# /root/node_modules/elasticdump/bin/elasticdump --input=${FULLPATH} --output