首页 > 代码库 > elasticsearch中api详解
elasticsearch中api详解
一、cluster API详解
1、cluster health(获取集群的状态)
集群状态:
green:绿色表示所有的碎片都被分配
yellow:黄色表示主碎片被分配,但副本不是
red:表示特定的碎片没有在集群中分配
请求参数
level: cluster,indices,shards
wait_for_status: green,yellow,red
[root@elasticsearch3 ~]# curl -XGET ‘http://10.2.11.225:9200/_cluster/health/tomcat-access-log-2017.05.11?level=shards&pretty‘ -u adminName -p
2、索引状态(cluster state)
2.1)nodes(节点状态)
2.2)显示主节点状态(master_node)
3、集群数据(cluster stats)
[root@elasticsearch3 ~]# curl -XGET ‘http://10.2.11.225:9200/_cluster/stats?human&pretty‘ -u adminName -p
Enter host password for user ‘adminName‘:
{
"timestamp" : 1494680352006,
"cluster_name" : "myelk",
"status" : "green",
"indices" : {
"count" : 5,
"shards" : {
"total" : 42,
"primaries" : 21,
"replication" : 1.0,
"index" : {
"shards" : {
"min" : 2,
"max" : 10,
"avg" : 8.4
},
"primaries" : {
"min" : 1,
"max" : 5,
"avg" : 4.2
},
"replication" : {
"min" : 1.0,
"max" : 1.0,
"avg" : 1.0
}
}
},
"docs" : {
"count" : 11047,
"deleted" : 0
},
"store" : {
"size" : "6.4mb",
"size_in_bytes" : 6802156,
"throttle_time" : "0s",
"throttle_time_in_millis" : 0
},
"fielddata" : {
"memory_size" : "0b",
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"query_cache" : {
"memory_size" : "0b",
"memory_size_in_bytes" : 0,
"total_count" : 144823,
"hit_count" : 0,
"miss_count" : 144823,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"completion" : {
"size" : "0b",
"size_in_bytes" : 0
},
"segments" : {
"count" : 213,
"memory" : "1.3mb",
"memory_in_bytes" : 1367681,
"terms_memory" : "1mb",
"terms_memory_in_bytes" : 1049853,
"stored_fields_memory" : "65.7kb",
"stored_fields_memory_in_bytes" : 67360,
"term_vectors_memory" : "0b",
"term_vectors_memory_in_bytes" : 0,
"norms_memory" : "199.3kb",
"norms_memory_in_bytes" : 204096,
"doc_values_memory" : "45.2kb",
"doc_values_memory_in_bytes" : 46372,
"index_writer_memory" : "0b",
"index_writer_memory_in_bytes" : 0,
"index_writer_max_memory" : "20.5mb",
"index_writer_max_memory_in_bytes" : 21504000,
"version_map_memory" : "0b",
"version_map_memory_in_bytes" : 0,
"fixed_bit_set" : "0b",
"fixed_bit_set_memory_in_bytes" : 0
},
"percolate" : {
"total" : 0,
"time" : "0s",
"time_in_millis" : 0,
"current" : 0,
"memory_size_in_bytes" : -1,
"memory_size" : "-1b",
"queries" : 0
}
},
"nodes" : {
"count" : {
"total" : 3,
"master_only" : 0,
"data_only" : 0,
"master_data" : 3,
"client" : 0
},
"versions" : [ "2.3.3" ],
"os" : {
"available_processors" : 3,
"allocated_processors" : 3,
"mem" : {
"total" : "312.1mb",
"total_in_bytes" : 327274496
},
"names" : [ {
"name" : "Linux",
"count" : 3
} ]
},
"process" : {
"cpu" : {
"percent" : 0
},
"open_file_descriptors" : {
"min" : 266,
"max" : 281,
"avg" : 272
}
},
"jvm" : {
"max_uptime" : "2.1d",
"max_uptime_in_millis" : 188337407,
"versions" : [ {
"version" : "1.8.0_111",
"vm_name" : "Java HotSpot(TM) 64-Bit Server VM",
"vm_version" : "25.111-b14",
"vm_vendor" : "Oracle Corporation",
"count" : 3
} ],
"mem" : {
"heap_used" : "203.7mb",
"heap_used_in_bytes" : 213674160,
"heap_max" : "2.9gb",
"heap_max_in_bytes" : 3195076608
},
"threads" : 88
},
"fs" : {
"total" : "40.7gb",
"total_in_bytes" : 43701583872,
"free" : "27.1gb",
"free_in_bytes" : 29138677760,
"available" : "25gb",
"available_in_bytes" : 26898292736,
"spins" : "true"
},
"plugins" : [ {
"name" : "head",
"version" : "master",
"description" : "head - A web front end for an elastic search cluster",
"url" : "/_plugin/head/",
"jvm" : false,
"site" : true
}, {
"name" : "license",
"version" : "2.3.3",
"description" : "Internal Elasticsearch Licensing Plugin",
"jvm" : true,
"classname" : "org.elasticsearch.license.plugin.LicensePlugin",
"isolated" : false,
"site" : false
}, {
"name" : "shield",
"version" : "2.3.3",
"description" : "Elasticsearch Shield (security)",
"jvm" : true,
"classname" : "org.elasticsearch.shield.ShieldPlugin",
"isolated" : false,
"site" : false
} ]
}
}
[root@elasticsearch3 ~]# curl -XGET ‘http://10.2.11.225:9200/_nodes/stats/indices?pretty‘ -u adminName -p----统计节点信息
二、CAT API
1、master---查找主节点
[root@elasticsearch3 ~]# curl -XGET ‘http://10.2.11.225:9200/_cat/master?pretty&v‘ -u adminName -p
Enter host password for user ‘adminName‘:
id host ip node
PbiopqxtST6qDZ5x9Oo9dw 10.2.11.230 10.2.11.230 elk01
2、nodes---节点信息
查看帮助:?help
指定相应的列:?h=列名 如:GET /_cat/nodes?v&h=id,ip,port,v,m
3、indices索引
4、health
[root@elasticsearch3 ~]# curl -XGET ‘http://10.2.11.225:9200/_cat/health?v‘ -u adminName -p
Enter host password for user ‘adminName‘:
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1494682040 21:27:20 myelk green 3 3 42 21 0 0 0 0 - 100.0%
5、shard--分片信息
[root@elasticsearch3 ~]# curl -XGET ‘http://10.2.11.225:9200/_cat/shards?v‘ -u adminName -p
Enter host password for user ‘adminName‘:
index shard prirep state docs store ip node
tomcat-system-message-2017.05.11 2 p STARTED 1459 345.7kb 10.2.11.231 elk02
tomcat-system-message-2017.05.11 2 r STARTED 1459 345.5kb 10.2.11.225 elk03
tomcat-system-message-2017.05.11 3 r STARTED 1395 316.6kb 10.2.11.225 elk03
tomcat-system-message-2017.05.11 3 p STARTED 1395 316.6kb 10.2.11.230 elk01
tomcat-system-message-2017.05.11 4 r STARTED 1468 338.8kb 10.2.11.231 elk02
tomcat-system-message-2017.05.11 4 p STARTED 1468 340.5kb 10.2.11.230 elk01
tomcat-system-message-2017.05.11 1 r STARTED 1434 346kb 10.2.11.225 elk03
tomcat-system-message-2017.05.11 1 p STARTED 1434 346kb 10.2.11.230 elk01
tomcat-system-message-2017.05.11 0 p STARTED 1426 313.4kb 10.2.11.231 elk02
tomcat-system-message-2017.05.11 0 r STARTED 1426 336.1kb 10.2.11.225 elk03
6、查看常见信息(plugins)
root@elasticsearch3 ~]# curl -XGET ‘http://10.2.11.225:9200/_cat/plugins?v‘ -u adminName -p
Enter host password for user ‘adminName‘:
name component version type url
elk03 license 2.3.3 j
elk03 shield 2.3.3 j
elk01 head master s /_plugin/head/
elk01 license 2.3.3 j
elk01 shield 2.3.3 j
elk02 head master s /_plugin/head/
elk02 license 2.3.3 j
elk02 shield 2.3.3 j
三、Search APIs
1、search
[root@elasticsearch3 ~]# curl -XGET ‘http://10.2.11.225:9200/tomcat-access-log-2017.05.11/_search?v&pretty‘ -u adminName -p
elasticsearch中api详解