美文网首页
ES普通模式下基础操作

ES普通模式下基础操作

作者: bigdata张凯翔 | 来源:发表于2020-11-02 22:45 被阅读0次

    查询某台机器的状态

    curl http://localhost:8200/_cluster/nodes/10.0.2.226?pretty

    使用通配符查询

    curl http://localhost:8200/_cluster/nodes/10.0.2.2*?pretty

    •获取集群健康状态

    curl -XGET 'http://192.168.10.84:9200/_cluster/health?pretty'

    获取集群全局状态

    curl -XGET 'http://192.168.10.84:9200/_cluster/stats?pretty'

    解释集群分片

    curl -XGET 'http://192.168.10.84:9200/_cluster/allocation/explain?pretty' -H 'Content-Type:application/json' -d '{"index""indexname","shard"number of shards,"primary"true}'

    curl -XGET 'http://192.168.10.84:9200/_cluster/allocation/explain?pretty' -H 'Content-Type:application/json' -d '{"index""indexname","shard"number of shards,"primary"true}'
    •查询_cat接口支持的所有命令列表
    curl -XGET 'http://192.168.10.84:9200/_cat/'
    •查询集群健康状态
    curl -XGET 'http://192.168.10.84:9200/_cat/health?v'

    查询索引列表【生产环境会有多个索引】

    curl -XGET 'http://192.168.10.84:9200/_cat/indices?v'
    •查询集群实例列表
    curl -XGET 'http://192.168.10.84:9200/_cat/nodes?v'
    •查询nodes接口的帮助信息
    curl -XGET 'http://192.168.10.84:9200/_cat/nodes?help'
    •查询nodes指定参数列的值
    curl -XGET 'http://192.168.10.84:9200/_cat/nodes?v&h=http,dt,du,dup,hm,hc,hp,fdm,fdc,fdp,cpu'
    •查询集群线程池使用情况
    curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool?v'
    •查询集群bulk线程数
    curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool/bulk?v'
    curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool/bulk?v&h=node_name,active,queue,rejected,c'

    [zkx@node04 ~]$ curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool/bulk?v'
    node_name name active queue rejected
    [zkx@node04 ~]$ curl -XGET 'http://192.168.10.84:9200/_cat/thread_pool/bulk?v&h=node_name,active,queue,rejected,c'
    node_name active queue rejected c
    

    •查询主master实例
    curl -XGET 'http://192.168.10.84:9200/_cat/master?v'

    [zkx@node04 ~]$ curl -XGET 'http://192.168.10.84:9200/_cat/master?v'
    id                     host          ip            node
    6lVL28gETga0UcaL1Aki6g 192.168.10.86 192.168.10.86 node06
    

    •查询每个实例的分片个数
    curl -XGET 'http://192.168.10.84:9200/_cat/allocation?v'

    •查看分片未分配的原因
    curl -XGET 'http://192.168.10.84:9200/_cat/shards?v&h=index,shard,prirep,state,ur'

    [zkx@node04 ~]$ curl -XGET 'http://192.168.10.84:9200/_cat/shards?v&h=index,shard,prirep,state,ur'
    index   shard prirep state   ur
    .kibana 0     p      STARTED
    .kibana 0     r      STARTED
    index1  1     r      STARTED
    index1  1     p      STARTED
    index1  3     r      STARTED
    index1  3     p      STARTED
    index1  2     p      STARTED
    index1  2     r      STARTED
    index1  4     p      STARTED
    index1  4     r      STARTED
    index1  0     r      STARTED
    index1  0     p      STARTED
    

    _nodes命令
    •查询所有EsMaster实例的jvm参数
    curl -XGET 'http://192.168.10.84:9200/_nodes/EsMaster*/stats/jvm?pretty'

    •查询指定EsMaster实例的jvm参数
    curl -XGET 'http://192.168.10.84:9200/_nodes/EsMaster@ip/stats/jvm?pretty'
    •查询所有EsNode实例的jvm参数
    curl -XGET 'http://192.168.10.84:9200/_nodes/EsNode*/stats/jvm?pretty'
    •查询指定EsNode1实例的jvm参数
    curl -XGET 'http://192.168.10.84:9200/_nodes/EsNode1@ip/stats/jvm?pretty'
    curl -XGET 'http://192.168.10.84:9200/_nodes/EsNode1@192.168.10.84/stats/jvm?pretty'
    索引操作
    •新建索引,并设置副本数
    curl -XPUT 'http://192.168.10.84:9200/website?pretty' -H 'Content-Type: application/json' -d' {"settings" : {"number_of_shards" : 3,"number_of_replicas" : 1} }'

    例如:curl -XPUT 'http://10.131.112.121:24100/website?pretty' -H 'Content-Type: application/json' -d' {"settings" : {"number_of_shards" : 3,"number_of_replicas" : 1} }'

    •查询指定索引mappings
    curl -XGET 'http://192.168.10.84:9200/website/_mappings?pretty'
    •查询指定索引settings
    curl -XGET 'http://192.168.10.84:9200/website/_settings?pretty'
    •写入数据
    curl -XPOST 'http://192.168.10.84:9200/website/blog/123?pretty' -H 'Content-Type: application/json' -d' {"title": "My first blog entry", "text": "Just trying this out...","date": "2014/01/01"}'
    •关闭索引
    curl -XPOST 'http://192.168.10.84:9200/website/_close?pretty'
    •打开索引
    curl -XPOST 'http://192.168.10.84:9200/website/_open?pretty'
    •删除索引
    curl -XDELETE 'http://192.168.10.84:9200/indexName?pretty'
    •修改索引刷新时间
    curl -XPUT 'http://192.168.10.84:9200/website/_settings?pretty' -H 'Content-Type: application/json' -d'{"refresh_interval" : "time (unit: seconds)"}'
    •清理Elasticsearch查询缓存
    curl -XPOST 'http://192.168.10.84:9200/_cache/clear?pretty'
    •设置索引副本
    curl -XPUT 'http://192.168.10.84:9200/indexName/_settings?pretty' -H 'Content-Type: application/json' -d'{"number_of_replicas" : number of replicas}'
    •执行refresh,将内存数据刷新到磁盘缓存
    curl -XPOST 'http://192.168.10.84:9200/_refresh?pretty'
    •执行flush,将磁盘缓存刷新到文件系统
    curl -XPOST 'http://192.168.10.84:9200/_flush?pretty'
    •执行synced flush,将磁盘缓存刷新到文件系统,并生成相同的syncid
    curl -XPOST 'http://192.168.10.84:9200/indexName/_flush/synced?pretty'
    •执行段合并
    curl -XPOST 'http://192.168.10.84:9200/indexName/_forcemerge?only_expunge_deletes=false&max_num_segments=1&flush=true&pretty'
    •设置索引在每个实例上的分片个数
    curl -XPUT 'http://192.168.10.84:9200/indexName/_settings?pretty' -H 'Content-Type:application/json' -d '{"index.routing.allocation.total_shards_per_node":"number of shards"}'
    •检查文档是否存在
    curl -i -HEAD 'http://192.168.10.84:9200/indexName/type/indexID?pretty'
    •查询索引全部数据【OK】
    curl -XGET 'http://192.168.10.84:9200/website/_search?pretty'
    •查询指定ID数据【OK】
    curl -XGET 'http://192.168.10.84:9200/indexName/type/indexID?pretty'
    •查询文档的一部分数据
    curl -XGET 'http://192.168.10.84:9200/indexName/type/indexID?_source=documentAttributeName1,documentAttribute2&pretty'
    •删除文档
    curl -XDELETE 'http://192.168.10.84:9200/indexName/type/indexID?pretty'

    相关文章

      网友评论

          本文标题:ES普通模式下基础操作

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