Elasticsearch CURL命令
1、查看集群状态
curl '10.18.37.223:9200/_cat/health?v'
绿色表示一切正常, 黄色表示所有的数据可用但是部分副本还没有分配,红色表示部分数据因为某些原因不可用
2、获取集群节点列表
curl '10.18.37.223:9200/_cat/nodes?v'
3、查看所有index
curl -X GET 'http://10.18.37.223:9200/_cat/indices?v'
4、查询所有的index包含其所有的type
curl '10.18.37.223:9200/_mapping?pretty=true'
5、查询某个index下的所有type
curl '10.18.37.223:9200/test/_mapping?pretty=true' 查询test下的所有type
6、查询某个index的所有数据
curl '10.18.37.223:9200/test/_search?pretty=true'
7、查询index下某个type类型的数据
curl '10.18.37.223:9200/test/test_topic/_search?pretty=true'
其中:根据规划,Elastic 6.x 版只允许每个 Index 包含一个 Type,7.x 版将会彻底移
除 Type, index=test type=test_topic 注意自己使用的版本
8、查询index下某个type下id确定的数据
curl '10.18.37.223:9200/test/test_topic/3525?pretty=true'
index = test type= test_topic id = 3525
9、和sql一样的查询数据
curl "10.18.37.223:9200/test/_search" -d'
{
"query": { "match_all": {} },
"_source": ["account_number", "balance"],
"sort": { "balance": { "order": "desc" },
"from": 10,
"size": 10
}
'
注:-d之后的内容使用回车输入,不能使用换行符,es不能识别
query:里面为查询条件此处为全部,不做限制,_source:为要显示的那些字段
sort:为排序字段 from为从第10条开始,size:取10条
除此之外还有:布尔匹配,or匹配。包含匹配。范围匹配。更多查询请去官网查看:
官网查询API地址
10、创建索引(index)
curl -X PUT '10.18.37.223:9200/test?pretty'
OR
curl -X PUT '10.18.37.223:9200/test'
创建一个名为test的索引
注:索引只能是小写,不能以下划线开头,也不能包含逗号
如果没有明确指定索引数据的ID,那么es会自动生成一个随机的ID,需要使用POST参数
11、往index里面插入数据
curl -X PUT '10.18.37.223:9200/test/test_zhang/1?pretty' -d '
{"name":"tom","age":18}'
往es中插入index=test,type=test_zhang id = 1的数据为
{"name":"tom","age":18}的数据。
-X POST也即可
12、修改数据
curl -X PUT '10.18.37.223:9200/test/test_zhang/1?pretty' -d '{"name":"pete","age":20}'
注:修改 index = test type=test_zhang id = 1 数据: {"name":"tom","age":18}
为{"name":"pete","age":20} 成功之后执行查看数据命令可看到最新数据,且
version 会增加一个版本
13、更新数据同时新增数据,在一个index,type中
curl -X POST '10.18.37.223:9200/test/test_zhang/1/_update?pretty' -d '{"doc":{"name":"Alice","age":18,"addr":"beijing"}}'
注:修改了名字,年龄,同时新增了字段addr=beijing
14、利用script更新数据
curl -X POST '10.18.37.223:9200/test/test_zhang/1/_update?pretty' -d '{"script": "ctx._source.age += 5"}'
注:将年龄加5
从ES 1.4.3以后, inline script默认是被禁止的
要打开, 需要在config/elasticsearch.yml中添加如下配置:
script.inline:true
script.indexed:true 然后重启 (如果是集群模式:需要每个节点都添加 然后重启)
15、删除记录
curl -X DELETE '10.18.37.223:9200/test/test_zhang/1'
注:删除index = test type = test_zhang id = 1 的数据
16、删除index
curl -X DELETE '10.18.37.223:9200/test'
删除index=test的数据
17、批量操作
curl -X POST '10.18.37.223:9200/test/test_zhang/_bulk?pretty' -d '
{"index":{"_id":"2"}}
{"name":"zhangsan","age":12}
{"index":{"_id":"3"}}
{"name":"lisi"}
'
注:在index = test type = test_zhang下
新增id= 2 和 id=3 的两条数据
curl -X POST '10.18.37.223:9200/test/test_zhang/_bulk?pretty' -d '
{"update":{"_id":"2"}}
{"doc":{"name":"wangwu"}}
{"delete":{"_id":"3"}}'
注: 修改id = 2 的数据 并且同时删除掉id=3的数据
在index = test type = test_zhang下
18、根据条件删除
curl -X POST "10.18.37.223:9200/test/_delete_by_query" -d'
{
"query": {
"match": {
"name": "pete"
}
}
}'
使用es的_delete_by_query,此插件在es2.0版本以后被移除掉,要使用此命令。
需要自己安装_delete_by_query插件:
在es安装目录下。bin目录下,执行:
./plugin install delete-by-query 安装插件
如果是集群模式,则每个节点都需要安装然后重启
Elasticsearch CURL命令的更多相关文章
- 使用curl命令操作elasticsearch
使用curl命令操作elasticsearch 大岩不灿 发表于 2015年4月25日 浏览 7,426 次 第一:_cat系列_cat系列提供了一系列查询elasticsearch集群状态的接口.你 ...
- 学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch
使用Elasticsearch不免要提到curl工具,curl是利用URL语法在命令行方式下工作的开源文件传输工具.官网地址:https://curl.haxx.se/ 因为elasticsearch ...
- Elasticsearch之CURL命令的UPDATE
对于,Elasticsearch之CURL命令的UPDATE包括局部更新和全部更新.可以去看我写的另一篇博客. Elasticsearch之更新(全部更新和局部更新) 总结: ES全部更新,使用PUT ...
- Elasticsearch之CURL命令的GET
这是个查询命令. 前期博客 Elasticsearch之CURL命令的PUT和POST对比 1. 以上是根据员工id查询. 即在任意的查询字符串中添加pretty参数,es可以得到易于我们识别的jso ...
- elasticsearch(3) curl命令
curl 操作http的get/post/put/delete CURL 命令参数-a/--append 上传文件时,附加到目标文件-A/--user-agent <string> 设置用 ...
- windows curl命令详解
概述 Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令. 软件下载 下载地址:https://cur ...
- windows(64位)下使用curl命令
Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令. 工具下载 在官网处下载工具包:http://cu ...
- windows curl 命令
windows 64 curl 命令的使用 https://blog.csdn.net/qq_27093465/article/details/53545693 curl命令可以通过命令行的方式,执行 ...
- windows curl命令
一.概述 Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令 二.下载 下载地址:https://cu ...
随机推荐
- Redhat 6.3上安装OpenSSL
需求是:在Redhat 6.3上安装OpenSSL 1.1.0b. 一开始试图去搜索rpm,没有对应版本.https://pkgs.org/http://rpmfind.net/放弃! 只能通过编译源 ...
- gevent模块学习(四)
gevent.spawn会对传入的子任务集合进行调度,gevent.joinall 方法会阻塞当前程序,除非所有的greenlet都执行完毕,才会退出程序 公有方法 gevent.spawn(cls, ...
- angular学习3
#创建了一个component 查看angular.json文件: "prefix":"app", 在所创建的component的selector上添加了app ...
- python3安装docx模块出现Import Error: No module named 'exceptions'
x首先 pip3 install docx 显示已经安装,但是 No module named 'exceptions' 网上查的资料命令行下载的docx安装包还没有完全兼容python3,第三方库应 ...
- Android View的滑动
Android View的滑动 文章目录 Android View的滑动 一.实现移动 1.1 layout() 1.2 设置位置偏移量 1.3 改变布局参数 1.4 动画 1.5 ScrollTo以 ...
- AI 帮助涂鸦
这个小工具挺有意思,可以在涂鸦的同时自动猜测你要画什么,并自动完成. https://quickdraw.withgoogle.com/
- ES(Elasticsearch)
基本概念 Elasticsearch是一个实时分布式搜索和分析引擎 支持: 全文搜索 结构化搜索 分析 可以这样进行描述: 分布式的实时文件存储,每个字段都被索引并可被搜索 分布式的实时分析搜索引擎 ...
- 【js高程学习笔记】Object类型
创建一组Object的实例的方式有两种: 方法一: var person = new Object(); person.name = '团子'; person.race = '猫'; person.s ...
- OO第四次作业总结
一:测试与正确性论证的效果差异 首先,测试和正确性论证都是对程序的可靠与否,是否有误进行测试,从整体上来看,测试多偏向于实践,而正确性论证则大多偏向于理论. 测试:测试首先是构造一组测试样例,之后将程 ...
- javascript20150124
表达式与运算符 表达式 与数学中的定义相似,表达式是指具有一定的值的.用运算符把常数和变量连接起来的代数式.一个表达式可以只包含一个常数或一个变量.运算符可以是四则运算符.关系运算符.位运算符.逻辑运 ...