Elasticsearch压缩索引——lucene倒排索引本质是列存储+使用嵌套文档可以大幅度提高压缩率
2017-01-10 15:44
726 查看
注意:由于是重复数据,词法不具有通用性!文章价值不大!
摘自:https://segmentfault.com/a/1190000002695169
Doc Values 会压缩存储重复的内容。 给定这样一个简单的 mapping
mappings = { 'testdata': { '_source': {'enabled': False}, '_all': {'enabled': False}, 'properties': { 'name': { 'type': 'string', 'index': 'no', 'store': False, 'dynamic': 'strict', 'fielddata': {'format': 'doc_values'} } } } }
插入100万行随机的重复值
words = ['hello', 'world', 'there', 'here'] def read_test_data_in_batches(): batch = [] for i in range(10000 * 100): if i % 50000 == 0: print(i) if len(batch) > 10000: yield batch batch = [] batch.append({ '_index': 'wentao-test-doc-values', '_type': 'testdata', '_source': {'name': random.choice(words)} }) print(i) yield batch
磁盘占用是
size: 28.5Mi (28.5Mi) docs: 1,000,000 (1,000,000)
把每个word搞长一些,同样是插入100万行
words = ['hello' * 100, 'world' * 100, 'there' * 100, 'here' * 100] def read_test_data_in_batches(): batch = [] for i in range(10000 * 100): if i % 50000 == 0: print(i) if len(batch) > 10000: yield batch batch = [] batch.append({ '_index': 'wentao-test-doc-values', '_type': 'testdata', '_source': {'name': random.choice(words)} }) print(i) yield batch
磁盘占用不升反降
size: 14.4Mi (14.4Mi) docs: 1,000,000 (1,000,000)
这说明了lucene在底层用列式存储这些字符串的时候是做了压缩的。这个要是在某个商业列式数据库里,就这么点优化都是要大书特书的dictionary encoding优化云云。
Nested Document
实验表明把一堆小文档打包成一个大文档的nested document可以压缩存储空间。把前面的mapping改成这样:mappings = { 'testdata': { '_source': {'enabled': False}, '_all': {'enabled': False}, 'properties': { 'children': { 'type': 'nested', 'properties': { 'name': { 'type': 'string', 'index': 'no', 'store': False, 'dynamic': 'strict', 'fielddata': {'format': 'doc_values'} } } } } } }
还是插入100万行,但是每一千行打包成一个大文档
words = ['hello', 'world', 'there', 'here'] def read_test_data_in_batches(): batch = [] for i in range(10000 * 100): if i % 50000 == 0: print(i) if len(batch) > 1000: yield [{ '_index': 'wentao-test-doc-values2', '_type': 'testdata', '_source': {'children': batch} }] batch = [] batch.append({'name': random.choice(words)}) print(i) yield [{ '_index': 'wentao-test-doc-values2', '_type': 'testdata', '_source': {'children': batch} }]
磁盘占用是
size: 2.47Mi (2.47Mi) docs: 1,001,000 (1,001,000)
文档数没有变小,但是磁盘空间仅仅占用了2.47M。这个应该受益于lucene内部对于嵌套文档的存储优化。
相关文章推荐
- sphinx 源码阅读之分词,压缩索引,倒排——单词对应的文档ID列表本质和lucene无异 也是外部排序再压缩 解压的时候需要全部扫描doc_ids列表偏移量相加获得最终的文档ID
- sphinx 源码阅读之分词,压缩索引,倒排——单词对应的文档ID列表本质和lucene无异 也是外部排序再压缩 解压的时候需要全部扫描doc_ids列表偏移量相加获得最终的文档ID
- ElasticSearch中head插件安装及创建索引,插入文档,使用
- 使用Elasticsearch建索引提高HBase检索速度的探索
- Lucene系列(二)luke使用及索引文档的基本操作
- 时间序列数据库选型——本质是列存储,B-tree索引,抑或是搜索引擎中的倒排索引
- 使用多线程压缩提高全量索引切换速度
- Poseidon 系统是一个日志搜索平台——认证看链接ppt,本质是索引的倒排列表和原始日志数据都存在HDFS,而文档和倒排的元数据都在NOSQL里,同时针对单个filed都使用了独立索引,使用MR来索引和搜索
- ElasticsearchCRUD使用(三)【嵌套文档的MVC】
- Lucene索引库查询;使用MatchAllDocsQuery查询索引目录中的所有文档;及代码示例
- 腾讯Hermes设计概要——数据分析用的是列存储,词典文件前缀压缩,倒排文件递增id、变长压缩、依然是跳表-本质是lucene啊
- elasticsearch聚合操作——本质就是针对搜索后的结果使用桶bucket(允许嵌套)进行group by,统计下分组结果,包括min/max/avg
- lucene底层数据结构——FST,针对field使用列存储,delta encode压缩doc ids数组,LZ4压缩算法
- 使用Lucene对预处理后的文档进行创建索引(可执行)
- 使用Lucene对预处理后的文档进行创建索引(可运行)
- 时间序列数据库选型——本质是列存储,B-tree索引,抑或是搜索引擎中的倒排索引
- 高效管理 Elasticsearch 中基于时间的索引——本质是在利用滚动模式做数据的冷热分离,热索引可以用ssd
- mysql在数据库表中,使用索引可以大大提高查询速度
- 转(备忘)提高lucene索引速度技巧汇总
- 使用索引和统计特性来提高数据库的查询性能(转)