elasticsearch部分命令
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了elasticsearch部分命令相关的知识,希望对你有一定的参考价值。
一.ES相关操作
1.ES启动与关闭相关命令
su elastic # elastic用户为安装ES时创建的用户,es不能用root账号启动
cd /usr/local/elasticsearch-6.4.3/ # cd 进入es安装目录
./bin/elasticsearch -d -p pid # -p 选项可以将es进程PID记录到pid文件中,该文件可以指定 -d 后台运行
####
kill -SIGTERM PID # PID 为ES进程的PID号
2.查看ES相关信息
]$ curl -XGET http://localhost:9200/
{
"name" : "SonoxO1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "Oktq2zxmSRWcU8Fvhat2TA",
"version" : {
"number" : "6.4.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "fe40335",
"build_date" : "2018-10-30T23:17:19.084789Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
二.索引的相关操作
1.查看索引
]# curl localhost:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open logstash-nq-coupon-2018.11.14 V2ilbJErQZGW2m9rBLXeEw 5 1 182396 0 24.9mb 24.9mb
green open .kibana llTJB8gQTS-r6oGjF8fTdg 1 0 3 0 17.6kb 17.6kb
2.删除索引
]# curl -XDELETE http://localhost:9200/logstash-2018.11.14
{"acknowledged":true}
三.备份与恢复
1.创建备份仓库
}# mkdir /data/elasticsearch/bakup # 创建备份目录
}# chown elastic.elastic /data/elasticsearch/bakup # 更改目录权限
# 在elasticsearch.yml配置文件中新增一行,并重新启动ES
path.repo: /data/elasticsearch/bakup
#创建仓库
}# curl -H ‘Content-Type: application/json‘ -XPUT http://localhost:9200/_snapshot/es_bakup # es_bakup 可自定义
-d ‘{"type":"fs","settings":{"location":"/data/elasticsearch/bakup","compress": "true"}}‘
{"acknowledged":true}
注:在6.X的版本中需要添加 -H ‘Content-Type: application/json‘ 设置header,原因可参考:https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests
2.查看备份仓库
]# curl -XGET http://127.0.0.1:9200/_snapshot?pretty
{
"es_bakup" : {
"type" : "fs",
"settings" : {
"compress" : "true",
"location" : "/data/elasticsearch/bakup"
}
}
}
3.备份索引
# 备份单个索引
]# curl -H‘Content-Type: application/json‘ -XPUT http://127.0.0.1:9200/_snapshot/es_bakup/log_bak_2018.11.14 # log_bak_2018.11.14 快照名称,可自定义
-d ‘{"indices":"logstash-2018.11.14"}‘
# 备份多个索引
]# curl -H ‘Content-Type: application/json‘ -XPUT http://127.0.0.1:9200/_snapshot/es_bakup/log_bak_2018.11.14 -d ‘{"indices": "idx_1,idx_2,idx_3"}‘
# 备份所有索引
]# curl -H ‘Content-Type: application/json‘ -XPUT http://127.0.0.1:9200/_snapshot/es_bakup/bakup_all_2018.11.16
4.查看备份的索引
]# curl -XGET http://127.0.0.1:9200/_snapshot/es_bakup/log_bak_2018.11.14?pretty
{
"snapshots" : [
{
"snapshot" : "log_bak_2018.11.14",
"uuid" : "wrDpuL8aQHe7kNn5l11WqA",
"version_id" : 6040399,
"version" : "6.4.3",
"indices" : [
"logstash-2018.11.14"
],
"include_global_state" : true,
"state" : "SUCCESS",
"start_time" : "2018-11-16T07:22:49.001Z",
"start_time_in_millis" : 1542352969001,
"end_time" : "2018-11-16T07:22:49.914Z",
"end_time_in_millis" : 1542352969914,
"duration_in_millis" : 913,
"failures" : [ ],
"shards" : {
"total" : 5,
"failed" : 0,
"successful" : 5
}
}
]
}
5.恢复索引
# 恢复单个索引
]# curl -H ‘Content-Type: application/json‘ -XPOST http://127.0.0.1:9200/_snapshot/es_bakup/xp-coupon-2018.11.14/_restore -d ‘{"indices":"logstash-2018.11.14"}‘
# 恢复所有索引
]# curl -H ‘Content-Type: application/json‘ -XPOST http://127.0.0.1:9200/_snapshot/es_bakup/bakup_all_2018.11.16/_restore
# 恢复所有索引备份中的部分索引
]# curl -H ‘Content-Type: application/json‘ -XPOST http://127.0.0.1:9200/_snapshot/es_bakup/bakup_all_2018.11.16/_restore -d ‘{"indices":"idx_1,idx_2"}‘
6.其他
(1)备份目录中的文件可以打包压缩,恢复时解压至备份目录即可
(2)恢复索引时,如果该索引存在则需要先关闭该索引,恢复完成之后重新开启该索引
# 关闭某个索引
]# curl -H ‘Content-Type: application/json‘ -XPOST http://127.0.0.1:9200/logstash-2018.11.16/_close
# 打开某个索引
]# curl -H ‘Content-Type: application/json‘ -XPOST http://127.0.0.1:9200/logstash-2018.11.16/_open
以上是关于elasticsearch部分命令的主要内容,如果未能解决你的问题,请参考以下文章
ElasticSearch学习问题记录——Invalid shift value in prefixCoded bytes (is encoded value really an INT?)(代码片段