Asticsearch 8.x 存儲(chǔ)有無壓縮?能壓縮到多少?
1、認(rèn)知前提
Elasticsearch 支持壓縮,壓縮方式默認(rèn)為:LZ4 壓縮算法。
具體參見:
The default value compresses stored data with LZ4 compression, but this can be set to best_compression which uses DEFLATE for a higher compression ratio, at the expense of slower stored fields performance.
中文翻譯為:
默認(rèn)值使用 LZ4 壓縮壓縮存儲(chǔ)的數(shù)據(jù),但這可以設(shè)置為 best_compression,它使用 DEFLATE 來獲得更高的壓縮率,但會(huì)降低存儲(chǔ)字段的性能。
https://www.elastic.co/guide/en/elasticsearch/reference/8.14/index-modules.html#index-codec
這里要引申一下,這屬于:靜態(tài)配置,類似:number_of_shard 主分片數(shù),不允許動(dòng)態(tài)修改,除非重建索引。
2、動(dòng)手驗(yàn)證一下壓縮比到底能壓縮多少?
2.1 樣例數(shù)據(jù)準(zhǔn)備
以 kibana_sample_flights 飛行數(shù)據(jù)為例進(jìn)行驗(yàn)證。
圖片
我們直接借助 elasticdump 進(jìn)行導(dǎo)出,以json 存儲(chǔ),作為原始數(shù)據(jù)。
導(dǎo)出實(shí)現(xiàn)參考:
NODE_TLS_REJECT_UNAUTHORIZED=0 elasticdump \
--input=https://elastic:@172.121.10.114:9200/kibana_sample_data_flights\
--output=/www/elasticsearch_0801_20220713/test/flights.json \
--type=data \
--input-ca=/www/elasticsearch_0801_20220713/elasticsearch-8.1.0/config/certs/http_ca.crt
導(dǎo)出成功截圖:
圖片
所占存儲(chǔ)空間大?。?/p>
圖片
2.2 Elasticsearch 默認(rèn) LZ4 壓縮算法的存儲(chǔ)大小
2.3 如果修改為:best_compression壓縮后,所占據(jù)存儲(chǔ)空間大小如下
需要修改索引:
PUT kibana_sample_data_flights_ext
{
"settings": {
"index.codec": "best_compression"
},
"mappings": {
"properties": {
......省略部分映射描述......
然后,reindex 遷移數(shù)據(jù)。
POST _reindex
{
"source": {
"index": "kibana_sample_data_flights"
},
"dest": {
"index": "kibana_sample_data_flights_ext"
}
}
3、初步結(jié)論
圖片
1)默認(rèn)壓縮LZ4 算法能壓縮到一半!54.77%,能節(jié)省一半的存儲(chǔ)!
新壓縮算法 best_compression 壓縮后,壓縮為原始空間的:35%,也就是能省65%的空間。
壓縮比要求高推薦使用:best_compression。