目录
1.新建 一个 index with correct mapping
2.数据迁移 reindex data into that index
弃用Type
ES 6.x 之前,Type 开始弃用
ES 7.x ,被弱化,仍支持
ES 8.x ,完全移除
弃用后,每个索引只包含一种文档类型
如果需要区分不同类型的文档,俩种方式:
- 创建不同的索引
- 在文档中添加自定义字段来实现。
why
Elasticsearch 的底层存储(Lucene)是基于索引的,而不是基于 Type 的。
在同一个索引中,不同 Type 的文档可能具有相同名称但不同类型的字段,这种字段类型冲突会导致数据不一致和查询错误。
- GET /bank/_search
- {
- "query": {
- "match": {
- "address": "mill lane"
- }
- },
- "_source": ["account_number","address"]
- }
从查询语句可以看出,查询是基于index的,不会去指定type。如果有不同type的address,就会引起查询冲突。
映射
Mapping 定义 doc和field 如何被存储和被检索
Mapping(映射) 是 Elasticsearch 中用于定义文档结构和字段类型的机制。它类似于关系型数据库中的表结构(Schema),用于描述文档中包含哪些字段、字段的数据类型(如文本、数值、日期等),以及字段的其他属性(如是否分词、是否索引等)。
Mapping 是 Elasticsearch 的核心概念之一,它决定了数据如何被存储、索引和查询。
查询 mapping of index
_mapping
GET /bank/_mapping
- {
- "bank" : {
- "mappings" : {
- "properties" : {
- "account_number" : {
- "type" : "long"
- },
- "address" : {
- "type" : "text",
- "fields" : {
- "keyword" : {
- "type" : "keyword",
- "ignore_above" : 256
- }
- }
- },
- "age" : {
- "type" : "long"
- },
- "balance" : {
- "type" : "long"
- },
- "city" : {
- "type" : "text",
- "fields" : {
- "keyword" : {
- "type" : "keyword",
- "ignore_above" : 256
- }
- }
- },
- "email" : {
- "type" : "text",
- "fields" : {
- "keyword" : {
- "type" : "keyword",
- "ignore_above" : 256
- }
- }
- },
- "employer" : {
- "type" : "text",
- "fields" : {
- "keyword" : {
- "type" : "keyword",
- "ignore_above" : 256
- }
- }
- },
- "firstname" : {
- "type" : "text",
- "fields" : {
- "keyword" : {
- "type" : "keyword",
- "ignore_above" : 256
- }
- }
- },
- "gender" : {
- "type" : "text",
- "fields" : {
- "keyword" : {
- "type" : "keyword",
- "ignore_above" : 256
- }
- }
评论记录:
回复评论: