Elasticsearch(ES)常用命令

常用运维命令

一、基本命令

1.1、查看集群的健康状态

curl -u aus:123456 -XGET 'http://10.11.42.22:9200/_cat/health?v'

1.2、查看节点信息

curl -u aus:123456 -XGET 'http://10.11.42.22:9201/_cat/nodes?v'

1.3、查看索引列表

curl -u aus:123456 '10.21.17.219:9201/_cat/indices?v&s=index'

1.4、创建索引

curl -u aus:123456 -XPUT 'http://10.11.42.22:9201/test_index?pretty'

test_index 为索引名

1.5、删除索引

curl -u aus:123456 -XDELETE 'http://10.11.42.22:9201/test_index?pretty'

test_index 为索引名

1.6、关闭索引

curl -XPOST '10.21.17.219:9201/maxs_standard_20210908/_close'

maxs_standard_20210908 索引名

1.7、打开索引

curl -XPOST '10.21.17.219:9201/maxs_standard_20210908/_open'

maxs_standard_20210908 为索引名

1.8、查看集群资源使用情况(各个节点的状态,包括磁盘,heap,ram的使用情况)

curl -XGET '10.21.17.219:9201/_cat/nodes?v&h=http,version,jdk,disk.total,disk.used,disk.avail,disk.used_percent,heap.current,heap.percent,heap.max,ram.current,ram.percent,ram.max,master'

1.9、复制索引(从一个索引复制到新的索引,新索引不会继承旧的配置,可以用来改变mapping)

1.9.1、同一个集群复制

JSON

curl -H "Content-Type:application/json" -XPOST -u aus:123456 'http://10.11.42.22:9201/_reindex ' -d ' { "source":{"index":"js_20200806"}, "dest":{"index":"js_20200806_bak"} }'

1.9.2、跨集群复制

JSON

curl -H "Content-Type:application/json" -XPOST -u elastic 'http://10.11.42.22:9201/_reindex ' -d ' { "source": { "remote": { "host": "http://10.11.42.21:9200", "username": "user", "password": "pass" }, "index": "xm_20200321", "query": { "match_all": {} }, "size": 5000 }, "dest": { "index": "xm_20200321" } }'

注意:1、跨集群复制,需要在被复制的集群里设置复制集群的IP白名单。

2、索引的合并、改名都是reindex。

1.10、如何批量删除索引?

JSON

curl -H "Content-Type: application/json" -XPUT 'http://10.11.42.22:9211/_cluster/settings' -d ' { "persistent": {"action.destructive_requires_name": false} }'

重要说明:批量删除后务必要改回原状态(true),防止不必要的误删除。

1.11、修改索引查询/导出的条数限制

1)、修改已存在的索引(-u aus:123456 其中aus/123456是认证的用户名和密码)

JSON

curl -u aus:123456 -H "Content-Type:application/json" -XPUT "http://10.11.42.22:9201/_settings" -d' { "index": { "max_result_window": "50000" } }'

2)、修改以后新建的索引,需要修改模板,增加红色方框部分

1.12、如何批量删除索引?

默认情况下,Elasticsearch不允许批量删除索引,需要通过以下命令手动开启。开启后,您可以通过通配符进行批量删除操作。

JSON

curl -H "Content-Type: application/json" -XPUT 'http://10.11.42.22:9211/_cluster/settings' -d ' { "persistent": {"action.destructive_requires_name": false} }'

重要说明:批量删除后务必要改回原状态(true),防止不必要的误删除。

1.13、修改节点的分片数

1.13.1、ElasticSearch 7.x 如果没有配置 cluster.max_shards_per_node ,默认的分片数是1000;通过curl方式修改如下

JSON

curl -H "Content-Type: application/json" -XPUT 'http://10.11.42.22:9201/_cluster/settings' -d'{"persistent":{"cluster":{"max_shards_per_node":"10000"}}}'
1.13.2、通过通过配置文件elasticsearch.yml修改节点(集群)分片数量,需要重启服务。(永久生效)

JSON

cluster.max_shards_per_node: 5000
1.13.3、查看节点的分片数

JSON

curl -XGET '10.11.42.22:9201/_cluster/settings?pretty'

1.14、默认ES的单条事件的字段数上限是1000, 如果要修改index字段上限,操作如下

1.14.1、修改现有索引的的字段上线

JSON

curl -H "Content-Type: application/json" -XPUT 10.11.42.22:9205/_settings -d'{"index.mapping.total_fields.limit": 2000}'

1.14.2、修改模板,让配置一劳永逸(可以把现有的aus_template模板删除,修改aus安装包里 aus/felix/conf/elasticsearch/aus_template_7x.json,将下列配置加进去,重启AUS前台)

JSON

"settings": { "index": { "mapping" : { "total_fields" :{"limit" : "2000"} } } },

相关推荐
武子康15 小时前
大数据-237 离线数仓 - Hive 广告业务实战:ODS→DWD 事件解析、广告明细与转化分析落地
大数据·后端·apache hive
大大大大晴天17 小时前
Flink生产问题排障-Kryo serializer scala extensions are not available
大数据·flink
Elasticsearch2 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch3 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
武子康3 天前
大数据-236 离线数仓 - 会员指标验证、DataX 导出与广告业务 ODS/DWD/ADS 全流程
大数据·后端·apache hive
武子康4 天前
大数据-235 离线数仓 - 实战:Flume+HDFS+Hive 搭建 ODS/DWD/DWS/ADS 会员分析链路
大数据·后端·apache hive
DianSan_ERP4 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
够快云库4 天前
能源行业非结构化数据治理实战:从数据沼泽到智能资产
大数据·人工智能·机器学习·企业文件安全
AI周红伟4 天前
周红伟:智能体全栈构建实操:OpenClaw部署+Agent Skills+Seedance+RAG从入门到实战
大数据·人工智能·大模型·智能体
B站计算机毕业设计超人4 天前
计算机毕业设计Django+Vue.js高考推荐系统 高考可视化 大数据毕业设计(源码+LW文档+PPT+详细讲解)
大数据·vue.js·hadoop·django·毕业设计·课程设计·推荐算法