深入了解Elasticsearch存储

本文我们深入了解关于Elasticsearch存储,如我们写入Elasticsearch的数据是如何在节点上存储的。

Elasticsearch的路径

Elasticsearch主要有以下路径:

  • path.home:运行Elasticsearch进程的用的的home目录,默认为Java系统属性user.dir
  • path.conf:Elasticsearch的配置文件目录
  • path.plugins:Elasticsearch安装第三方插件的目录
  • path.work:Elasticsearch存放工作和临时文件的目录,现在已经弃用
  • path.logs:存放Elasticsearch日志目录
  • path.data:存放Elasticsearch数据目录

本文我们详细研究path.data目录存储结构。

path.data存储详情

由于Elasticsearch的底层是基于Lucene的,所以path.data索引文件中的主要是由Lucene产生。Elasticsearch与Lucene各自有各自的分工。Lucene主要负责编写和维护索引文件,Elasticsearch则是在Lucene的基础之上维护元数据信息,比如Mapping和集群状态等。一些Lucene做不到的功能则由Elasticsearch来弥补。

参考:Elasticsearch原理(二):索引存储方式

Elasticsearch存储

Node Data

data(path.data)
└── elasticsearch
    └── nodes
      └── 0
          ├── _state
          ├── indices

          │   └── global-0.st
          └── node.lock

  • node.lock文件用于确保一次只能从一个数据目录读取/写入一个Elasticsearch实例。
  • global-0.st文件是存储集群状态的二进制文件,global后面的数字代表集群状态的版本号,每个节点在选举Master过程中的存储的集群状态版本号不一定一致,在选举Master成功后会采用最大版本号的集群状态。
  • indices目录下面介绍

理论上这些文件都是可以使用特定编辑器进行修改的,但原则上不建议修改,有可能会造成数据丢失。
###Index Data
上面看到了indices文件夹中主要存储索引数据,下面是indices目录下的结构:

indices
└── index_id
    └── shard_id
      └── 0
      ├── _state
          └── state-0.st

  • index_id对应的是索引的唯一标识,Elasticsearch内部是根据这个唯一标识来区分不同索引的。
  • shard_id即为分片编号,从0开始递增
  • state-0.st文件是保存索引状态文件,如索引创建时间、设置等。也是二进制文件。state后面的编号是版本号,类似集群状态文件。

Shard Data

分片数据存储在上面提到的shard_id中,不同分片存在不同的目录下。

0
└── index
├── _state
    └── state-0.st
└── translog

      └── 0
      ├── _state
          ├── state-0.st

  • index目录中包含所有索引Lucene文件
  • state-0.st文件存储分片状态,state后跟版本号
  • translog目录存储Elasticsearch的事务日志

Lucene Index Files

Lucene对于索引文件的记录这方面做的很好,下面我们进入Lucene索引文件目录。

NameExtensionBrief Description
Segments Filesegments_NStores information about a commit point
Lock Filewrite.lockThe Write lock prevents multiple IndexWriters from writing to the same file.
Segment Info.siStores metadata about a segment
Compound File.cfs, .cfeAn optional “virtual” file consisting of all the other index files for systems that frequently run out of file handles.
Fields.fnmStores information about the fields
Field Index.fdxContains pointers to field data
Field Data.fdtThe stored fields for documents
Term Dictionary.timThe term dictionary, stores term info
Term Index.tipThe index into the Term Dictionary
Frequencies.docContains the list of docs which contain each term along with frequency
Positions.posStores position information about where a term occurs in the index
Payloads.payStores additional per-position metadata information such as character offsets and user payloads
Norms.nvd, .nvmEncodes length and boost factors for docs and fields
Per-Document Values.dvd, .dvmEncodes additional scoring factors or other per-document information.
Term Vector Index.tvxStores offset into the document data file
Term Vector Documents.tvdContains information about each document that has term vectors
Term Vector Fields.tvfThe field level info about term vectors
Live Documents.livInfo about what files are live

总结:

在本文中,我们查看了各种级别的Elasticsearch写入数据目录的文件:节点,索引和分片级别。 我们已经看到了Lucene索引存储在磁盘上的位置,我们最好不好试图去修改这些文件。

--------------------- 本文来自 桃花惜春风 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/xiaoyu_BD/article/details/82423749?utm_source=copy

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值