Elasticsearch 命令行初识

发布时间 2023-09-15 19:45:53作者: walkersss

完整教程:
https://www.cnblogs.com/shaner/p/5661071.html
https://zhuanlan.zhihu.com/p/449555826


http://192.168.1.10:9201/_cat/health?v
http://192.168.1.10:9201/_cat
http://192.168.1.10:9201/_cat/indices?v


ES服务器 命令行:
----服务器命令行删除大索引
curl -XDELETE http://localhost:9201/sw_metrics-percentile-20230911
curl -XDELETE http://localhost:9201/sw_segment-20230914

curl -XGET http://localhost:9200/_cluster/health?pretty --查询elasticsearch的健康信息
curl -XGET http://localhost:9200/ --查询实例的相关信息
curl -XGET http://localhost:9200/_cluster/nodes/ --得到集群中节点的相关信息
curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown --关闭整个集群
curl -XPOST http://localhost:9200/_cluster/nodes/aaaa/_shutdown --关闭集群中指定节点
curl -XPOST http://localhost:9200/lishuai --创建名为lishuai的索引
curl -XDELETE http://localhost:9200/lishuai --删除名为lishuai的索引

curl -XGET 'http://10.10.110.2:19200/benlaitest/_search?pretty=true' -d '{"query":{"multi_match":{"query":"法国","fields":["firstname","lastname"]}}}' --查询数据(匹配firstname和lastname)
curl http://10.10.110.160:9200/benlaitest/_analyze?analyzer=standard -d 我爱你中国

postman执行请求API:
http://10.10.110.160:9200/_cat/indices?v -- Get请求 查看有多少索引
http://10.10.110.160:9200/benlaitest/_analyze?analyzer=standard --查看分词结果

1. 查看集群的健康状况
http://localhost:9200/_cat
http://localhost:9200/_cat/health?v

查看集群的节点
http://localhost:9200/_cat/?v

查看所有索引
http://localhost:9200/_cat/indices?v

创建一个索引
创建一个名为 customer 的索引。pretty要求返回一个漂亮的json 结果
PUT /customer?pretty

索引一个文档到customer索引中
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'{ "name": "John Doe"}'

5. 从customer索引中获取指定id的文档
curl -X GET "localhost:9200/customer/_doc/1?pretty"

6. 查询所有文档
GET /customer/_search?q=*&sort=name:asc&pretty

JSON格式方式
GET /customer/_search{ "query": { "match_all": {} }, "sort": [ {"name": "asc" } ]}

可视化工具: Kibana/Dev Tools

删除索引
DELETE /twitter

判断索引是否存在
HEAD twitter


curl命令
-XGET一种请求方法
-d 标识以post形式传入参数 ,写在请求正文里面
?pretty=true 以格式的形式显示结果