elasticsearch -- mapping(动态映射)

本文介绍了Elasticsearch中动态字段类型映射的特性,包括自动检测数据类型(如日期和数值),以及如何通过控制date_detection、dynamic_date_formats和numeric_detection来定制这些检测。还展示了如何使用_mapping命令查看和修改索引的字段类型设置。
摘要由CSDN通过智能技术生成

Dynamic field mapping (动态字段类型映射)

ES 官方文档地址

  • 个人理解:
    本篇主要描述的是 ES会根据保存的字段动态的设置字段类型,不像MySQL创建表时需要定义字段类型

Date detection 数据检测(默认开启)

  • _mapping 命令:查看文档中各个字段的数据类型
PUT my-index-000001/_doc/1
{
  "create_date": "2015/09/02"
}

GET my-index-000001/_mapping 

Disabling date detection 关闭数据检测

PUT my-index-000001
{
  "mappings": {
    "date_detection": false
  }
}

PUT my-index-000001/_doc/1 
{
  "create_date": "2015/09/02"
}

Customizing detected date formats 自定义时间格式检测

PUT my-index-000001
{
  "mappings": {
    "dynamic_date_formats": [ "yyyy/MM", "MM/dd/yyyy"]
  }
}

PUT my-index-000001/_doc/1
{
  "create_date": "09/25/2015"
}

Numeric detection 数值检测

  • 开启数值检测(默认情况下是关闭的)
PUT my-index-000001
{
  "mappings": {
    "numeric_detection": true
  }
}

PUT my-index-000001/_doc/2
{
  "my_float":   "8.0", 
  "my_integer": "88" 
}

GET my-index-000001/_mapping

在这里插入图片描述

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值