elasticsearch rest api
查看帮助
curl -s http://${esHost}:9200/_cat
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
查看集群节点
curl -s http://${esHost}:9200/_cat/nodes
172.17.0.2 26 53 0 0.00 0.02 0.05 dilm * 3e4cc9650c81
curl -s curl -s http://${esHost}:9200/_cat/master
5J-yRNX9SmGVPTwWC4NvLw 172.17.0.2 172.17.0.2 3e4cc9650c81
查看当前集群健康状态
curl -s http://192.168.134.16:9200/_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1647485540 02:52:20 docker-cluster yellow 1 1 1 1 0 0 1 0 - 50.0%
索引操作
# 查看所有的索引
curl -s http://192.168.134.16:9200/_cat/indices?pretty
yellow open test_employees ytLQkvvkRK-7TdrBx10TGw 1 1 20 0 10.8kb 10.8kb
yellow open label_system ywbz6poBRIWVmVDX6AlB6A 1 1 2828 2068 1.7mb 1.7mb
# 删除指定索引
curl -XDELETE http://192.168.134.16:9200/test_employees
搜索
# 关键字搜索
curl -s "http://192.168.134.16:9200/test_employees/_search?q=10001&pretty"
# 指定字段查询(+包含,-不包含)
curl -s "http://192.168.134.16:9200/test_employees/_search?q=emp_no:10001&pretty"
curl -s "http://192.168.134.16:9200/test_employees/_search?q=+emp_no:10001&pretty"
# 通DSL搜索
curl -H "Content-Type: application/json" -XGET "http://192.168.134.16:9200/test_employees/_search?pretty" -d '{"query":{"match":{"emp_no":10001}}}'
