[转]使用curl命令操作elasticsearch And 使用http 查询ES

3 篇文章 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,让输出内容表格显示表头,举例

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/
第二:_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
}

http 查询方式

Map<String, Object> allObMap = new HashMap<String, Object>();
//查ES
StringBuffer sbUrl = new StringBuffer();
sbUrl.append("http://").append(Config.getInstance().getESSearch()).append("/")
.append(PrepareForInsertES.getIndex(getlastHourTime(startTime))).append("/")
.append(PrepareForInsertES.TYPE).append("/").append("_search");
// url 格式 "http://192.168.10.20:9200/acceptor-bilog-2017-01-11/bi/_search";
// param 格式 {\"query\": {\"term\": {\"time\": 1484096400000}}} ;
// "{ \"query\": { \"range\": { \"time\": { \"gte\" :1484096400000, \"lte\":1484096500000 } } } }";
StringBuffer sbParam = new StringBuffer();
sbParam.append("{\"query\": {\"term\": {\"time\":").append(startTime).append("}}}");
StringBuffer result = HttpUtil.submitPost(sbUrl.toString(),sbParam.toString());

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值