首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Elasticsearch CURL命令

Elasticsearch CURL命令

作者头像
用户7657330
发布2021-12-07 17:21:25
1.3K0
发布2021-12-07 17:21:25
举报
文章被收录于专栏:程序生涯程序生涯

1、查看集群状态

curl "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_cat/health?v"

提示:绿色表示一切正常, 黄色表示所有的数据可用但是部分副本还没有分配,红色表示部分数据因为某些原因不可用

2、获取集群节点列表

curl "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_cat/nodes?v"

3、查看所有index

curl -XGET "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_cat/indices?v"

4、查询所有的index包含其所有的type

curl -XGET "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_mapping?pretty=true"

5、查询某个index下的所有type

curl -XGET "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121:9200/_mapping?pretty=true"

6、查询某个index的所有数据

curl -XGET "http://elastic:YfCRYaerPug8B35YUEob@47.119.138.121: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 安装插件 如果是集群模式,则每个节点都需要安装然后重启

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-09-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、查看集群状态
  • 2、获取集群节点列表
  • 3、查看所有index
  • 4、查询所有的index包含其所有的type
  • 5、查询某个index下的所有type
  • 6、查询某个index的所有数据
  • 7、查询index下某个type类型的数据
  • 8、查询index下某个type下id确定的数据
  • 9、和sql一样的查询数据
  • 10、创建索引(index)
  • 11、往index里面插入数据
  • 12、修改数据
  • 13、更新数据同时新增数据,在一个index,type中
  • 14、利用script更新数据
  • 15、删除记录
  • 16、删除index
  • 17、批量操作
  • 18、根据条件删除
相关产品与服务
Elasticsearch Service
腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档