ElasticSearch 常用命令
内容覆盖:集群、节点、索引、分片、路由、性能、健康、任务、快照、ILM、模板、Pipeline。
全部采用 最常用、最高频、运维必备、业务常见场景 的命令。
结构如下:
- 集群命令(最重要)
- 节点命令
- 索引命令
- 分片命令
- 文档命令
- 搜索命令
- 监控和性能
- Task & Reindex
- 模板(index template)
- ILM 生命周期
- Snapshot & Restore
- Pipeline(ingest)
- 用户与角色(安全)
全部实战可用。
GET /_cluster/health
GET /_cluster/state
GET /_cluster/allocation/explain
GET /_cluster/settings?include_defaults=true
PUT /_cluster/settings
{
"transient": {
"cluster.routing.allocation.enable": "all"
}
}
PUT /_cluster/settings
{
"persistent": {
"indices.recovery.max_bytes_per_sec": "200mb"
}
}
PUT /_cluster/settings
{
"transient": {
"cluster.routing.allocation.exclude._name": "node-1"
}
}
GET /_cat/nodes?v
GET /_nodes/node-1
查看角色、堆、线程池、磁盘等。
GET /_nodes/stats
GET /_nodes/hot_threads
GET /_nodes/stats/jvm
GET /_cat/indices?v
PUT /my-index
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}
DELETE /my-index
POST /my-index/_close
POST /my-index/_open
GET /my-index/_settings
PUT /my-index/_settings
{
"number_of_replicas": 2
}
POST /my-index/_forcemerge?max_num_segments=1
GET /_cat/shards?v
GET /_cat/shards/my-index?v
GET /my-index/_search_shards
POST /_cluster/reroute
{
"commands": [
{
"move": {
"index": "my-index",
"shard": 0,
"from_node": "node-1",
"to_node": "node-2"
}
}
]
}
POST /my-index/_doc/1
{
"title": "hello"
}
POST /my-index/_doc
GET /my-index/_doc/1
POST /my-index/_update/1
{
"doc": { "title": "new title" }
}
DELETE /my-index/_doc/1
GET /my-index/_search?q=title:hello
POST /my-index/_search
{
"query": {
"match": { "title": "hello" }
}
}
POST /my-index/_search
{
"size": 0,
"aggs": {
"by_day": {
"date_histogram": {
"field": "timestamp",
"calendar_interval": "day"
}
}
}
}
GET /_nodes/hot_threads
GET /_nodes/stats/indices
GET /my-index/_segments
POST /my-index/_search?profile=true
POST /_reindex
{
"source": { "index": "old" },
"dest": { "index": "new" }
}
GET /_tasks?detailed=true
POST /_tasks/<task_id>/_cancel
GET /_index_template
PUT /_index_template/logs_template
{
"index_patterns": ["logs-*"],
"template": {
"settings": {
"number_of_shards": 1
}
}
}
GET /_ilm/status
GET /my-index/_ilm/explain
PUT /_ilm/policy/logs_policy
{
"policy": {
"phases": {
"hot": { "actions": { "rollover": { "max_size": "40GB" } } },
"delete": { "min_age": "30d", "actions": { "delete": {} } }
}
}
}
PUT /_snapshot/my_repo
{
"type": "fs",
"settings": { "location": "/data/backups" }
}
PUT /_snapshot/my_repo/snap-01
POST /_snapshot/my_repo/snap-01/_restore
GET /_ingest/pipeline
PUT /_ingest/pipeline/my_pipe
{
"processors": [
{ "lowercase": { "field": "title" } }
]
}
POST /_security/role/log_reader
{
"indices": [
{
"names": ["logs-*"],
"privileges": ["read"]
}
]
}
POST /_security/user/martin
{
"password": "123456",
"roles": ["log_reader"]
}