前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ELK学习笔记之使用curl命令操作elasticsearch

ELK学习笔记之使用curl命令操作elasticsearch

作者头像
Jetpropelledsnake21
发布2019-05-17 11:52:34
1.6K0
发布2019-05-17 11:52:34
举报
文章被收录于专栏:JetpropelledSnakeJetpropelledSnake

0x00 _cat系列

_cat系列提供了一系列查询elasticsearch集群状态的接口。你可以通过执行 curl -XGET localhost:9200/_cat

1. 获取所有_cat系列的操作

代码语言:javascript
复制
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_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/plugins
/_cat/fielddata
/_cat/fielddata/{fields}

你也可以后面加一个v,让输出内容表格显示表头,举例

代码语言:javascript
复制
name       component        version type url
Prometheus analysis-mmseg   NA      j
Prometheus analysis-pinyin  NA      j
Prometheus analysis-ik      NA      j
Prometheus analysis-ik      NA      j
Prometheus analysis-smartcn 2.1.0   j
Prometheus segmentspy       NA      s    /_plugin/segmentspy/
Prometheus head             NA      s    /_plugin/head/
Prometheus bigdesk          NA      s    /_plugin/bigdesk/
Xandu      analysis-ik      NA      j
Xandu      analysis-pinyin  NA      j
Xandu      analysis-mmseg   NA      j
Xandu      analysis-smartcn 2.1.0   j
Xandu      head             NA      s    /_plugin/head/
Xandu      bigdesk          NA      s    /_plugin/bigdesk/
Onyxx      analysis-ik      NA      j
Onyxx      analysis-mmseg   NA      j
Onyxx      analysis-smartcn 2.1.0   j
Onyxx      analysis-pinyin  NA      j
Onyxx      head             NA      s    /_plugin/head/
Onyxx      bigdesk          NA      s    /_plugin/bigdesk/

0x01 _cluster系列

1、查询设置集群状态

代码语言:javascript
复制
curl -XGET localhost:9200/_cluster/health?pretty=true

pretty=true表示格式化输出 level=indices 表示显示索引状态 level=shards 表示显示分片信息

2、显示集群系统信息,包括CPU JVM等等

代码语言:javascript
复制
curl -XGET localhost:9200/_cluster/stats?pretty=true

3、 集群的详细信息。包括节点、分片等。

代码语言:javascript
复制
curl -XGET localhost:9200/_cluster/state?pretty=true

3、获取集群堆积的任务

代码语言:javascript
复制
curl -XGET localhost:9200/_cluster/pending_tasks?pretty=true 

4、修改集群配置

代码语言:javascript
复制
curl -XPUT localhost:9200/_cluster/settings -d '{
    "persistent" : {
        "discovery.zen.minimum_master_nodes" : 2
    }
}'

transient 表示临时的,persistent表示永久的

5、对shard的手动控制

代码语言:javascript
复制
curl -XPOST ‘localhost:9200/_cluster/reroute’ -d ‘xxxxxx’

对shard的手动控制,参考http://zhaoyanblog.com/archives/687.html

6、关闭节点

关闭指定192.168.1.1节点

代码语言:javascript
复制
curl -XPOST ‘http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown’
curl -XPOST ‘http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown’

7、关闭主节点

代码语言:javascript
复制
curl -XPOST ‘http://localhost:9200/_cluster/nodes/_master/_shutdown’

8、关闭整个集群

代码语言:javascript
复制
$ curl -XPOST ‘http://localhost:9200/_shutdown?delay=10s’
$ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_shutdown’
$ curl -XPOST ‘http://localhost:9200/_cluster/nodes/_all/_shutdown’

delay=10s表示延迟10秒关闭

0x02 _nodes系列

代码语言:javascript
复制
1、查询节点的状态
curl -XGET ‘http://localhost:9200/_nodes/stats?pretty=true’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2/stats?pretty=true’
curl -XGET ‘http://localhost:9200/_nodes/process’
curl -XGET ‘http://localhost:9200/_nodes/_all/process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/jvm,process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/info/jvm,process’
curl -XGET ‘http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/_all
curl -XGET ‘http://localhost:9200/_nodes/hot_threads

0x03 索引操作

1、获取索引

代码语言:javascript
复制
curl -XGET ‘http://localhost:9200/{index}/{type}/{id}’

2、索引数据

代码语言:javascript
复制
curl -XPOST ‘http://localhost:9200/{index}/{type}/{id}’ -d'{“a”:”avalue”,”b”:”bvalue”}’

3、删除索引

代码语言:javascript
复制
curl -XDELETE ‘http://localhost:9200/{index}/{type}/{id}’

4、设置mapping

代码语言:javascript
复制
curl -XPUT http://localhost:9200/{index}/{type}/_mapping -d '{
  "{type}" : {
    "properties" : {
      "date" : {
        "type" : "long"
      },
      "name" : {
        "type" : "string",
        "index" : "not_analyzed"
      },
      "status" : {
        "type" : "integer"
      },
      "type" : {
        "type" : "integer"
      }
    }
  }
}'

5、获取mapping

代码语言:javascript
复制
curl -XGET http://localhost:9200/{index}/{type}/_mapping

6、搜索

代码语言:javascript
复制
curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{
    "query" : {
        "term" : { "user" : "kimchy" } //查所有 "match_all": {}
    },
    "sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ],
    "from":0,
    "size":100
}
curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{
    "filter": {"and":{"filters":[{"term":{"age":"123"}},{"term":{"name":"张三"}}]},
    "sort" : [{ "age" : {"order" : "asc"}},{ "name" : "desc" } ],
    "from":0,
    "size":100
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-05-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 0x00 _cat系列
    • 1. 获取所有_cat系列的操作
    • 0x01 _cluster系列
      • 1、查询设置集群状态
        • 2、显示集群系统信息,包括CPU JVM等等
          • 3、 集群的详细信息。包括节点、分片等。
            • 3、获取集群堆积的任务
              • 4、修改集群配置
                • 5、对shard的手动控制
                  • 6、关闭节点
                    • 7、关闭主节点
                      • 8、关闭整个集群
                      • 0x02 _nodes系列
                      • 0x03 索引操作
                        • 1、获取索引
                          • 2、索引数据
                            • 3、删除索引
                              • 4、设置mapping
                                • 5、获取mapping
                                  • 6、搜索
                                  相关产品与服务
                                  Prometheus 监控服务
                                  Prometheus 监控服务(TencentCloud Managed Service for Prometheus,TMP)是基于开源 Prometheus 构建的高可用、全托管的服务,与腾讯云容器服务(TKE)高度集成,兼容开源生态丰富多样的应用组件,结合腾讯云可观测平台-告警管理和 Prometheus Alertmanager 能力,为您提供免搭建的高效运维能力,减少开发及运维成本。
                                  领券
                                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档