写点什么

Elasticsearch Mapping Overview

用户头像
escray
关注
发布于: 2021 年 02 月 14 日
Elasticsearch Mapping Overview

Elasticsearch Mapping Overview,文字内容来自 B 站中华石杉 Elasticsearch 高手进阶课程,英文内容来自官方文档。

Review

To summarize the flow of index requests, this is what happens:


  1. The node accepting the request will be the coordinator. It consults the mappings to determine which shard to send the request to.

  2. The request is sent to the primary of that shard.

  3. The primary writes the operation to its translog, and relays the request to the replicas.

  4. When a sufficient number of replicas have acknowledged, the primary returns success.

  5. The coordinator returns success when all the sub-operations (in e.g. a bulk request) have succeeded.

Mapping

mapping,就是 index 的 type 的元数据,每个 type 都有一个自己的 mapping,决定了数据类型,建立倒排索引的行为,还有进行搜索的行为


Mapping is the process of defining how a document, and the fields it contains, are stored and indexed.


Indices created in Elasticsearch 7.0.0 or later no longer accept a _default_ mapping.


In an Elasticsearch index, fields that have the same name in different mapping types are backed by the same Lucene field internally.


  1. 往 Elasticsearch 里面直接插入数据,Elasticsearch 会自动建立索引,同时建立 type 以及对应的 mapping

  2. mapping 中就自动定义了每个 field 的数据类型

  3. 不同的数据类型(比如说 text 和 date),可能有的是 exact value,有的是 full text

  4. exact value,在建立倒排索引的时候,分词的时候,是将整个值一起作为一个关键词建立到倒排索引中的;full text,会经历各种各样的处理,分词,normaliztion(时态转换,同义词转换,大小写转换),才会建立到倒排索引中

  5. 同时呢,exact value 和 full text 类型的 field 就决定了,在一个搜索过来的时候,对 exact value field 或者是 full text field 进行搜索的行为也是不一样的,会跟建立倒排索引的行为保持一致;比如说 exact value 搜索的时候,就是直接按照整个值进行匹配,full text query string 会进行分词和 normalization 再去倒排索引中去搜索

  6. 可以用 Elasticsearch 的 dynamic mapping,让其自动建立 mapping,包括自动设置数据类型;也可以提前手动创建 index 和 type 的 mapping,自己对各个 field 进行设置,包括数据类型,包括索引行为,包括分词器,等等

Mapping explosion

Defining too many fields in an index can lead to a mapping explosion, which can cause out of memory errors and difficult situations to recover from.


Use the mapping limit settings to limit the number of field mappings (created manually or dynamically) and prevent documents from causing a mapping explosion.


发布于: 2021 年 02 月 14 日阅读数: 17
用户头像

escray

关注

Let's Go 2017.11.19 加入

在学 Elasticsearch 的项目经理

评论

发布
暂无评论
Elasticsearch Mapping Overview