--------------------------------------------------------------------------------
1、查看所有可查看项
[root@k8s-master01 ~]# curl http://172.16.3.226:9200/_cat/ -u elastic:chinaedu
=.=
/_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
2、?pretty 美化输出(查看集群状态)
[root@k8s-master01 ~]# curl -XGET 'http://172.16.3.225:9200/_cluster/health?pretty' -u elastic:chinaedu
3、?v显示详细信息(查看谁是master)
[root@k8s-master01 ~]# curl -XGET 'http://172.16.3.225:9200/_cat/master?v' -u elastic:chinaedu
id host ip node
5tlr3zNDRwSBE1K6ggknZA 172.16.3.226 172.16.3.226 elk02
4、?help输出可以显示的列
[root@k8s-master01 ~]# curl -XGET 'http://172.16.3.225:9200/_cat/master?help' -u elastic:chinaedu
id | | node id
host | h | host name
ip | | ip address
node | n | node name
5、header执行输出的列?h
[root@k8s-master01 ~]# curl -XGET 'http://172.16.3.225:9200/_cat/master?h=ip,node' -u elastic:chinaedu
172.16.3.226 elk02
6、查看所有的索引
[root@k8s-master01 ~]# curl -XGET 'http://172.16.3.225:9200/_cat/indices?v' -u elastic:chinaedu
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .monitoring-kibana-6-2021.03.22 Iy-f_ZiZRFqESpo6gbbycA 1 1 2522 0 1.7mb 666.4kb
green open nginx_log_2021.03.22 TtXhhabzQjSPg3s3Yv-etg 5 1 34 0 385.5kb 203.1kb
green open .watcher-history-9-2021.03.20 Ouumi99hS6CxR-oVHI7Nog 1 1 4284 0 11.9mb 6mb
green open .triggered_watches xtTzRnYkSsKUFSrxfz_kmg 1 1 0 0 1.6mb 846.8kb
green open .monitoring-alerts-6 NEdvqZryQQaGmnBMQ7wjOw 1 1 1 0 12.9kb 6.4kb
green open .monitoring-kibana-6-2021.03.21 kZEdvsDeQ-aQ8yUq8z_Byw 1 1 8634 0 4.1mb 2mb
green open ilm yj5B5g0rQTa0zd7mopnfPA 5 1 1 0 7.3kb 3.6kb
green open .watcher-history-9-2021.03.22 nov2kZHKT2-u8T43hBr5QA 1 1 2530 0 8mb 4.1mb
green open .watcher-history-9-2021.03.21 2NpH_6osQkiluZJM1JtqSQ 1 1 8640 0 23.9mb 11.9mb
green open nginx_log_2021.03.20 SAdS35WwRnW5kDRs10zFhQ 5 1 28 0 314.5kb 157.4kb
green open .monitoring-es-6-2021.03.22 6gN1eOkOQLuPtF9bgc-v1Q 1 1 64655 450 87mb 43.2mb
green open .monitoring-es-6-2021.03.21 MjU4Oeo3QvyGxv7pGsabsA 1 1 177993 480 229.2mb 115.7mb
green open tomcat_log_2021.03.20 jhw-fi1cS_GaRCJBjCOH_w 5 1 38 0 320.6kb 170.9kb
green open .watches qLVmCng5QhKc6j5yXKowVQ 1 1 6 0 50.9kb 24.8kb
green open .kibana_1 Pd3GGYFJSgGmHBerrKpkYQ 1 1 5 0 52.7kb 26.3kb
green open tomcat_log_2021.03.21 DXwlJxH-R2apGQkXzIxwbg 5 1 30 0 307.4kb 169.4kb
green open nginx_log_2021.03.21 mE8X_oC0TTyfvK5Rw7lJyQ 5 1 22 0 416.9kb 219kb
green open .monitoring-es-6-2021.03.20 tHAnheRpTw6Z0yPHx-1luQ 1 1 68871 136 76.4mb 38.2mb
green open .monitoring-kibana-6-2021.03.20 eBQXi2LgRxepU0lZ0Rc2nw 1 1 4453 0 2.5mb 1.2mb
green open .security-6 -3AiJLFmTsuoBRjV8F_4lg 1 1 12 1 52.7kb 26.2kb
green open tomcat_log_2021.03.22 QrMVEjYRST6R74paIrQfmw 5 1 110 0 603.8kb 317.7kb
7、创建索引
[root@k8s-master01 ~]# curl -XPUT 'http://172.16.3.225:9200/test?pretty' -u elastic:chinaedu
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "test"
}
8、关闭索引
[root@k8s-master01 ~]# curl -XPOST 'http://172.16.3.225:9200/test/_close?pretty' -u elastic:chinaedu
{
"acknowledged" : true
}
9、开启索引
[root@k8s-master01 ~]# curl -XPOST 'http://172.16.3.225:9200/test/_open?pretty' -u elastic:chinaedu
{
"acknowledged" : true,
"shards_acknowledged" : true
}
10、删除索引
[root@k8s-master01 ~]# curl -XDELETE 'http://172.16.3.225:9200/test?pretty' -u elastic:chinaedu
{
"acknowledged" : true
}
11、插入数据
[root@k8s-master01 ~]# curl -H 'Content-Type: application/json' -XPUT http://172.16.3.225:9200/test/fulltext/1?pretty -d'
{
"name":"zhangsan"
}' -u elastic:chinaedu
12、查看索引下所有的数据
[root@k8s-master01 ~]# curl -XGET http://172.16.3.225:9200/test/_search?pretty -u elastic:chinaedu
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "test",
"_type" : "fulltext",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "lisi"
}
}
]
}
}
13、取出ID等于1的数据
[root@k8s-master01 ~]# curl -XGET http://172.16.3.225:9200/test/fulltext/1?pretty -u elastic:chinaedu
{
"_index" : "test",
"_type" : "fulltext",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"name" : "zhangsan"
}
}
14、更新文档 / 更新数据
[root@k8s-master01 ~]# curl -H 'Content-Type: application/json' -XPOST http://172.16.3.225:9200/test/fulltext/1/_update/?pretty -d'
{
"doc":{"name":"lisi"}
}' -u elastic:chinaedu
{
"_index" : "test",
"_type" : "fulltext",
"_id" : "1",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
15、匹配符合条件的记录
[root@k8s-master01 ~]# curl -H 'Content-Type: application/json' -XPOST http://172.16.3.225:9200/test/fulltext/_search?pretty -d'
{
"query" : {"match": {"name": "lisi"}}
}' -u elastic:chinaedu
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "test",
"_type" : "fulltext",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "lisi"
}
}
]
}
}
16、删除文档
[root@k8s-master01 ~]# curl -XDELETE http://172.16.3.225:9200/test/fulltext/1/?pretty -u elastic:chinaedu
{
"_index" : "test",
"_type" : "fulltext",
"_id" : "1",
"_version" : 3,
"result" : "deleted",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1
}
17、clear cache 清空内存中的缓存
[root@k8s-master01 ~]# curl -H 'Content-Type: application/json' -XPOST http://172.16.3.225:9200/test/_cache/clear?pretty -u elastic:chinaedu
18、refresh 刷新:可以立即实现从内存到磁盘的缓存过程,
[root@k8s-master01 ~]# curl -H 'Content-Type: application/json' -XPOST http://172.16.3.225:9200/test/_refresh?pretty -u elastic:chinaedu
19、flush 跟refresh类似,只不过会删除translog日志
[root@k8s-master01 ~]# curl -H 'Content-Type: application/json' -XPOST http://172.16.3.225:9200/test/_flush?pretty -u elastic:chinaedu