Elasticsearch-CURL

tech2023-02-12  103

Elasticsearch-CURL

命令格式

curl -H "Content-Type: application/json" -u username:password -X指定http请求的方法(如HEAD GET POST PUT DELETE)httpUrl -d '指定要传输的数据'

备注:

可选【-H指定头部】【-u 指定用户名和密码】【-d 指定要传输的数据】在任意的查询httpUrl中添加pretty参数-可格式化操作结果-更易识别的json数据 应用示例 获取集群的节点列表

curl 'localhost:9200/_cat/nodes?v'

 

列出所有索引

curl 'localhost:9200/_cat/indices?v'

 

创建索引

curl -X PUT 'localhost:9200/test_linxiao?pretty'

删除索引

curl -X DELETE 'localhost:9200/test_linxiao'

 

查看索引定义

curl -X GET 'localhost:9200/linxiao_test?pretty'

 

查询数据(前10)

curl -X GET 'localhost:9200/linxiao_test/_search?pretty'

指定条件查询

curl -H "Content-Type: application/json" -X GET 'localhost:9200/linxiao_test/_search?pretty' -d '{"query":{"term":{"user_code":{"value":"test"}}}}'

User_code=xiao

curl -X GET 'localhost:9200/linxiao_test/_search?q=user_code:xiao&pretty'

 

更新数据

curl -H "Content-Type: application/json" -X POST 'localhost:9200/linxiao_test/my_type/5/_update?pretty' -d '{"doc":{"user_code":"linxiao","staff_name":"test_linxiao"}}'

 

删除数据

curl  -X DELETE 'localhost:9200/linxiao_test/my_type/5?pretty'

 

最新回复(0)