热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

37Mapping字段的数据类型解析及其Object类型的底层架构分析

1、字段类型概述一级分类二级分类具体类型核心类型字符串类型string,text,keyword整数类型integer,long,short,byte浮点类型double,flo
1、字段类型概述
一级分类二级分类具体类型
核心类型字符串类型string,text,keyword
整数类型integer,long,short,byte
浮点类型double,float,half_float,scaled_float
逻辑类型boolean
日期类型date
范围类型range
二进制类型binary
复合类型数组类型array
对象类型object
嵌套类型nested
地理类型地理坐标类型geo_point
地理地图geo_shape
特殊类型IP类型ip
范围类型completion
令牌计数类型token_count
附件类型attachment
抽取类型percolator

2、object 类型

JSON天生具有层级关系,文档会包含嵌套的对象:

1)创建index并动态创建mapping

PUT /company/employee/1
{"address": {"country": "china","province": "guangdong","city": "guangzhou"},"name": "zhangsan","age": 18,"join_date": "2017-01-01"
}

响应结果

{"_index": "company","_type": "employee","_id": "1","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"created": true
}

address:object类型

2)查看自动创建的mapping

GET /company/_mapping/employee

响应结果

{"company": {"mappings": {"employee": {"properties": {"address": {"properties": {"city": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"country": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"province": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}}}},"age": {"type": "long"},"join_date": {"type": "date"},"name": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}}}}}}
}

3address对象在es底层的结构

{"address": {"country": "china","province": "guangdong","city": "guangzhou"},"name": "zhangsan","age": 18,"join_date": "2017-01-01"
}

在es底层的结构

{"name": [zhangsan],"age": [18],"join_date": [2017-01-01],"address.country": [china],"address.province": [guangdong],"address.city": [guangzhou]
}

4如果是数组类型

{"authors": [{ "age": 26, "name": "Jack White"},{ "age": 55, "name": "Tom Jones"},{ "age": 39, "name": "Kitty Smith"}]
}

在es底层的结构

{"authors.age": [26, 55, 39],"authors.name": [jack, white, tom, jones, kitty, smith]
}

对于其他字段类型就不一一提及了,可以参考

https://www.cnblogs.com/candlia/p/11920029.html


推荐阅读
author-avatar
缅甸新葡京国际
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有