• Elasticsearch常用API


    Note:以下API基于ES 5x,6x/7x可能略有不同,具体查看官方文档

    ES常用API

    # 查看集群node
    curl "http://localhost:9200/_cat/nodes?v"
    
    # 查看索引
    curl "http://localhost:9200/_cat/indices?v"
    curl "http://localhost:9200/_cat/indices/api*?v"
    
    # 打开一个索引
    curl -s -XPOST "http://localhost:9200/my-esdata/_open?pretty"
    
    # 关闭一个索引
    curl -s -XPOST "http://localhost:9200/my-esdata/_close?pretty"
    
    # 删除一个索引
    curl -XDELETE "http://localhost:9200/my-esdata"
    
    # 设置alias
    curl -X POST "localhost:9200/_aliases?pretty" -H 'Content-Type: application/json' -d'
    {
        "actions" : [
            { "add" : { "index" : "test1", "alias" : "alias1" } }
        ]
    }'
    
    # 查看alias
    curl "localhost:9200/_cat/aliases?v"
    
    # thread
    curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{
      "index.merge.scheduler.max_thread_count" : "1",
      "index.translog.flush_threshold_size" : "512m"
    }'
    
    # 设置副本为0,可快速批量导入
    curl -XPUT "localhost:9200/_settings" -d '
     {
    "index":{
    "number_of_replicas":0
    }
    }'
    
    # 关闭合并限流,使导入更快、在导入完成后改回 merge
    curl -XPUT "localhost:9200/_cluster/settings" -d '{
        "persistent" : {
            "indices.store.throttle.type" : "none" 
        }
    }'
    
    # 更改threadpool
    curl -XPUT "localhost:9200/_cluster/settings" -d '{
        "thread_pool": {
    		"thread_pool.index.size" : "fixed"
    		"thread_pool.bulk.size" : "32"
    		"thread_pool.index.queue_size" : "800"
        }
    }'
    
    # 设置刷新频率
    PUT /_all/_settings
    {
        "index" : {
            "refresh_interval" : "60s"
        }
    }
    
    # 查看shard分布
    curl -XGET "http://localhost:9200/_cat/shards"
    
    # 手动移动分片
    curl -XPOST "http://localhost:9200/_cluster/reroute" -d '{
      "commands" : [ {
            "move" :
                {
                  "index" : "my-esdata", "shard" : 3, "from_node" : "localhost", "to_node" : "10.1.1.10"
                }
            }
      ]
    }'
    

    ES Template API

    # 集群设定
    curl -XPUT 'http://localhost:9200/_cluster/_settings?preserve_existing=true' -d '{
    "index": {
    "translog.durability" : "async",
    "translog.flush_threshold_size" : "1g",
    "translog.sync_interval" : "60s",
    "store.throttle.type": "none"
    }
    }'
    
    # 设置全局shards数量
    curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{
      "index": {
      "number_of_shards" : "4"
      }
    }'
    
    # 查看所有template基本信息
    curl -XGET "http://localhost:9200/_cat/templates?v"
    
    # 查看指定template信息
    curl -XGET "http://localhost:9200/_template/my-esdata?pretty"
    
    # 查看所有template详细信息
    curl -XGET "http://localhost:9200/_template?pretty"
    
    # 设置my-esdata-template模板
    # index name匹配为my-esdata*则使用此template
    # template中参数优先与全局参数
    curl -XPUT "http://localhost:9200/_template/my-esdata-template" -d '{
    "template" : "my-esdata*",
      "settings" : {
      "number_of_shards" : 4,
      "number_of_replicas" : 0,
      "refresh_interval" : "60s",
      "translog.durability" : "async",
      "translog.flush_threshold_size" : "1g",
      "translog.sync_interval" : "60s",
      "store.throttle.type": "none",
      "store.throttle.max_bytes_per_sec": "100m",
      "index.routing.allocation.total_shards_per_node": "1"
      }
    }'
    
    # 设置my-test模板
    # index name匹配为**则使用此template
    # template中参数优先与全局参数
    curl -XPUT "http://localhost:9200/_template/my-test-template" -d '{
    "template" : "*my-test*",
      "settings" : {
      "number_of_shards" : 4,
      "number_of_replicas" : 0,
      "refresh_interval" : "60s",
      "translog.durability" : "async",
      "translog.flush_threshold_size" : "1g",
      "translog.sync_interval" : "60s",
      "store.throttle.type": "none",
      "store.throttle.max_bytes_per_sec": "100m",
      "index.routing.allocation.total_shards_per_node": "1"
      }
    }'
    
  • 相关阅读:
    八款常用的 Python GUI 开发框架推荐
    scrapy + mogoDB 网站爬虫
    tkinter界面卡死的解决办法
    通过核心API启动单个或多个scrapy爬虫
    爬虫怎样绕过验证码?
    Python爬虫入门教程 33-100 电影评论数据抓取 scrapy
    Python开发 之 Websocket 的使用示例
    StringBuffer详解
    其实python正则表达式就这样简单明了
    ABAP和Java里的单例模式攻击
  • 原文地址:https://www.cnblogs.com/ioops/p/14313363.html
Copyright © 2020-2023  润新知