Type是什么
- type,是一个
index
中用来区分类似的数据的,类似的数据,但是可能有不同的 fields
- 而且有不同的属性来控制索引建立、分词器
lucene
是没有 type 的概念的
- 在
document
中,实际上将 type 作为一个 document 的 field
来存储
- 即 type,es 通过
_type
来进行 type 的过滤和筛选
Type的存储机制
- 一个
index
中的多个 type,实际上是放在一起存储的
- 因此一个
index
下,不能有多个 type
重名
- 而类型或者其他设置的不同,因为那样是无法处理的
PUT /goods/electronic_goods/1
{
"name":"小米空调",
"price":1999,
"service_period":"one year"
}
PUT /goods/fresh_goods/1
{
"name":"澳洲龙虾",
"price":199,
"eat_period":"one week"
}
{
"goods":{
"mappings":{
"_type":{
"type":"string",
"index":"false"
},
"name":{
"type":"string"
},
"price":{
"type":"double"
},
"service_period":{
"type":"string"
},
"eat_period":{
"type":"string"
}
}
}
}
{
"_type":"electronic_goods",
"name":"小米空调",
"price":1999,
"service_period":"one year",
"eat_period":""
}
{
"_type":"fresh_goods",
"name":"澳洲龙虾",
"price":199,
"service_period":"",
"eat_period":"one week"
}
Type弃用的原因
- 同一索引下,不同
type
的数据也需要存储其他 type
的 field
- 这样就会出现大量的空值,造成资源的浪费,因此不同的数据要放到不同的索引中
ES9 中将会彻底删除 type