Elasticsearch常用的命令
2018-05-26 本文已影响32人
wangfs
- 查看es版本信息
curl IP:9200
[root@pro-3-b ~]# curl 172.31.15.172:9200
{
"name" : "node-1",
"cluster_name" : "flow-es6.2",
"cluster_uuid" : "B-q_10OsSDmUgVZIGxb54Q",
"version" : {
"number" : "6.2.1",
"build_hash" : "7299dc3",
"build_date" : "2018-02-07T19:34:26.990113Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
- 查看集群是否健康
htt://IP:9200/_cat/health?v
[root@pro-3-b ~]# curl 172.31.15.172: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
1527324378 16:46:18 flow-es6.2 green 3 3 40 20 0 0 0 0 - 100.0%
- 查看集群状态
[root@elastic-redis-01 ~]# curl -XGET "http://localhost:9200/_cluster/health?pretty"
{
"cluster_name" : "flow-es6.2",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 20,
"active_shards" : 40,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
- 查看节点列表
http://IP:9200/_cat/nodes?v
[root@pro-3-b ~]# curl 172.31.15.172:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.31.15.173 7 45 0 0.00 0.01 0.05 mdi * node-2
172.31.15.172 7 48 0 0.00 0.01 0.05 mdi - node-1
172.31.15.174 4 45 0 0.00 0.01 0.05 mdi - node-3
- 列出所有索引及存储大小
http://IP:9200/_cat/indices?v
[root@pro-3-b ~]# curl 172.31.15.172:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open test I-3VQjA7RtmO-4xT_OtoTg 5 1 0 0 2.2kb 1.1kb
green open custome CF2DRI7uSqWxKGGl9tvynA 5 1 0 0 2.2kb 1.1kb
green open test_index 47WS4HLeSkysS5McrqmY1A 5 1 1 0 10.7kb 5.3kb
green open customer VfkQgXiIQpyWM72RoRK2Zg 5 1 5 0 36.7kb 18.3kb
- 创建索引
创建索引名为xx,默认会有5个分片,1个索引
[root@pro-3-b ~]# curl -XPUT 172.31.15.172:9200/hello_index?pretty
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "hello_index"
}
- 添加一个类型
curl -XPUT 'IP:9200/XX/external/2?pretty' -d '
{
"gwyy": "John"
}'
[root@pro-3-b ~]# curl -XPUT -H "Content-Type: application/json" '172.31.15.172:9200/hello_index/external/2?pretty' -d '
{
"gwyy": "John"
}'
{
"_index" : "hello_index",
"_type" : "external",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
- 更新一个类型
curl -XPOST 'IP:9200/XX/external/1/_update?pretty' -d '
{
"doc": {"name": "Jaf"}
}'
[root@pro-3-b ~]# curl -XPOST -H "Content-Type: application/json" '172.31.15.172:9200/hello_index/external/5/_update?pretty' -d '
{
"doc": {"name": "Jaf"}
}'
{
"error" : {
"root_cause" : [
{
"type" : "document_missing_exception",
"reason" : "[external][5]: document missing",
"index_uuid" : "4IRpFzGITlifIBhHR2N1yw",
"shard" : "1",
"index" : "hello_index"
}
],
"type" : "document_missing_exception",
"reason" : "[external][5]: document missing",
"index_uuid" : "4IRpFzGITlifIBhHR2N1yw",
"shard" : "1",
"index" : "hello_index"
},
"status" : 404
}
报错了,404,实际应该修改已经存在的ID。如下所示
[root@pro-3-b ~]# curl -XPOST -H "Content-Type: application/json" '172.31.15.172:9200/hello_index/external/2/_update?pretty' -d '
{
"doc": {"name": "Jaf"}
}'
{
"_index" : "hello_index",
"_type" : "external",
"_id" : "2",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
- 删除指定索引
curl -XDELETE 'IP:9200/_ index?pretty'
#删除hello_index索引
[root@pro-3-b ~]# curl -XDELETE -H "Content-Type: application/json" '172.31.15.172:9200/hello_index?pretty'
{
"acknowledged" : true
}
#查看所有的索引
[root@pro-3-b ~]# curl 172.31.15.172:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open test I-3VQjA7RtmO-4xT_OtoTg 5 1 0 0 2.2kb 1.1kb
green open custome CF2DRI7uSqWxKGGl9tvynA 5 1 0 0 2.2kb 1.1kb
green open test_index 47WS4HLeSkysS5McrqmY1A 5 1 1 0 10.7kb 5.3kb
green open customer VfkQgXiIQpyWM72RoRK2Zg 5 1 5 0 36.7kb 18.3kb
#删除test索引
[root@pro-3-b ~]# curl -XDELETE -H "Content-Type: application/json" '172.31.15.172:9200/test?pretty'
{
"acknowledged" : true
}
#查看所有的索引
[root@pro-3-b ~]# curl 172.31.15.172:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open custome CF2DRI7uSqWxKGGl9tvynA 5 1 0 0 2.2kb 1.1kb
green open customer VfkQgXiIQpyWM72RoRK2Zg 5 1 5 0 36.7kb 18.3kb
green open test_index 47WS4HLeSkysS5McrqmY1A 5 1 1 0 10.7kb 5.3kb
参考:
https://blog.csdn.net/E_Eric12138/article/details/79333606
https://blog.csdn.net/zhangbin666/article/details/73332538