• ElasticSearch常用命令


    状态查询

    • 获取所有_cat系列的操作
    curl http://localhost:9200/_cat
    =^.^=
    /_cat/allocation
    /_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"
    ip             heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
    192.168.58.101           69          99  71   12.67   12.25    11.71 mdi       -      node-101
    192.168.58.103           23          99  70   14.64   13.45    12.68 mdi       -      node-103
    192.168.58.105           60          97  69   11.17   10.96    10.88 mdi       *      node-105
    • 节点详细信息
    curl -X GET "localhost:9200/_nodes/stats/http?pretty"

    后面的http是查看的属性,另外还有indices, fs, http, jvm, os, process, thread_pool, discovery等,支持组合(如indices,fs,http

    分片状态

    • 分片
    curl -X GET "localhost:9200/_cat/shards?v&pretty"
    index                           shard prirep state    docs store ip          node
    tenmao_index_153915944934 1     p      STARTED 39931 4.1mb 172.17.0.14 35S66p1
    tenmao_index_153915944934 1     r      STARTED 39931   4mb 172.17.0.3  DPKsmMN
    tenmao_index_153915944934 0     p      STARTED 39634   4mb 172.17.0.2  PE8QHxz
    tenmao_index_153915944934 0     r      STARTED 39634   4mb 172.17.0.3  DPKsmMN

    分片中如果存在未分配的分片, 可以查看未分片的原因:_cat/shards?h=index,shard,prirep,state,unassigned.reason&v

    索引

    索引管理

    • 索引列表
    curl -X GET "localhost:9200/_cat/indices?v"
    health status index                           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    green  open   tenmao_index_153915944934 Z6BV1VaMRc-tC-7IucJE2w   5   1     198444            0     40.9mb         20.4mb

    条件过滤:_cat/indices?v&health=yellow

    排序:_cat/indices?v&health=yellow&s=docs.count:desc

    • 索引详细信息
    curl -X GET "localhost:9200/chat_index_alias/_stats?pretty"
    • 数据量
    curl -X GET "localhost:9200/_cat/count/chat_index_alias?v&pretty"
    • 新建索引
    curl -X PUT "localhost:9200/my_index" -d '
    {
        "settings" : {
            "index" : {
                "number_of_shards" : 3, 
                "number_of_replicas" : 2 
            }
        }
    }'
    • 删除索引
    curl -X DELETE "localhost:9200/tenmao_index"
    
    curl -X DELETE "localhost:9200/tenmao_index_1504520299944"

    索引使用

    • 分词搜索
    curl -X POST "localhost:9200/chat_index_alias/_search" -d '
    {
      "query": {
        "match": {
          "question": "吃饭了吗"
        }
      }
    }'
    • 完全匹配搜索
    curl -X POST "localhost:9200/chat_index_alias/_search" -d '
    {
      "query": {
        "match_phrase": {
          "question": "你吃饭了"
        }
      }
    }'

    别名

    • 查看别名
    curl -X GET "localhost:9200/_alias/chat_index_alias?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"}}
        ]
    }'

    一般纯删除别名使用的比较少,一般是别名重新绑定(删除和绑定为一个原子操作)

    • 别名重新绑定
    curl -XPOST 'http://localhost:9200/_aliases' -d '
    {
        "actions" : [
            { "remove" : { "index" : "my_index", "alias" : "my_index_alias" } },
            { "add" : { "index" : "my_index_v2", "alias" : "my_index_alias" } }
        ]
    }'
  • 相关阅读:
    @MapperScan 注解和 mybatis.mapper-locations 配置两者缺一不可
    com.mysql.cj.jdbc.Driver和com.mysql.jdbc.Driver的区别
    定时任务框架Quartz-(一)Quartz入门与Demo搭建
    js分页的实现代码
    圣杯布局中对left盒子设置负内边距-100%的一点解释
    前端小知识--为什么你写的height:100%不起作用?
    CSS:实现垂直居中的常用方法
    [jdk源码阅读系列]Java中System.arraycopy()的用法
    [jdk源码阅读系列]overflow-conscious code
    省选?
  • 原文地址:https://www.cnblogs.com/weifeng1463/p/13415409.html
Copyright © 2020-2023  润新知