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并动态创建mappingPUT /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)查看自动创建的mappingGET /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