基礎(chǔ)概念
NRT (Near Realtime)
ES的查詢不是實(shí)時的,進(jìn)索引后再查出缴挖,延遲不會超過1秒
集群 Cluster
Cluster 是 Node 的集合铺呵,Cluster的名字唯一
節(jié)點(diǎn) Node
節(jié)點(diǎn)存儲數(shù)據(jù)斧拍,參與Index&Search運(yùn)算
索引 Index
索引是文檔的集合酒奶,索引名稱只能是小寫的
文檔 Document
文檔是信息的基本單元,被Index的信息屑埋,就是文檔豪筝;文檔的格式只能是JSON;
分片(Shards)& 副本(Replicas)
一個索引里的數(shù)據(jù)量可能有10億條摘能,占用1T的存儲空間续崖,如果只有1個Node可能運(yùn)算、存儲能力都跟不上团搞;解決辦法是严望,分割1個Index到N個Shards,每個Shard有Index的完整功能莺丑,可以被分配到任意1個Node上去著蟹,這樣便于分割或橫向擴(kuò)展ES集群墩蔓;通過這種分布式&并發(fā)梢莽,能夠通過增加Node提高性能及吞吐量;
副本的能力:1)提升高可用能力奸披;2)跟分片類似昏名,也能提升并發(fā)能力、吞吐量阵面;
總結(jié)
每個Index可分割為多個Shard轻局,每個Index可以有0個副本或多個副本;擁有副本的Index样刷,會擁有兩類分片:Primary Shard 仑扑、Replica Shard,副本數(shù)量可隨時動態(tài)的調(diào)整置鼻;
_shrink
and _split
镇饮,這倆接口可給已存在的Index增加或減少Shard數(shù)量;
每個分片的最大數(shù)量是:2,147,483,519
安裝
待補(bǔ)充
查看索引基本信息
ES提供了1個強(qiáng)大的 REST API 給我們提供了跟ES Cluster交互的通道箕母,主要功能如下:
- 查看 集群 節(jié)點(diǎn) 索引 的健康狀況储藐、數(shù)據(jù);
- 管理 集群 節(jié)點(diǎn) 索引數(shù)據(jù) 元數(shù)據(jù)嘶是;
- 索引的 CURD 操作钙勃、查詢操作;
- 執(zhí)行高級查詢操作:paging聂喇、sorting辖源、filtering、scripting、aggregations等同木;
查看Cluster信息
GET /_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
1576394406 07:20:06 elasticsearch green 11 8 336 168 0 0 0 0 - 100.0%
查看Node信息
GET /_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.17.3.14 44 95 20 5.78 5.08 4.75 di - 5xa5kOK
172.17.3.10 69 95 28 6.54 5.09 4.66 di - 4dnxamP
172.17.3.15 74 95 22 4.83 4.87 4.52 di - Bs4CG9y
172.17.3.20 2 75 0 0.00 0.01 0.05 mi - rzZXZ5T
172.17.3.9 57 95 20 5.40 4.95 4.51 di - Hh9uMaU
172.17.3.18 3 75 0 0.00 0.04 0.06 mi * HFYmHzu
172.17.3.16 49 95 28 5.49 4.52 4.32 di - EaECxZP
172.17.3.19 1 75 0 0.00 0.01 0.05 mi - -vvjApo
172.17.3.13 56 95 23 6.22 5.17 4.59 di - HuQhdN6
172.17.3.11 50 95 21 6.26 5.44 5.01 di - iJDUeJ7
172.17.3.12 44 95 33 5.33 5.05 5.02 di - aDS9FZm
查看索引信息
GET /_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open abnormal-92 -ASolaunSieNjRuJOfp8-Q 1 0 138684 26 593.8mb 593.8mb
green open ac-apply-batch-91 R6HR3kX1QNK8PfvnuI6AFg 1 1 473153 0 556.9mb 278.4mb
green open ac-apply-daily-91 bJbruUXmSxmBPxk3B1PywQ 1 1 292742 0 297.9mb 148.9mb
green open ac-apply-order-91 mNOtjL28Tiin4vdKxrP_QA 8 1 14093331 0 15.6gb 7.8gb
green open accounts-91 8DxWjlImQAOFFZskWINimQ 8 0 7451614 0 18.9gb 18.9gb
green open amap-zone-90 nw91DRxoRY6okv2queOmLg 1 0 0 0 261b 261b
green open approval-90 hmmn4TlvQiGuW2x5-HdUaA 1 0 0 0 261b 261b
green open batch-96 rtST_ROXTNKv5CHgvbiJnQ 8 0 20728026 0 92.1gb 92.1gb
green open batch-account-91 oH-lw8NURlmkTyuHchxFIQ 1 0 5003832 0 3.1gb 3.1gb
green open batch-invoice-91 EUEnLoyQRxGqGWTJ2y7Yog 1 0 0 0 261b 261b
green open co-dy-batch-90 TFGohd0cQhqJeXde14BGjQ 1 0 0 0 261b 261b
green open co-dy-ticket-90 iDletuK-QWqR5sCq1_Bzrw 1 0 0 0 261b 261b
green open company-info-94 6kt2KEPJQOWwOSwmYNb3Ew 1 0 0 0 261b 261b
green open customer-95 59wvGQ8CSTyupNlJVAGlQg 8 0 0 0 2kb 2kb
green open customer-proj-90 AxGfRZDoTNK3ZDA_lah4Gg 1 0 1140 0 659.7kb 659.7kb
green open driver-91 V9B8s6bqTMaKWpU0MXnkjQ 1 0 0 0 261b 261b
green open fuel-card-92 SvENC7tKTAqV2y9xVsKOiQ 1 0 0 0 261b 261b
green open fuel-carrier-90 MURSlOJaTVKHYXujok7YRw 1 0 0 0 261b 261b
green open goods-90 lvZFldjQQP6srkgBSWYygA 1 0 21601 0 27.6mb 27.6mb
green open goods-category-90 nPR0BmKASoiKxY-7PUtE3g 1 0 440 0 120kb 120kb
green open insurance-90 60jVebmbS7erCy5IrgMTWQ 1 0 0 0 261b 261b
green open line-91 F0w6DvAHSU26VFXsps_yoQ 1 0 0 0 261b 261b
green open log-92 2EUyrFSYScS1xug9KPdt5Q 8 0 5928788 1 70.6gb 70.6gb
green open loss-91 hx0KQR5-QUqq0IXBpSkPig 1 0 339 0 551.8kb 551.8kb
green open material-91 pA0ZZF3DSqWlL0Y1B1WSgg 1 0 330 0 7.9mb 7.9mb
green open material-apply-91 ry3G3knsSFK89KwWCzE_mA 1 0 1567 0 1.5mb 1.5mb
創(chuàng)建索引
PUT /customer?pretty
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "customer"
}
索引&查詢數(shù)據(jù)
PUT /customer/_doc/1?pretty
{
"name": "John Doe"
}
// 索引新增Document結(jié)果
{
"_index" : "customer",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
// 獲取數(shù)據(jù)
GET /customer/_doc/1?pretty
// 返回的結(jié)果
{
"_index" : "customer",
"_type" : "_doc",
"_id" : "1",
"_version" : 2,
"_seq_no" : 1,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "John Doe"
}
}
// 刪除索引
API的模式
<HTTP Verb> /<Index>/<Type>/<ID>
更新Document
// 更新name值
POST /customer/_doc/1/_update?pretty
{
"doc": { "name": "Jane Doe" }
}
// 更新的同時新增字段
POST /customer/_doc/1/_update?pretty
{
"doc": { "name": "Jane Doe", "age": 20 }
}
// 通過script動態(tài)更新Document數(shù)據(jù)
POST /customer/_doc/1/_update?pretty
{
"script" : "ctx._source.age += 5"
}
// 刪除Document數(shù)據(jù)
DELETE /customer/_doc/2?pretty
批量操作
// 批量更新兩條數(shù)據(jù)
POST /customer/_doc/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
// 更新1條數(shù)據(jù) 刪除1條數(shù)據(jù)
POST /customer/_doc/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
批量操作浮梢,如果其中某條執(zhí)行失敗,其余的會繼續(xù)執(zhí)行