elasticsearch curl命令操作
查询elasticsearch集群状态
curl参数说明
-X :指定http的请求方式,有HEAD、GET、POST、PUT、DELETE
-d :指定要传输的数据
-H :指定http的请求头信息
创建索引 pretty参数是美化返回结果
curl -XPUT 'http://118.195.173.53:9200/student?pretty'
查看当前es的所有索引信息 v参数加表头
curl -XGET 'http://118.195.173.53:9200/_cat/indices?v'
查看单个索引信息
curl -XGET 'http://118.195.173.53:9200/user'
删除索引
curl -XDELETE 'http://118.195.173.53:9200/student'
新增修改文档信息
curl -H "Content-Type:application/json" -XPOST 'http://118.195.173.53:9200/student/_doc/1001' -d '{
"id":1001,
"name":"huyongjian"
}'
修改文档的一个字段
curl -H "Content-Type:application/json" -XPOST 'http://118.195.173.53:9200/student/_update/1001' -d '{
"doc":{
"id":11
}}'
查询一条文档数据
curl -XGET 'http://118.195.173.53:9200/student/_doc/1001'
删除一条文档数据
curl -XDELETE "http://118.195.173.53:9200/student/_doc/1001"
安条件删除文档数据
curl -H "Content-Type:application/json" -XPOST 'http://118.195.173.53:9200/student/_doc/_delete_by_query' -d '{
"query":{
"match":{"name":"huyongjian"}
}}'
查询指定库的文档数据
curl -XGET http://118.195.173.53:9200/student/_search
查询指定索引库的所有数据记录的name值
curl -XGET http://118.195.173.53:9200/student/_search?_source=name
查询所有数据
curl -H "Content-Type:application/json" -XGET http://118.195.173.53:9200/student/_search?pretty -d '{"query":{"match_all":{}}}'
指定条数
curl -H "Content-Type:application/json" -XGET http://118.195.173.53:9200/student/_search?pretty -d '{"query":{"match_all":{}},"size":2}'
查询指定列
curl -H "Content-Type:application/json" -XGET http://118.195.173.53:9200/student/_search?pretty -d '{"query":{"match_all":{}},"_source":["id","name"]}'
排序
curl -H "Content-Type:application/json" -XGET http://118.195.173.53:9200/student/_search?pretty -d '{"query":{"match_all":{}},"sort":{"id":{"order":"desc"}}}'
匹配查询
curl -H "Content-Type:application/json" -XGET http://118.195.173.53:9200/student/_search?pretty -d '{"query":{"match":{"name":"huyongjian"}}}'
多条件查询
curl -H "Content-Type:application/json" -XGET http://118.195.173.53:9200/student/_search?pretty -d '{"query":{"bool":{"must":{"match":{"name":"huyongjian22"}}}}}'
must_not:必须不能满足的条件,should:应该,可有可无,或者
精准查询
curl -H "Content-Type:application/json" -XGET http://118.195.173.53:9200/student/_search?pretty -d '{"query":{"term":{"name":"huyongjian"}}}'
精准查询
-d '{"query":{"terms":{"name":["huyongjian","huyongjian2"]}}}'
范围查询
-d '{"query":{"range":{"age":{"gt":"20","lte":"25"}}}}'
查看映射
curl -XGET http://118.195.173.53:9200/student/_mapping

浙公网安备 33010602011771号