elasticsearch5.0 mapping

mapping

https://www.elastic.co/guide/en/elasticsearch/reference/5.0/mapping.html
每个index存在一个或多个types,用于分割索引中的多个文档到逻辑分组(type)。
每个type含有:
Meta-fields(type的元数据,系统定义属性)
Examples of meta-fields include the document’s _index, _type, _id, and _source fields
Fields or properties(type的自定义属性)

Field datatypes

Field datatypes
a simple type like text, keyword, date, long, double, boolean or ip.
a type which supports the hierarchical nature of JSON such as object or nested.
or a specialised type like geo_point, geo_shape, or completion.
multi-fields
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/multi-fields.html
经常用作索引相同field为不同目的使用不同方法,比如一个string field 可以作为text filed所谓索引用作全文搜索,同时也可以作为keyword filed用于排序或者聚合(sorting aggregations)。同时,你可以索引一个string field 使用标准分词器,英文分词器 和 中分分词器等。
This is the purpose of multi-fields. Most datatypes support multi-fields via the fields parameter.
这句话应该表示,大部分datatypes都支持对一个field(属性)进行多field(被索引属性)的设置。

防止mappings剧增(爆炸)的设置
下面的设置允许你限制手动或者自动创建field mappings的数量,为了阻止不好的文档结构(比如文档字段不确定,经常变动)造成的mappings爆炸(剧增)
index.mapping.total_fields.limit 一个index的最大fields数量默认1000
index.mapping.depth.limit field(属性)的最大深度,如果对象均在root下就是1,如果存在属性含有一个内部对象(object,nested),则2,默认20
index.mapping.nested_fields.limit 一个index的嵌套fields的最大数量默认50

dynamic mapping
fields和type在使用前无需定义,在增加field和type时会自动创建mapping
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/dynamic-mapping.html
动态mapping 规则可以被配置参看上面url

explicit mappings
当需要自己设置是,可以创建mapping在你创建index时,或者使用put mapping修改已经存在的index的mapping
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/indices-put-mapping.html

updating existing mapping
存在的type和field mappings 不能被updated。改变mapping将意味着已索引的文档变得无效。正确的做法时创建一个含有正确mappings的index,将数据导入新的index中

fields 被多个types 共享
fields 如果有相同的名字,在同一个index中,即使再不同的type中,也必须拥有相同的mapping

meta-fields

每个文档均由元数据联合组成,比如_index,_type _id等元数据。部分元数据在映射创建时都可以自定义它们的行为。
identity meta-fields
_index 文档属于的index
_uid _id和_type混合成的唯一值
_type 文档的所属的type
_id 文档对应的id

document source meta-fields
_source 原始的json表述(文档中的body部分)
_size _source的字节数,mapper-size 插件提供
插件参看
https://www.elastic.co/guide/en/elasticsearch/plugins/5.0/mapper-size.html

indexing meta-fields
_all A catch-all field that indexes the values of all other fields
_field_names 文档中包含非空值的所有属性

routing meta-fields
_parent 在两个type间创建父子关系
_routing 路由一个文档到指定的分片的自定义路由值

other meta-field
_meta 应用设置的元数据

mapping parameters

主要介绍用于各个datatype中可以进行设置的与mapping相关的参数
下面显示的是所有的datatype所有公用的所有映射参数
参看原网址

dynamic mapping

elasticsearch重要的特性之一是它视图在你的自己的详细设计之前能够让你尽可能快速的创建和浏览你自己的数据。索引文档,你不需要预先创建索引,定义映射,定义文档属性–你能够直接索引文档,索引,类型以及属性都会自动创建。
自动化的新类型以及属性的侦测和增加叫做动态映射(dynamic mapping)。动态映射规则可以被自定义设置去满足你自己的目的:
_default_mapping
为新的映射类型配置基本的映射。
dynamic field mapping
管理动态的属性侦测规则。
Dynamic templates
为动态增加属性配置自定义规则。

tip
index template允许你配置默认的映射,设置以及别名在你自动化创建索引或者显式创建索引的时候。

禁止自动化type的创建

自动化的映射类型创建可以在索引设置中通过 index.mapper.dynamic参数进行禁止设置

PUT data/_settings
{
  "index.mapper.dynamic":false 
}

自动化映射类型的创建也可以通过索引模板对所有索引进行设置

PUT _template/template_all
{
  "template": "*",
  "order":0,
  "settings": {
    "index.mapper.dynamic": false 
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值