美文网首页
ElasticSearch常用命令收集

ElasticSearch常用命令收集

作者: singleZhang2010 | 来源:发表于2021-02-19 15:11 被阅读0次

    收集一些ElasticSearch日常使用到的命令,这样可以不用经常去搜了:

    各类状态信息

    • _cat系列的操作
    curl http://localhost:9200/_cat
    
    /_cat/allocation?pretty&v
    /_cat/shards
    /_cat/shards/{index}
    /_cat/master
    /_cat/nodes
    /_cat/tasks
    /_cat/indices
    /_cat/indices/{index}
    /_cat/segments
    /_cat/segments/{index}
    /_cat/count
    /_cat/count/{index}
    /_cat/recovery
    /_cat/recovery/{index}
    /_cat/health
    /_cat/pending_tasks
    /_cat/aliases
    /_cat/aliases/{alias}
    /_cat/thread_pool
    /_cat/thread_pool/{thread_pools}
    /_cat/plugins
    /_cat/fielddata
    /_cat/fielddata/{fields}
    /_cat/nodeattrs
    /_cat/repositories
    /_cat/snapshots/{repository}
    /_cat/templates
    

    ※ v,让输出内容表格显示表头;
    ※ pretty则让输出缩进更规范

    • 集群状态
    curl -X GET "localhost:9200/_cluster/health?pretty"
    
    • 节点简要信息
    curl -X GET "localhost:9200/_cat/nodes?pretty&v"
    
    • 节点详细信息
    curl -X GET "localhost:9200/_nodes/stats/http?pretty"
    

    ※ http这里可以添加的属性还有indices, fs, http, jvm, os, process, thread_pool, discovery等。

    • 分片状态
    curl -X GET "localhost:9200/_cat/shards?v&pretty"
    

    索引管理

    • 索引列表
    #health 过滤条件,s 排序规则
    curl -X GET "localhost:9200/_cat/indices?v&health=yellow&s=docs.count:desc"
    
    • 新建索引
    curl -X PUT "localhost:9200/my_index" -d 
    '{
        "settings" : {
            "index" : {
                "number_of_shards" : 3, 
                "number_of_replicas" : 2 
            }
        }
    }'
    
    • 删除索引
    curl -X DELETE "localhost:9200/my_index"
    
    • 分词搜索
    curl -X POST "localhost:9200/my_index/_search" -d 
    '{
      "query": {
        "match": {
          "question": "地址"
        }
      }
    }'
    
    • 完全匹配搜索
    curl -X POST "localhost:9200/my_index/_search" -d 
    '{
      "query": {
        "match_phrase": {
          "question": "详细地址"
        }
      }
    }'
    
    • 别名
    # 查看
    curl -X GET "localhost:9200/_alias/my_index?pretty"
    
    # 增加
    curl -X PUT "localhost:9200/my_index/_alias/my_index_alias?pretty"
    
    # 删除
    curl -X POST 'http://localhost:9200/_aliases' -d 
    '{
        "actions": [
            {"remove": {"index": "my_index", "alias": "my_index_alias"}}
        ]
    }'
    

    // TODO 以后用到再继续补充

    相关文章

      网友评论

          本文标题:ElasticSearch常用命令收集

          本文链接:https://www.haomeiwen.com/subject/xxjaxltx.html