Elasticsearch Mapping Root Object
Elasticsearch Mapping Root Object,内容来自 B 站中华石杉 Elasticsearch 顶尖高手系列课程核心知识篇,英文内容来自 Elasticsearch: The Definitive Guide [2.x],在新的版本中 Mapping types have been removed。
在目前的 Elasticsearch 中,Mapping types 已经被取消了,可以直接查看 Mappings 相关文档。
The Root Object
The uppermost level of a mapping is known as the root object.
properties: the mapping for each field that a document may contain
metadata fields: all of which start with an underscore, such as _type, _id, and _source
settings: control how the dynamic detection of new fields is handled, such as analyzer, dynamic_date_formats, and dynamic_templates
Other settings: which can be applied both to the root object and to fields of type object, such as enabled, dynamic and include_in_all
root object
就是某个 type 对应的 mapping JSON,包括了 properties,metadata(_id,_source,_type),settings(analyzer),其他 settings(比如 include_in_all)
Properties
type: The datatype that the field contains
index: Whether a field should be searchable as full text (analyzed), searchable as an exact value (not_analyzed), or not searchable to all (no)
analyzer: Which analyzer to use for a full-text field, both at index time and at search time.
Metadata: _source Field
By default, Elasticsearch stores the JSON string representing the document body in the _source field. Like all stored fields, the _source field is compressed before being written to disk.
好处:
查询的时候,直接可以拿到完整的 document,不需要先拿 document id,再发送一次请求拿 document
partial update 基于 _source 实现
reindex 时,直接基于 _source 实现,不需要从数据库(或者其他外部存储)查询数据再修改
可以基于 _source 定制返回 field
debug query 更容易,因为可以直接看到 _source
如果不需要上述好处,可以禁用 _source
在查询的时候也可以只返回需要的字段:
In Elasticsearch, setting individual document fields to be stored is usually a false optimization. The whole document is already stored as the _source field.
Metadata: _all Field
Metadata all Field: a special field that indexes the values from all other fields as one big string. The query_string query clause (and searches performed as ?q=john) defaults to search in the _all field if no other field is specified.
将所有 field 打包在一起,作为一个_all field,建立索引。没指定任何 field 进行搜索时,就是使用 all field 在搜索。
_all 在新版本的 Elasticsearch 中似乎已经不再使用了。
Metadata: Document Identity 标识性 metadata
_index: The string ID of the document, default indexed but not stored
_type: The type name of the document, default neither indexed nor stored
_id: The index where the document lives, default neither indexed nor stored
_uid: The _type and _id concatenated together as type#id, default stored(can be retrieved) and indexed(searchable)
you can query the _id field as though it were a real field. Elasticsearch uses the _uid field to derive the _id
版权声明: 本文为 InfoQ 作者【escray】的原创文章。
原文链接:【http://xie.infoq.cn/article/1ceab03a471a8a33c12de0631】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
评论