几种复杂的数据类型
multivalue field
比如数据是1
{"tags":["tag1","tag2"]}
这种数据建立索引时,与string类型是一样的, 数组中的数据是不能混的,要放字符串都放字符串.
empty field
比如 null, [], [null]这样的数据
object field
我们先来添加一个document1
2
3
4
5
6
7
8
9
10
11PUT /company/emp/1
{
"name":"jack",
"age":27,
"join_date":"2017-01-01",
"address":{
"country":"china",
"province":"zhejiang",
"city":"hangzhou"
}
}
像上面这个address就是object类型的, 我们来看一下这个type的_mapping1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56{
"company": {
"mappings": {
"emp": {
"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
}
}
}
}
}
}
}
}
可以看到 address中的每个field都有对应的type等
其实像我们刚才添加的这个document,它的数据在es底层是像这样存储的1
2
3
4
5
6
7
8{
"name":[jack],
"age":[27],
"join_date":[2017-01-01],
"address.country":[china],
"address.province":[zhejiang],
"address.city":[hangzhou]
}
再比如有更复杂的数据,比如下面我们再加一个,数据是1
2
3
4
5
6
7{
"authors": [
{ "age": 26, "name": "Jack White"},
{ "age": 55, "name": "Tom Jones"},
{ "age": 39, "name": "Kitty Smith"}
]
}
像这种包含json数组的数据,底层会从横向转为列式存储,就像这样1
2
3
4{
"authors.age": [26, 55, 39],
"authors.name": [jack, white, tom, jones, kitty, smith]
}
就是一列存在一起