Elasticsearch常用API梳理 配置参数详解

作者:石文
时间:2018-05-24


集群ES版本:

curl -XGET http://0.0.0.0:9200/

集群配置API

curl -XPUT “http://10.128.128.132:9200/_cluster/settings” -d’ {
    “transient”: {
        “cluster.routing.allocation.enable” : “none”   #1
        “cluster.routing.allocation.disk.watermark.low” : “85%”  , #2
        “cluster.routing.allocation.disk.watermark.higt” : “90%”  , #3
         “cluster.routing.allocation.total_shards_per_node” : 3     #4
    },
    “persistent” : {
    },
}’
#1:禁用为none 启用为 all  在6.X版本中为null
#2  : 节点磁盘超过这个量则停止往这个节点分配分片,默认为85%
#3 :节点磁盘超过这个量开始迁移分片,默认为90%
#4:-1为无界

“cluster.routing.allocation.enable” : 这个参数作用的情形包括如下几个部分:初始恢复阶段,副本分配,集群再平衡,节点的增加和减少。除去以上情形,这个参数不起作用,比如新建索引时分片在节点上新增分片的操作不受影响。
索引配置API

##索引是否存在
curl -XGET "http://0.0.0.0:9200/_cat/indices/<index_pattern>?v"
##查看索引设置
curl -XGET "http://0.0.0.0:9200/<index_pattern>/_settings/?pretty"
##新建索引
curl -XPUT "http://0.0.0.0:9200/<index_pattern>?pretty" -d'{
    "settings":{
        "index":{
            "number_of_shards":3,
            "number_of_replicas":1
        }
    }
}'
##索引设置更新
curl -XPUT "http://0.0.0.0:9200/<index_pattern>/_settings?pretty" -d'{
    "number_of_replicas":1
}'
##索引重建
###重建索引前需要新建索引
curl -XPOST http://0.0.0.0:9200/_reindex?pretty -d '{
    "source":{
        "index" : "<index_old>"
    },
    "dest" : {
        "index" : "<index_new>"
    }
}'
##索引模板
###新建模板
curl -XPUT http://0.0.0.0:9200/_template/<template_name> -d '{
    "template":"<index_pattern-*>",
    "settings":{
        "number_of_shards":5,
        "number_of_replicas":1
    },
    "orider": 0,
    "aliases":{}
}'
###查看模板
curl -XGET http://0.0.0.0:9200/_template/?pretty
###删除模板
curl -XDELETE http://0.0.0.0:9200/_template/<template_name>?pretty
##索引恢复的信息
curl -XPUT "http://0.0.0.0:9200/test_index/_recovery/?human&pretty"

线程池API

在这里插入图片描述

##查看各节点线程池类型,使用情况
curl -XGET “http://hb-dev-es.jdcloud.com:80/_cat/thread_pool?v
ES对于每个nodes都有一套线程池,特定的线程池执行特定的任务
线程池共两类:fixing和scaling。其中,fixing是固定大小的线程池,默认为core的5倍,scaling是动态变化的线程池。

每套线程池包括了:

generic — 用于节点的发现等集群操作的线程池 — scaling

index — 新建和删除索引 — fixing

search — 读操作需要的操作的线程池 — fixing

get —

bulk — 批量操作的线程池 — fix

snapshot — 备份和恢复 — fixed

warmer — — scaling

refresh — refersh操作 — scaling

listener —

快照,备份API

##查看仓库和快照信息
curl -XGET “http://0.0.0.0.9200/_snapshot/?pretty”
curl -XGET “http://0.0.0.0.9200/_snapshot/test_repository/?pretty”
curl -XGET “http://0.0.0.0.9200/_snapshot/test_repository/test_backup/?pretty”       注1
##查看仓库和快照的具体详细信息
curl -XGET “http://0.0.0.0.9200/_snapshot/_status?pretty”
curl -XGET “http://0.0.0.0.9200/_snapshot/test_repository/_status?pretty”
curl -XGET “http://0.0.0.0.9200/_snapshot/test_repository/test_backup/_status?pretty”
##删除快照
curl -XDELETE “http://0.0.0.0.9200/_snapshot/test_repository/test_backup/_status?pretty”
注1: 查看快照进度
参考文献:
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html

参考资料:

https://github.com/adelean/elasticsearch-cheatsheet/blob/master/elasticsearch-cheatsheet.md

发布了67 篇原创文章 · 获赞 0 · 访问量 1784

猜你喜欢

转载自blog.csdn.net/zhinengyunwei/article/details/104042477