本文共 4311 字,大约阅读时间需要 14 分钟。
这篇文章主要介绍了Elasticsearch 5.x的基本命令,包括ES集群相关命令、索引CRUD命令和文档CRUD命令。由于Query查询命令较为复杂,故未包含在此。
_cat 命令_cat 命令系列用于查询Elasticsearch集群的状态信息。以下是常用命令的示例:
查看单节点的 shard 分配情况
curl -X GET "localhost:9200/_cat/allocation?v&pretty"
查看各 shard 的详细情况
curl -X GET "localhost:9200/_cat/shards?v&pretty"
查看指定分片的详细情况
curl -X GET "localhost:9200/_cat/shards/{index}?v&pretty"查看 master 节点信息
curl -X GET "localhost:9200/_cat/master?v&pretty"
查看所有节点信息
curl -X GET "localhost:9200/_cat/nodes?v&pretty"
查看集群中所有 index 的详细信息
curl -X GET "localhost:9200/_cat/indices?v&pretty"
查看指定 index 的详细信息
curl -X GET "localhost:9200/_cat/indices/{index}?v&pretty"查看各 index 的 segment 详细信息
curl -X GET "localhost:9200/_cat/segments?v&pretty"
查看指定 index 的 segment 详细信息
curl -X GET "localhost:9200/_cat/segments/{index}?v&pretty"查看当前集群的文档总数
curl -X GET "localhost:9200/_cat/count?v&pretty"
查看指定索引的文档总数
curl -X GET "localhost:9200/_cat/count/{index}?v&pretty"查看集群内每个 shard 的 recovery 过程和调整 replica
curl -X GET "localhost:9200/_cat/recovery?v&pretty"
查看指定索引 shard 的 recovery 过程
curl -X GET "localhost:9200/_cat/recovery/{index}?v&pretty"查看集群当前状态(红、黄、绿)
curl -X GET "localhost:9200/_cat/health?v&pretty"
查看当前集群的 pending task
curl -X GET "localhost:9200/_cat/pending_tasks?v&pretty"
查看集群中所有 alias 信息
curl -X GET "localhost:9200/_cat/aliases?v&pretty"
查看指定索引的 alias 信息
curl -X GET "localhost:9200/_cat/aliases/{alias}?v&pretty"查看集群各节点内部的 threadpool 统计信息
curl -X GET "localhost:9200/_cat/thread_pool?v&pretty"
查看集群各节点上的 plugin 信息
curl -X GET "localhost:9200/_cat/plugins?v&pretty"
查看当前集群各节点的 fielddata 内存使用情况
curl -X GET "localhost:9200/_cat/fielddata?v&pretty"
查看指定字段的内存使用情况
curl -X GET "localhost:9200/_cat/fielddata/{fields}?v&pretty"查看单节点的自定义属性
curl -X GET "localhost:9200/_cat/nodeattrs?v&pretty"
输出集群中注册的快照存储库
curl -X GET "localhost:9200/_cat/repositories?v&pretty"
输出当前存在的模板信息
curl -X GET "localhost:9200/_cat/templates?v&pretty"
注意:上述命令均支持
?v参数,会输出表格形式的内容;支持?pretty参数,会格式化输出更具可读性。
curl -X GET "localhost:9200/_cat/nodes?v&pretty"
输出示例:
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name172.18.0.4 52 97 6 0.02 0.11 0.28 mdi - es7_021172.18.0.5 57 97 6 0.02 0.11 0.28 mdi * es7_01
curl -X GET "localhost:9200/_cat/shards?v&pretty"
输出示例:
index shard prirep state docs store ip nodemonitoring-es-7-2019.08.30 0 p STARTED 21333 11.8mb 172.18.0.5kibana_1 0 r STARTED 4 22.4kb 172.18.0.5
查看健康状态为 yellow 的索引
curl -X GET "localhost:9200/_cat/indices?v&health=yellow"
根据文档数量排序
curl -X GET "localhost:9200/_cat/indices?v&health=yellow&s=docs.count:desc"
查看索引详细信息
curl -X GET "localhost:9200/my_index/_stats?pretty"
curl -X PUT "localhost:9200/student" -H "Content-Type: application/json" -d { "settings": { "number_of_shards": 3, "number_of_replicas": 1 }, "mappings": { "properties": { "name": { "type": "text" }, "country": { "type": "keyword" }, "age": { "type": "integer" }, "date": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } }} curl -X DELETE "localhost:9200/index-name"
使用 PUT 方法
curl -X PUT "localhost:9200/student/_doc/1" -H "Content-Type: application/json" -d { "name": "徐小小", "country": "杭州", "age": "3", "date": "2019-09-04"}使用 POST 方法(不指定 ID)
curl -X POST "localhost:9200/student/_doc" -H "Content-Type: application/json" -d { "name": "徐小小", "country": "杭州", "age": "3", "date": "2019-09-04"}使用 POST 方法(指定 ID)
curl -X POST "localhost:9200/student/_doc/88" -H "Content-Type: application/json" -d { "name": "徐小小", "country": "杭州", "age": "3", "date": "2019-09-04"}curl -X GET "localhost:9200/student/_doc/1"
使用 POST 方法
curl -X POST "localhost:9200/student/_update/1" -H "Content-Type: application/json" -d { "doc": { "age": 5 }}curl -X DELETE "localhost:9200/student/_doc/1"
转载地址:http://ftffz.baihongyu.com/