之前我们已经成功安装了Elasticsearch,接下来我们看看ES 提供了那些常用的查询方法。
1.查询集群健康信息
GET /_cat/health 或 GET /_cluster/health
返回结果
{
"cluster_name" : "docker-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"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
}
释义:
cluster_name——集群名称
status——集群状态,如果为red,则表示集群当前不可用,
timed_out——是否有超时,
number_of_nodes——集群中的节点个数
number_of_data_nodes——集群中的数据节点数
active_primary_shards——集群中的主分片数量。这是涵盖了所有索引的汇总值。
active_shards——是涵盖了所有索引的_所有_分片的汇总值,即包括副本分片。
relocating_shards—— 显示当前正在从一个节点迁往其他节点的分片的数量。通常来说应该是 0,不过在 Elasticsearch 发现集群不太均衡时,该值会上涨。比如说:添加了一个新节点,或者下线了一个节点
initializing_shards—— 是刚刚创建的分片的个数。比如,当你刚创建第一个索引,分片都会短暂的处于 initializing 状态。这通常会是一个临时事件,分片不应该长期停留在 initializing 状态。你还可能在节点刚重启的时候看到 initializing 分片:当分片从磁盘上加载后,它们会从 initializing 状态开始
unassigned_shards——通常未分配分片的来源是未分配的副本。比如,一个有 5 分片和 1 副本的索引,在单节点集群上,就会有 5 个未分配副本分片。如果你的集群是 red 状态,也会长期保有未分配分片(因为缺少主分片)
number_of_pending_tasks——是指主节点创建索引并分配shards等任务,如果该指标数值一直未减小代表集群存在不稳定因素
number_of_in_flight_fetch——正在进行的碎片信息请求的数量
2.查看集群状态信息
GET _cluster/stats?pretty
indices.count:索引总数。
indices.shards.total:分片总数。
indices.shards.primaries:主分片数量。
docs.count:文档总数。
store.size_in_bytes:数据总存储容量。
segments.count:段总数。
nodes.count.total:总节点数。
nodes.count.data:数据节点数。
nodes. process. cpu.percent:节点CPU使用率。
fs.total_in_bytes:文件系统使用总容量。
fs.free_in_bytes:文件系统剩余总容量。
3.查询集群当前全部索引
GET /_cat/indices
4.新增索引
PUT /<index>
不过不建议这样创建索引,最好列出文档的字段和类型
PUT qlanglog/
{
"settings":{
"number_of_shards":5,
"number_of_replicas":0
},
"mappings": {
"doc":{
"properties":{
"ruleTraceId":{
"type":"keyword"
},
"message":{
"type":"text"
},
"line_number":{
"type":"integer"
},
"class":{
"type":"keyword"
},
"method":{
"type":"keyword"
},
"exception":{
"type":"nested",
"properties":{
"exception_message":{
"type":"text"
},
"exception_class":{
"type":"text"
},
"stacktrace":{
"type":"text"
}
}
},
"timestamp":{
"type": "date",
"format":"yyyy-MM-dd HH:mm:ss"
},
"version":{
"type":"keyword"
},
"level":{
"type":"keyword"
}
}
}
}
}
5.删除索引
delete /<index>
以上就是对ES 创建索引和查询基本信息的一些API接口