获取所有_cat系列的操作
  1. curl http://localhost:9200/_cat
  2. =^.^=
  3. /_cat/allocation
  4. /_cat/shards
  5. /_cat/shards/{index}
  6. /_cat/master
  7. /_cat/nodes
  8. /_cat/tasks
  9. /_cat/indices
  10. /_cat/indices/{index}
  11. /_cat/segments
  12. /_cat/segments/{index}
  13. /_cat/count
  14. /_cat/count/{index}
  15. /_cat/recovery
  16. /_cat/recovery/{index}
  17. /_cat/health
  18. /_cat/pending_tasks
  19. /_cat/aliases
  20. /_cat/aliases/{alias}
  21. /_cat/thread_pool
  22. /_cat/thread_pool/{thread_pools}
  23. /_cat/plugins
  24. /_cat/fielddata
  25. /_cat/fielddata/{fields}
  26. /_cat/nodeattrs
  27. /_cat/repositories
  28. /_cat/snapshots/{repository}
  29. /_cat/templates

可以后面加一个v,让输出内容表格显示表头; pretty则让输出缩进更规范

集群状态
  1. curl -X GET "localhost:9200/_cluster/health?pretty"
节点状态
  1. curl -X GET "localhost:9200/_cat/nodes?pretty&v"
分片状态
  1. curl -X GET "localhost:9200/_cat/shards?v&pretty"
  2. #分片中如果存在未分配的分片, 可以查看未分片的原因:_cat/shards?h=index,shard,prirep,state,unassigned.reason&v
索引管理
  1. curl -X GET "localhost:9200/_cat/indices?v"
  2. #条件过滤:_cat/indices?v&health=yellow
  3. #排序:_cat/indices?v&health=yellow&s=docs.count:desc
索引详细信息
  1. curl -X GET "localhost:9200/chat_index_alias/_stats?pretty"
  2. curl -X GET "localhost:9200/_cat/count/chat_index_alias?v&pretty"
新建索引
  1. curl -X PUT "localhost:9200/my_index_name" -d '
  2. {
  3. "settings" : {
  4. "index" : {
  5. "number_of_shards" : 3,
  6. "number_of_replicas" : 2
  7. }
  8. }
  9. }'
删除索引
  1. curl -X DELETE "localhost:9200/index_name"
索引查询
  1. #分词搜索
  2. curl -X POST "localhost:9200/chat_index_alias/_search" -d '
  3. {
  4. "query": {
  5. "match": {
  6. "question": "吃饭了吗"
  7. }
  8. }
  9. }'
  1. #完全匹配搜索
  2. curl -X POST "localhost:9200/chat_index_alias/_search" -d '
  3. {
  4. "query": {
  5. "match_phrase": {
  6. "question": "你吃饭了"
  7. }
  8. }
  9. }'
别名
  1. #查看别名
  2. curl -X GET "localhost:9200/_alias/chat_index_alias?pretty"
  3. #增加别名
  4. curl -X PUT "localhost:9200/my_index/_alias/my_index_alias?pretty"
  5. #删除别名(一般纯删除别名使用的比较少,一般是别名重新绑定(删除和绑定为一个原子操作)
  6. curl -X POST 'http://localhost:9200/_aliases' -d '
  7. {
  8. "actions": [
  9. {"remove": {"index": "my_index", "alias": "my_index_alias"}}
  10. ]
  11. }'
  12. #别名重新绑定
  13. curl -XPOST 'http://localhost:9200/_aliases' -d '
  14. {
  15. "actions" : [
  16. { "remove" : { "index" : "my_index", "alias" : "my_index_alias" } },
  17. { "add" : { "index" : "my_index_v2", "alias" : "my_index_alias" } }
  18. ]
  19. }'
文档更新时间: 2021-05-19 11:11   作者:张尚