ES(6): access elasticsearch via curl
curl是一个非常实用的、用来与服务器之间传输数据的工具;支持的协议包括 (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP),curl设计为无用户交互下完成工作,linux curl功能十分强大,命令参数十分多, 可运行“man curl”命令查看
目录:
- 访问ES:_cat系列
- 访问ES:_cluster系列
- 访问ES:_nodes系列
- 访问ES:{index}系列
访问ES:_cat系列
- /_cat/allocation
- /_cat/shards
- /_cat/master
- /_cat/nodes
- /_cat/indices
- /_cat/segments
- /_cat/count
- /_cat/recovery
- /_cat/health
- /_cat/pending_tasks
- /_cat/aliases
- /_cat/thread_pool
- /_cat/plugins
- /_cat/fielddata
- /_cat/XXXX/{index}
- 示例如下图:

访问ES:_cluster系列
- /_cluster/health?pretty (查询设置集群状态, pretty=true表示格式化输出)
- /_cluster/stats?pretty (显示集群系统信息,包括CPU JVM等等)
- /_cluster/state?pretty (集群的详细信息。包括节点、分片等)
- /_cluster/pending_tasks?pretty (获取集群堆积的任务)
- /_cluster/nodes/192.168.1.1/_shutdown (关闭指定节点)
- /_cluster/nodes/_master/_shutdown (关闭主节点)
- /_shutdown?delay=10s (delay=10s表示延迟10秒关闭所有节点)
- /_cluster/nodes/_shutdown 或 /_cluster/nodes/_all/_shutdown (关闭所有节点)
- 修改集群配置, transient 表示临时的,persistent表示永久的, 如下代码
/_cluster/settings -d '{
"persistent" : {
"discovery.zen.minimum_master_nodes" : 2
}
}' 
访问ES:_nodes系列
- /_nodes/stats?pretty=true
- /_nodes/192.168.1.2/stats?pretty=true
- /_nodes/process
- /_nodes/_all/process
- /_nodes/192.168.1.2,192.168.1.3/jvm,process
- /_nodes/192.168.1.2,192.168.1.3/info/jvm,process
- /_nodes/192.168.1.2,192.168.1.3/_all
- /_nodes/hot_threads

访问ES:{index}系列
- 简单创建索引: curl -XPUT 'http://10.0.0.5:12000/test/'
- 删除索引: curl -XDELETE 'http://10.0.0.5:12000/test/'
- 设置mapping,如下示例
curl -XPUT 'http://10.0.0.5:12000/etlstasday' -d '
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
},
"mappings": {
"etlstasday": {
"properties": {
"电站名称": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"业务日期": {
"format": "yyyyMMddZ",
"type": "date"
},
"总电量": {
"type": "double"
},
"总收入(元)": {
"type": "double"
}
}
}
}
}' - mapping 字段类型参见:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html
- 插入数据,如下
curl -XPUT 'http://10.0.0.5:12000/etlstasday/etlstasday/1' -d '
{
"电站名称": "测试数据1",
"业务日期": "20160101+08:00",
"总电量": "",
"总收入(元)": ""
}' - 查询数据:curl -XGET 'http://10.0.0.5:12000/etlstasday/etlstasday/1'

- 查询某个索引下某个类型的所有记录: curl -XGET 'http://10.0.0.5:12000/etlstasday/etlstasday/_search?pretty'
- 查询某个索引下所有数据: curl -XGET 'http://10.0.0.5:12000/etlstasday/_search?pretty'
- 查询所有索引数据: curl -XGET 'http://10.0.0.5:12000/_search?pretty'
- 使用JSON参数的查询: (注意 query 和 term 关键字): $ curl localhost:9200/film/_search -d '{"query" : { "term": { "tag":"bad"}}}'
日常总结:
- 修改索引最大返回记录
PUT /索引名/_settings
{
"index" : {
"max_result_window" : 20000
}
}- 创建索引
ES(6): access elasticsearch via curl的更多相关文章
- ElasticSearch之CURL操作(有空再去整理)
https://www.cnblogs.com/jing1617/p/8060421.html ElasticSearch之CURL操作 CURL的操作 curl是利用URL语法在命令行方式下工 ...
- ES之四、Elasticsearch集群和索引常用命令
REST API用途 elasticsearch支持多种通讯,其中包括http请求响应服务,因此通过curl命令,可以发送http请求,并得到json返回内容. ES提供了很多全面的API,常用的RE ...
- Elasticsearch之curl创建索引库
关于curl的介绍,请移步 Elasticsearch学习概念之curl 启动es,请移步 Elasticsearch的前后台运行与停止(tar包方式) Elasticsearch的前后台运行与停止( ...
- Elasticsearch之CURL命令的DELETE
也可以看我写的下面的博客 Elasticsearch之curl删除 Elasticsearch之curl删除索引库 删除,某一条数据,如下 [hadoop@master elasticsearch-] ...
- Elasticsearch之CURL命令的UPDATE
对于,Elasticsearch之CURL命令的UPDATE包括局部更新和全部更新.可以去看我写的另一篇博客. Elasticsearch之更新(全部更新和局部更新) 总结: ES全部更新,使用PUT ...
- Elasticsearch之CURL命令的GET
这是个查询命令. 前期博客 Elasticsearch之CURL命令的PUT和POST对比 1. 以上是根据员工id查询. 即在任意的查询字符串中添加pretty参数,es可以得到易于我们识别的jso ...
- Elasticsearch之curl删除
扩展下, Elasticsearch之curl删除索引库 [hadoop@djt002 elasticsearch-2.4.3]$ curl -XDELETE 'http://192.168.80.2 ...
- Elasticsearch之curl创建索引库和索引时注意事项
前提, Elasticsearch之curl创建索引库 Elasticsearch之curl创建索引 注意事项 1.索引库名称必须要全部小写,不能以下划线开头,也不能包含逗号 2.如果没有明确指定索引 ...
- Elasticsearch之curl创建索引
前提,是 Elasticsearch之curl创建索引库 [hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://192.168.80.200: ...
随机推荐
- ShardedJedis的分片原理
ShardedJedisPool xml配置: <bean id="shardedJedisPool" class="redis.clients.jedis.Sha ...
- elasticsearch 路由文档到分片
路由文档到分片 当你索引一个文档,它被存储在单独一个主分片上.Elasticsearch是如何知道文档属于哪个分片的呢?当你创建一个新文档,它是如何知道是应该存储在分片1还是分片2上的呢? 进程不能是 ...
- EL表达式、 jstl标签
https://www.cnblogs.com/zhaotiancheng/p/6391894.html https://blog.csdn.net/zdwzzu2006/article/detail ...
- mongodb控制台中文乱码
问题描述: 使用命令行打开mongo,查询的结果里中文都是乱码,检查了文件编码均正常: 解决方法: 该问题是cmd字体引起的,设置cmd的字体即可,cmd的默认字体是“点阵字体”,选择其他两个均可,如 ...
- CCF 2015-03-3 节日
输出y1到y2年之间的每一年的a月份的第b个周c.感觉像是一个恶心的模拟.更像一个很恶心的小学奥赛题. 题目:http://115.28.138.223/view.page?gpid=T25 考试的时 ...
- 一个Flex 对话框的坑
最近在项目中遇到一个问题,在Flex中使用Alert.show("this is content!", "title");发现对话框可以弹出来,但是文本始终不显 ...
- Mac自带的本地服务器的使用
1. 打开终端,开启Apache: //开启apache: sudo apachectl start //重启apache: sudo apachectl restart //关闭apache: su ...
- java.io.FileNotFoundException: antlr-2.7.7.jar (系统找不到指定的路径。)[待解决]
严重: Failed to destroy the filter named [struts2] of type [org.apache.struts2.dispatcher.ng.filter.St ...
- django页面导出excel
from django.http import HttpResponse from xlwt import * from io import BytesIO def excel_export(requ ...
- shell 脚本实战笔记(8)--ssh免密码输入执行命令
前言: ssh命令, 没有指定密码的参数. 以至于在脚本中使用ssh命令的时候, 必须手动输入密码, 才能继续执行. 这样使得脚本的自动化执行变得很差, 尤其当ssh对应的机器数很多的时候, 会令人抓 ...