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命令的更多相关文章

  1. 使用curl命令操作elasticsearch

    使用curl命令操作elasticsearch 大岩不灿 发表于 2015年4月25日 浏览 7,426 次 第一:_cat系列_cat系列提供了一系列查询elasticsearch集群状态的接口.你 ...

  2. 学习用Node.js和Elasticsearch构建搜索引擎(3):使用curl命令操作elasticsearch

    使用Elasticsearch不免要提到curl工具,curl是利用URL语法在命令行方式下工作的开源文件传输工具.官网地址:https://curl.haxx.se/ 因为elasticsearch ...

  3. Elasticsearch之CURL命令的UPDATE

    对于,Elasticsearch之CURL命令的UPDATE包括局部更新和全部更新.可以去看我写的另一篇博客. Elasticsearch之更新(全部更新和局部更新) 总结: ES全部更新,使用PUT ...

  4. Elasticsearch之CURL命令的GET

    这是个查询命令. 前期博客 Elasticsearch之CURL命令的PUT和POST对比 1. 以上是根据员工id查询. 即在任意的查询字符串中添加pretty参数,es可以得到易于我们识别的jso ...

  5. elasticsearch(3) curl命令

    curl 操作http的get/post/put/delete CURL 命令参数-a/--append 上传文件时,附加到目标文件-A/--user-agent <string> 设置用 ...

  6. windows curl命令详解

    概述 Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令. 软件下载 下载地址:https://cur ...

  7. windows(64位)下使用curl命令

    Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令. 工具下载 在官网处下载工具包:http://cu ...

  8. windows curl 命令

    windows 64 curl 命令的使用 https://blog.csdn.net/qq_27093465/article/details/53545693 curl命令可以通过命令行的方式,执行 ...

  9. windows curl命令

    一.概述 Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令 二.下载 下载地址:https://cu ...

随机推荐

  1. hdu6395 (矩阵快速幂+分块)

    Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.Q Hand In Hand Onli ...

  2. CentOS下运行Java文件Error: Could not find or load main class

    今天,因为测试拷贝一个JvmTest.java文件到CentOS虚机上运行,发现文件编译没有问题,但运行时却报错,如下图: Java代码如下: package com.zhi.test; public ...

  3. sass中文注释的解决方法和一些简单用法

    最近用sass来编写项目中的css,发现不能添加中文注释,报错如下 于是查阅了一下发现需要在scss文件顶部加上@charset "utf-8"即可解决. 在此顺便记录一些sass ...

  4. python学习------模块

    模块(modue)的概念 在计算机程序开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件 ...

  5. 电脑小白和ta的小白电脑——Tomcat服务器

    配置web服务器tomcat,这里默认了已经配置JAVA开发环境↓ https://www.cnblogs.com/gifted35/p/9775112.html (一)下载tomcat 我安装的服务 ...

  6. pip 在win10下安装

    http://blog.csdn.net/yupu56/article/details/50470970C:\Users\sunof\AppData\Local\Programs\Python\Pyt ...

  7. mybatis源码解析之Configuration加载(二)

    概述 上一篇我们讲了configuation.xml中几个标签的解析,例如<properties>,<typeAlises>,<settings>等,今天我们来介绍 ...

  8. linux 迁移项目ProtocolException

    背景:服务器跟换机房,虚拟机完整迁移项目,只修改ip和主机名 1.检查/etc/hosts 中ip 和主机名映射 2.检查网络端口是否有限制以及端口开放是否全了,检查ip有没有配对.RMI注册不上.

  9. ng-model-options 时延

    ng-model-options="{updateOn: 'blur'}" 失去焦点时生效 ng-model-options="{debounce:500}" ...

  10. Pycharm 远程调试

    上传后发现成图片了,很模糊.可以看我在百度盘分享pdf文件. https://pan.baidu.com/s/1bYVcAq40SRFtn8qXCPH6TQ