欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 会展 > Elasticsearch常用命令

Elasticsearch常用命令

2025/5/25 23:35:01 来源:https://blog.csdn.net/chunzhi128/article/details/148119834  浏览:    关键词:Elasticsearch常用命令

以下是 Elasticsearch 查看集群状态配置和索引完整操作流程的详细命令:

一、查看集群状态与配置

1. 集群健康状态
curl -X GET "localhost:9200/_cluster/health?pretty"
关键参数:
level=indices:显示每个索引的健康状态
level=shards:显示每个分片的详细状态健康状态说明:
- `green`:所有主分片和副本分片都正常。
- `yellow`:主分片正常,但至少有一个副本分片缺失。
- `red`:至少有一个主分片不可用。

输出示例:

{"cluster_name": "my_cluster","status": "green",                 # 集群状态:green/yellow/red"number_of_nodes": 3,"number_of_data_nodes": 2,"active_primary_shards": 15,"active_shards": 30,...
}
2. 集群节点信息
curl -X GET "localhost:9200/_nodes?pretty"
_nodes/stats:查看节点统计信息(CPU、内存、JVM 等)
_nodes/process:查看进程信息
3. 集群状态详细信息
curl -X GET "localhost:9200/_cluster/state?pretty"
包含分片分配、元数据、路由表等信息
4. 集群设置(动态配置)
#获取当前动态设置
curl -X GET "localhost:9200/_cluster/settings?include_defaults=true&pretty"#临时修改集群块级别(禁止写操作)
curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{"transient": {"cluster.blocks.read_only_allow_delete": true}
}
'

二、索引操作完整流程

1. 创建索引(带映射)
curl -X PUT "localhost:9200/my_index?pretty" -H 'Content-Type: application/json' -d'
{"settings": {"number_of_shards": 3,          # 主分片数量"number_of_replicas": 1         # 每个主分片的副本数},"mappings": {"properties": {"title": { "type": "text" },"user": {"type": "nested",           # 嵌套对象"properties": {"id": { "type": "keyword" },"name": { "type": "text" }}},"timestamp": { "type": "date" }}}
}
'

创建索引别名

POST /_aliases
{
"actions":[{"add": {"index": "my_index","alias": "my_alias"}   ]
}#删除别名
POST /_aliases
{
"actions":[{"remove": {"index": "my_index","alias": "my_alias"}   ]
}#更新别名POST /_aliases
{

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词