Elasticsearch Mapping
有关 Elasticsearch Mapping,文字内容来自 B 站中华石杉 Elasticsearch 高手进阶课程,英文内容来自官方文档。
插入几条数据,让 Elasticsearch 自动为我们建立一个索引
尝试各种搜索
在 7.10 版本的 Elasticsearch 上查了一下,都是一条结果,为什么呢?直接去看官方文档。
Mapping
Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. For instance, use mappings to define:
which string fields should be treated as full text fields.
which fields contain numbers, dates, or geolocations.
the format of date values.
custom rules to control the mapping for dynamically added fields.
Settings to prevent mappings 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.
Consider a situation where every new document inserted introduces new fields, such as with dynamic mapping. Each new field is added to the index mapping, which can become a problem as the mapping grows.
自动或手动为 index 中的 type 建立的一种数据结构和相关配置,简称为 mapping
dynamic mapping,自动为我们建立 index,创建 type,以及 type 对应的 mapping,mapping 中包含了每个 field 对应的数据类型,以及如何分词等设置
Dynamic mapping
Fields and mapping types do not need to be defined before being used. Thanks to dynamic mapping, new field names will be added automatically, just by indexing a document. New fields can be added both to the top-level mapping type, and to inner object and nested fields.
The dynamic mapping rules can be configured to customise the mapping that is used for new fields.
搜索结果为什么不一致,因为 Elasticsearch 自动建立 mapping 的时候,设置了不同的 field 不同的 data type。不同的 data type 的分词、搜索等行为是不一样的。所以出现了_all field 和 post_date field 的搜索表现完全不一样。
遗留问题
没能解决为什么我的查询结果和教程中不一样的问题,应该是因为版本升级,倒是查询的条件变了,留待以后解决。
版权声明: 本文为 InfoQ 作者【escray】的原创文章。
原文链接:【http://xie.infoq.cn/article/d8760a5462df4671e2379d6d0】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
评论