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