Elasticsearch压缩索引——lucene倒排索引本质是列存储+使用嵌套文档可以大幅度提高压缩率

简介:

注意:由于是重复数据,词法不具有通用性!文章价值不大!

摘自: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内部对于嵌套文档的存储优化。














本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6269604.html,如需转载请自行联系原作者


相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。  
相关文章
|
自然语言处理 大数据 应用服务中间件
大数据-172 Elasticsearch 索引操作 与 IK 分词器 自定义停用词 Nginx 服务
大数据-172 Elasticsearch 索引操作 与 IK 分词器 自定义停用词 Nginx 服务
547 5
|
存储 分布式计算 大数据
大数据-169 Elasticsearch 索引使用 与 架构概念 增删改查
大数据-169 Elasticsearch 索引使用 与 架构概念 增删改查
474 3
|
JSON 自然语言处理 数据库
ElasticSearch基础1——索引和文档。Kibana,RestClient操作索引和文档+黑马旅游ES库导入
概念、ik分词器、倒排索引、索引和文档的增删改查、RestClient对索引和文档的增删改查
ElasticSearch基础1——索引和文档。Kibana,RestClient操作索引和文档+黑马旅游ES库导入
|
存储 缓存 监控
优化Elasticsearch 索引设计
优化Elasticsearch 索引设计
504 5
|
测试技术 API 开发工具
ElasticSearch7.6.x 模板及滚动索引创建及注意事项
ElasticSearch7.6.x 模板及滚动索引创建及注意事项
480 8
|
存储 JSON 关系型数据库
Elasticsearch 索引
【11月更文挑战第3天】
606 4
|
测试技术 API 开发工具
ElasticSearch核心概念:倒排索引
ElasticSearch核心概念:倒排索引
410 6
|
存储 自然语言处理 数据库
Elasticsearch倒排索引
【11月更文挑战第2天】
512 1
|
存储 监控 分布式数据库
百亿级存储架构: ElasticSearch+HBase 海量存储架构与实现
本文介绍了百亿级数据存储架构的设计与实现,重点探讨了ElasticSearch和HBase的结合使用。通过ElasticSearch实现快速检索,HBase实现海量数据存储,解决了大规模数据的高效存储与查询问题。文章详细讲解了数据统一接入、元数据管理、数据一致性及平台监控等关键模块的设计思路和技术细节,帮助读者理解和掌握构建高性能数据存储系统的方法。
百亿级存储架构: ElasticSearch+HBase 海量存储架构与实现
|
JSON 自然语言处理 算法
ElasticSearch基础2——DSL查询文档,黑马旅游项目查询功能
DSL查询文档、RestClient查询文档、全文检索查询、精准查询、复合查询、地理坐标查询、分页、排序、高亮、黑马旅游案例
ElasticSearch基础2——DSL查询文档,黑马旅游项目查询功能

热门文章

最新文章