Elasticsearch之type底层结构及弃用原因
生活随笔
收集整理的這篇文章主要介紹了
Elasticsearch之type底层结构及弃用原因
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.type是什么
type,是一個index中用來區分類似的數據的,類似的數據,但是可能有不同的fields,而且有不同的屬性來控制索引建立、分詞器.
field的value,在底層的lucene中建立索引的時候,全部是opaque bytes類型,不區分類型的。
lucene是沒有type的概念的,在document中,實際上將type作為一個document的field來存儲,即type,es通過type來進行type的過濾和篩選。
2.es中不同type存儲機制
一個index中的多個type,實際上是放在一起存儲的,因此一個index下,不能有多個type重名,而類型或者其他設置不同的,因為那樣是無法處理的
{"goods": {"mappings": {"electronic_goods": {"properties": {"name": {"type": "string",},"price": {"type": "double"},"service_period": {"type": "string"} }},"fresh_goods": {"properties": {"name": {"type": "string",},"price": {"type": "double"},"eat_period": {"type": "string"}}}}} } PUT /goods/electronic_goods/1 {"name": "小米空調","price": 1999.0,"service_period": "one year" } PUT /goods/fresh_goods/1 {"name": "澳洲龍蝦","price": 199.0,"eat_period": "one week" }es文檔在底層的存儲是這樣子的
{"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.0,"service_period": "one year","eat_period": "" } {"_type": "fresh_goods","name": "澳洲龍蝦","price": 199.0,"service_period": "","eat_period": "one week" }3. type棄用
同一索引下,不同type的數據存儲其他type的field 大量空值,造成資源浪費。
所以,不同類型數據,要放到不同的索引中。
es9中,將會徹底刪除type。
總結
以上是生活随笔為你收集整理的Elasticsearch之type底层结构及弃用原因的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Elasticsearch之mappin
- 下一篇: Elasticsearch之search