美文网首页工作生活
ES 常用查询命令汇总

ES 常用查询命令汇总

作者: aben328 | 来源:发表于2019-07-03 14:30 被阅读0次

一:_cat系列

_cat系列提供了一系列查询elasticsearch集群状态的接口。你可以通过执行

curl -XGET localhost:9200/_cat

获取所有_cat系列的操作

/_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,让输出内容表格显示表头,举例

二:_cluster系列

1、查询设置集群状态

curl -XGET localhost:9200/_cluster/health?pretty=true

pretty=true表示格式化输出

level=indices 表示显示索引状态

level=shards 表示显示分片信息

2、curl -XGET localhost:9200/_cluster/stats?pretty=true

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

3、curl -XGET localhost:9200/_cluster/state?pretty=true

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

3、curl -XGET localhost:9200/_cluster/pending_tasks?pretty=true

获取集群堆积的任务

3、修改集群配置

举例:

curl -XPUT localhost:9200/_cluster/settings -d ‘{

    “persistent” : {

        “discovery.zen.minimum_master_nodes” : 2

    }

}’

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

4、curl -XPOST ‘localhost:9200/_cluster/reroute’ -d ‘xxxxxx’

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

5、关闭节点

关闭指定192.168.1.1节点

curl -XPOST ‘http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown’

curl -XPOST ‘http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown’

关闭主节点

curl -XPOST ‘http://localhost:9200/_cluster/nodes/_master/_shutdown’

关闭整个集群

$ 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秒关闭

三:_nodes系列

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

第四:索引操作

1、获取索引

curl -XGET ‘http://localhost:9200/{index}/{type}/{id}’

2、索引数据

curl -XPOST ‘http://localhost:9200/{index}/{type}/{id}’ -d’{“a”:”avalue”,”b”:”bvalue”}’

3、删除索引

curl -XDELETE ‘http://localhost:9200/{index}/{type}/{id}’

4、设置mapping

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

curl -XGET http://localhost:9200/{index}/{type}/_mapping

6、搜索

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

}

相关文章

  • ES 常用查询命令汇总

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

  • Linux系统运维常见的150个命令

    亮神对Linux系统常见的常用的150个命令汇总。 线上查询及帮助命令(2个) man:查看命令帮助,命令的词典,...

  • 数据库如何查询

    数据库查询知识汇总 gy_user具体查询实际操作 1.常用的命令和代表的意思 2.常用命令实际操作 对函数过滤只...

  • [13]ES常用查询命令

    本文集主要是总结自己在项目中使用ES 的经验教训,包括各种实战和调优。 本文主要包含es 相关的各种查询命令,在进...

  • SQL常用命令书目录

    SQL常用命令之单表查询 SQL常用命令之多表查询 SQL常用命令之模糊查找 SQL常用命令之空值查询 SQL常用...

  • Linux 常用命令汇总

    Linux 常用命令0Linux 常用命令1--ls命令 参考 Linux 常用命令汇总

  • mysql使用笔记

    mysql常用命令汇总

  • 其他

    Git常用命令mac常用命令Linux 常用命令汇总Linux 常用命令0Linux 常用命令1--ls命令

  • ES | ES 查询命令

  • Elastic检索技巧总结

    常用的检索类型 在mysql中,我们常用的查询 可能就是 精准查询 模糊查询 范围查询 等等,那么在es中,有哪...

网友评论

    本文标题:ES 常用查询命令汇总

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