為何要避免往ES里寫入稀疏數(shù)據(jù)

轉(zhuǎn)一些文檔鏈接嗤栓,說明當(dāng)前版本(<=5.x) 為何要避免將稀疏的數(shù)據(jù)寫入ES。 隨著ES/Lucene編碼的改進(jìn)箍邮,這個問題未來版本可能會得到改善茉帅,特別是ES6.0/Lucene7.0優(yōu)化了doc_values對稀疏數(shù)據(jù)的編碼方式。

general-recommendations.html#sparsity

Avoid sparsity

The data-structures behind Lucene, which Elasticsearch relies on in order to index and store data, work best with dense data, ie. when all documents have the same fields. This is especially true for fields that have norms enabled (which is the case for text fields by default) or doc values enabled (which is the case for numerics, date, ip and keyword by default).

The reason is that Lucene internally identifies documents with so-called doc ids, which are integers between 0 and the total number of documents in the index. These doc ids are used for communication between the internal APIs of Lucene: for instance searching on a term with a matchquery produces an iterator of doc ids, and these doc ids are then used to retrieve the value of the norm in order to compute a score for these documents. The way this norm lookup is implemented currently is by reserving one byte for each document. The norm value for a given doc id can then be retrieved by reading the byte at index doc_id. While this is very efficient and helps Lucene quickly have access to the norm values of every document, this has the drawback that documents that do not have a value will also require one byte of storage.

In practice, this means that if an index has M documents, norms will require M bytes of storage per field, even for fields that only appear in a small fraction of the documents of the index. Although slightly more complex with doc values due to the fact that doc values have multiple ways that they can be encoded depending on the type of field and on the actual data that the field stores, the problem is very similar. In case you wonder: fielddata, which was used in Elasticsearch pre-2.0 before being replaced with doc values, also suffered from this issue, except that the impact was only on the memory footprint since fielddata was not explicitly materialized on disk.

Note that even though the most notable impact of sparsity is on storage requirements, it also has an impact on indexing speed and search speed since these bytes for documents that do not have a field still need to be written at index time and skipped over at search time.

It is totally fine to have a minority of sparse fields in an index. But beware that if sparsity becomes the rule rather than the exception, then the index will not be as efficient as it could be.

This section mostly focused on norms and doc values because those are the two features that are most affected by sparsity. Sparsity also affect the efficiency of the inverted index (used to index text/keyword fields) and dimensional points (used to index geo_point and numerics) but to a lesser extent.

Here are some recommendations that can help avoid sparsity:

index-vs-type

Fields that exist in one type will also consume resources for documents of types where this field does not exist.

This is a general issue with Lucene indices: they don’t like sparsity. Sparse postings lists can’t be compressed efficiently because of high deltas between consecutive matches. And the issue is even worse with doc values: for speed reasons, doc values often reserve a fixed amount of disk space for every document, so that values can be addressed efficiently. This means that if Lucene establishes that it needs one byte to store all value of a given numeric field, it will also consume one byte for documents that don’t have a value for this field. Future versions of Elasticsearch will have improvements in this area but I would still advise you to model your data in a way that will limit sparsity as much as possible.

sparse-versus-dense-document-values-with-apache-lucene
issues# LUCENE-6863?
elasticsearch-6-0-0-alpha1-released

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末锭弊,一起剝皮案震驚了整個濱河市堪澎,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌味滞,老刑警劉巖樱蛤,帶你破解...
    沈念sama閱讀 221,548評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異桃犬,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)行楞,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,497評論 3 399
  • 文/潘曉璐 我一進(jìn)店門攒暇,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人子房,你說我怎么就攤上這事形用。” “怎么了证杭?”我有些...
    開封第一講書人閱讀 167,990評論 0 360
  • 文/不壞的土叔 我叫張陵田度,是天一觀的道長。 經(jīng)常有香客問我解愤,道長镇饺,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,618評論 1 296
  • 正文 為了忘掉前任送讲,我火速辦了婚禮奸笤,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘哼鬓。我一直安慰自己监右,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 68,618評論 6 397
  • 文/花漫 我一把揭開白布异希。 她就那樣靜靜地躺著健盒,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上扣癣,一...
    開封第一講書人閱讀 52,246評論 1 308
  • 那天惰帽,我揣著相機(jī)與錄音,去河邊找鬼搏色。 笑死善茎,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的频轿。 我是一名探鬼主播垂涯,決...
    沈念sama閱讀 40,819評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼航邢!你這毒婦竟也來了耕赘?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,725評論 0 276
  • 序言:老撾萬榮一對情侶失蹤膳殷,失蹤者是張志新(化名)和其女友劉穎操骡,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體赚窃,經(jīng)...
    沈念sama閱讀 46,268評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡册招,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,356評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了勒极。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片是掰。...
    茶點故事閱讀 40,488評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖辱匿,靈堂內(nèi)的尸體忽然破棺而出键痛,到底是詐尸還是另有隱情,我是刑警寧澤匾七,帶...
    沈念sama閱讀 36,181評論 5 350
  • 正文 年R本政府宣布絮短,位于F島的核電站,受9級特大地震影響昨忆,放射性物質(zhì)發(fā)生泄漏丁频。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,862評論 3 333
  • 文/蒙蒙 一邑贴、第九天 我趴在偏房一處隱蔽的房頂上張望限府。 院中可真熱鬧,春花似錦痢缎、人聲如沸胁勺。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,331評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽署穗。三九已至寥裂,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間案疲,已是汗流浹背封恰。 一陣腳步聲響...
    開封第一講書人閱讀 33,445評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留褐啡,地道東北人诺舔。 一個月前我還...
    沈念sama閱讀 48,897評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像备畦,于是被迫代替她去往敵國和親低飒。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,500評論 2 359

推薦閱讀更多精彩內(nèi)容

  • 從來都不覺得自己精致懂盐,甚至覺得很糙 20歲的年紀(jì)褥赊,這是最美好的時候了吧,但反思一下自己的過去莉恼,活的是真的糙“韬恚現(xiàn)在,...
    青春流沙ww閱讀 165評論 0 0
  • 前言:以前對用戶體驗的理解俐银,處在一種很模糊的狀態(tài)尿背。A說:用戶體驗就是產(chǎn)品要好用,要用得舒服捶惜,你看微信就用得很自然田藐;...
    狐檬閱讀 578評論 0 8
  • 姑娘叫童蕓坞淮。 她只用一張A4紙就讓在上海職場浮沉五六年的王大炮簽了賣身契茴晋。 在王大炮看來陪捷,這多少有些兒戲。但他終歸...
    炮哥的篝火世界閱讀 278評論 0 0