curl:
-X :指定http的请求方式,有HEAD、GET、POST、PUT、DELETE
-d :指定要传输的数据
-H :指定http的请求头信息
curl -XPUT http://ip:port/索引名?pretty-- 创建索引
curl -XGET http://ip:port/_cat/indices?v --查看当前es的所有索引信息
curl -XGET http://ip:port/索引名?pretty --查看单个索引信息
curl -XDELETE http://ip:port/索引名?pretty --删除索引
curl -H "Content-Type:application/json" -XPOST http://ip:port/索引名/_doc/01?pretty -d '{"id":"34234","name":"李四"}' --新增修改一条document文档信息,documentId为01
curl -XGET http://ip:port/索引名/_doc/01?pretty --查询documentId为01的一条数据
curl -H "Content-Type:application/json" -XPOST http://ip:port/索引名/_update/1?pretty -d '{"id":"34234"}' --修改documentId为1的指定一个字段
curl -XDELETE http://ip:port/索引名/_doc/1?pretty --删除指定documentId的一条数据
curl -H "Content-Type:application/json" -XPOST http://ip:port/索引名/_doc/_delete_by_query?pretty -d '{"query":{"match":{"name":"赵"}}}' --条件删除
curl -XGET http://ip:port/索引名/_search?pretty --查询指定所有库的所有数据
curl -XGET http://ip:port/索引名/_search?_source=name?pretty --查询指定索引库的所有数据记录的name值
curl -XGET 'http://ip:port/索引名/01?_source=name&pretty' --查询documentId为01的数据记录的name值
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"match_all":{}}}' -- 查询所有数据
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"match_all":{}},"size":2}' -- 指定条数
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"match_all":{}},"from":0,"size":2}' -- 分页查询
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"match_all":{}},"_source":["name","id"]}' -- 查询指定列
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"match_all":{}},"sort":{"price":{"order":"desc"}}}' -- 分页查询
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"match":{"name":"赵"}}}' --模糊匹配 match
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"bool":{"must":{"match":{"name":"赵"}}}}}' --多条件查询 bool must:必须满足的条件,must_not:必须不能满足的条件,should:应该,可有可无,或者
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"term":{"name":"赵雷"}}}' --精准查询term
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"terms":{"name":["赵雷",""]}}}' --精准多个词匹配
curl -H "Content-Type:application/json" -XGET http://ip:port/索引名/_search?pretty -d '{"query":{"range":{"age":{"gt":"20","lte":"25"}}}}' --范围查询
curl -XGET http://ip:port/索引名/_mapping --查看映射
curl -XGET http://ip:port/cluster/health --查看集群状态
单个索引
curl -XGET http://localhost:9200/indexname?pretty
获取所有type类型信息
curl -XGET http://localhost:9200/_mapping?pretty=true
获取指定索引的type类型信息
curl -XGET http://localhost:9200/indexname/_mapping?pretty=true
实战示例
索引版本
curl -XGET localhost:9200
所有索引
curl -XGET localhost:9200/_cat/indices?v
查看索引所有数据
curl -X GET "localhost:9200/indexname/_search" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}'
根据id查询数据
curl -H "Content-Type:application/json" -XGET http://localhost:9200/indexname/_search?pretty -d '{"query":{"term":{"id":"2a69f"}}}'
curl -H "Content-Type:application/json" -XGET http://localhost:9200/indexname/_search?pretty -d '{"query":{"term":{"serviceId":668}}}'
es修改只读状态 read_only_allow_delete
curl -X PUT -H 'Authorization: YOUR_TOKEN' -H "Content-Type: application/json" -d '{"index.blocks.read_only_allow_delete": null}' http://127.0.0.1:9200/service_info/_settings
curl -X PUT -H 'Authorization: YOUR_TOKEN' -H "Content-Type: application/json" -d '{"index.blocks.read_only_allow_delete": null}' http://127.0.0.1:9200/_all/_settings
curl -X GET -H 'Authorization: YOUR_TOKEN' http://127.0.0.1:9200/service_info/_settings
elasticsearch用curl查询
于 2024-07-08 14:03:55 首次发布