elasticsearch index 的 type 解釋

Index names are different indices. Types are just syntactic sugar to add separation between types of documents. If you know Lucene, type is just a field on a doc.


Let me explain a bit how types work in elasticsearch. At the end of the day, Lucene index has Documents and has no notion of types. Types are something added (as best as possible) by elasticsearch. A lucene document is a flat structure key value pair (so objects in json are also translated to this), and a type ends up as another field within the document (called _type).


Then you build a query and in the field (any query that acces a field to execute on), you can specify type1.field1, and in this case, it will be automatically detected, and the query will be wrapped to only be executed match on docs with _type:type1 (in an efficient manner), on field1.


This does mean that across types, having the same field name with different mappings types (for example, type1 has field1 of type numeric, and type2 also has field1 but of type string) should not be done (working on automatically detecting that...).

So, the type prefix when you define the field name should allow to only search on a field against that specific type. (At the end of the day, it is wrapped in a filtered query with a _type:type1 term filter)

發佈了7 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章