偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Elasticsearch 存儲(chǔ)一條數(shù)據(jù), put 過(guò)程是什么樣子的?

存儲(chǔ) 存儲(chǔ)軟件
在前面已經(jīng)介紹了 ES 中常用的一些名詞,知道了數(shù)據(jù)是存儲(chǔ)在 shard 中的,而 index 會(huì)映射一個(gè)或者多個(gè) shard 。那這時(shí)候我要存儲(chǔ)一條數(shù)據(jù)到某個(gè)索引下,這條數(shù)據(jù)是在哪個(gè) index 下的呢?

 [[340646]]

前言

 在前面已經(jīng)介紹了 ES 中常用的一些名詞,知道了數(shù)據(jù)是存儲(chǔ)在 shard 中的,而 index 會(huì)映射一個(gè)或者多個(gè) shard 。那這時(shí)候我要存儲(chǔ)一條數(shù)據(jù)到某個(gè)索引下,這條數(shù)據(jù)是在哪個(gè) index 下的呢? "

1.ES演示

一切按照官方教程使用 三條命令,在本機(jī)啟動(dòng)三個(gè)節(jié)點(diǎn)組裝成偽集群。

  1. ~  % > ./elasticsearch 
  2.  
  3. ~  % > ./elasticsearch -Epath.data=data2 -Epath.logs=log2 
  4.  
  5. ~  % > ./elasticsearch -Epath.data=data3 -Epath.logs=log3 

創(chuàng)建一個(gè)索引

  1. curl -X PUT "localhost:9200/my-index-000001?pretty" -H 'Content-Type: application/json' -d' 
  2.   "settings": { 
  3.     "index": { 
  4.       "number_of_shards": 3,   
  5.       "number_of_replicas": 2  
  6.     } 
  7.   } 

當(dāng)前版本 7.9

ES 默認(rèn) number_of_shards 為 1

默認(rèn) number_of_replicas 為 1,即一個(gè)分片只有一個(gè)副本

 

下面命令可以查看索引信息:

  1. curl -X GET "localhost:9200/_cat/indices/my-index-000001?v&s=index&pretty" 

 

存放數(shù)據(jù)

  1. curl -X PUT "localhost:9200/my-index-000001/_doc/0825?pretty" -H 'Content-Type: application/json' -d' 
  2.   "name""liuzhihang" 

 

查詢(xún)數(shù)據(jù)

  1. curl -X GET "localhost:9200/my-index-000001/_doc/0825?pretty" 

 

2.一條數(shù)據(jù)該存放在哪個(gè) shard ?

通過(guò)命令可以看出:在存放數(shù)據(jù)時(shí)并沒(méi)有指定到哪個(gè) shard,那數(shù)據(jù)是存在哪里的呢?

當(dāng)一條數(shù)據(jù)進(jìn)來(lái),會(huì)默認(rèn)會(huì)根據(jù) id 做路由:

  1. shard = hash(routing) % number_of_primary_shards 

從而確定存放在哪個(gè) shard。routing 默認(rèn)是 _id, 也可以設(shè)置其他。

這個(gè) id 可以自己指定也可以系統(tǒng)給生成, 如果不指定則會(huì)系統(tǒng)自動(dòng)生成。

3.put 一條數(shù)據(jù)的過(guò)程是什么樣的?

 

寫(xiě)入過(guò)程主要分為三個(gè)階段

1.協(xié)調(diào)階段:Client 客戶(hù)端選擇一個(gè) node 發(fā)送 put 請(qǐng)求,此時(shí)當(dāng)前節(jié)點(diǎn)就是協(xié)調(diào)節(jié)點(diǎn)(coordinating node)。協(xié)調(diào)節(jié)點(diǎn)根據(jù) document 的 id 進(jìn)行路由,將請(qǐng)求轉(zhuǎn)發(fā)給對(duì)應(yīng)的 node。這個(gè) node 上的是 primary shard 。

2.主要階段:對(duì)應(yīng)的 primary shard 處理請(qǐng)求,寫(xiě)入數(shù)據(jù) ,然后將數(shù)據(jù)同步到 replica shard。

  • primary shard 會(huì)驗(yàn)證傳入的數(shù)據(jù)結(jié)構(gòu)
  • 本地執(zhí)行相關(guān)操作
  • 將操作轉(zhuǎn)發(fā)給 replica shard

3.當(dāng)數(shù)據(jù)寫(xiě)入 primary shard 和 replica shard 成功后,路由節(jié)點(diǎn)返回響應(yīng)給 Client。

4.副本階段:每個(gè) replica shard 在轉(zhuǎn)發(fā)后,會(huì)進(jìn)行本地操作。

在寫(xiě)操作時(shí),默認(rèn)情況下,只需要 primary shard 處于活躍狀態(tài)即可進(jìn)行操作。

在索引設(shè)置時(shí)可以設(shè)置這個(gè)屬性

index.write.wait_for_active_shards

默認(rèn)是 1,即 primary shard 寫(xiě)入成功即可返回。

如果設(shè)置為 all 則相當(dāng)于 number_of_replicas+1 就是 primary shard 數(shù)量 + replica shard 數(shù)量。就是需要等待 primary shard 和 replica shard 都寫(xiě)入成功才算成功。

可以通過(guò)索引設(shè)置動(dòng)態(tài)覆蓋此默認(rèn)設(shè)置。

4.總結(jié)

如何看一條數(shù)據(jù)在哪個(gè) shard 上呢?

curl -X GET "localhost:9200/my-index-000001/_search_shards?routing=0825&pretty"

通過(guò)上面命令可以查到數(shù)據(jù) 0825 的所在 shard。

 

相關(guān)資料

[1] ES 創(chuàng)建索引:

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

[2] ES 查詢(xún)數(shù)據(jù):

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html

[2] ES 檢索 shard:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-shards.html

本文轉(zhuǎn)載自微信公眾號(hào)「劉志航」,可以通過(guò)以下二維碼關(guān)注。轉(zhuǎn)載本文請(qǐng)聯(lián)系劉志航公眾號(hào)。

 

 

 

責(zé)任編輯:武曉燕 來(lái)源: 劉志航
相關(guān)推薦

2023-06-18 23:13:27

MySQL服務(wù)器客戶(hù)端

2018-01-16 15:02:20

存儲(chǔ)RAIDSAN

2022-10-10 08:47:49

ITCIO數(shù)據(jù)

2021-02-19 10:14:49

云計(jì)算公共云

2015-11-18 10:13:54

數(shù)據(jù)中心數(shù)據(jù)中心發(fā)展

2021-05-08 13:11:58

物聯(lián)網(wǎng)IOT物聯(lián)網(wǎng)技術(shù)

2022-03-15 16:19:13

物聯(lián)網(wǎng)物聯(lián)網(wǎng) 2.0IoT

2011-10-10 11:04:54

2020-11-04 11:17:20

好代碼程序員整潔

2014-04-08 09:56:30

銷(xiāo)售易CRM

2021-11-29 07:42:44

CSS 技巧CSS 繪圖技巧

2024-03-04 09:19:33

CSSbackground前端

2021-05-27 09:30:51

Java流程控制

2023-02-17 14:40:06

物聯(lián)網(wǎng)供應(yīng)鏈

2021-10-04 15:46:31

網(wǎng)絡(luò)通信5G

2012-10-29 15:45:51

2021-01-07 07:33:06

Tomcat啟動(dòng)工具

2021-09-30 19:12:46

通信網(wǎng)絡(luò)ADSL

2022-11-18 10:17:10

2019-09-03 14:57:33

智慧城市虛擬新加坡3D
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)