Elastic索引定义应用

数据索引

字段类型

Elastic数据类型和数据库字段类型映射关系

数据库类型 Elastic类型 说明
String/Varchar keyword 该field不做分词
String/Varchar/Text text 该field会经过分词处理
Integer integer int类型(32bit)
Long long long类型(64bit)
float float 浮点类型(32bit)
double double 浮点类型(64bit)
boolean boolean 布尔类型: true或者false
date/datetime date 日期类型: 2015-10-11, 2015-10-11T22:21:10
bytes/binary binary 二进制类型, 用于存储文件或者字节流

创建索引

1
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
[root@localhost ~]# curl -XPUT "http://127.0.0.1:9200/db_test?pretty=true" -H 'Content-Type: application/json' -d'
{
"index": {
"analysis": {
"filter": {
"mix_pinyin": {
"lowercase": "true",
"padding_char": " ",
"first_letter": "prefix",
"keep_original": "true",
"remove_duplicated_term": "true",
"type": "pinyin",
"keep_full_pinyin": "true"
}
},
"analyzer": {
"ik_pinyin_analyzer": {
"filter": [
"mix_pinyin",
"word_delimiter"
],
"type": "custom",
"tokenizer": "ik_max_word"
},
"default": {
"tokenizer": "ik_max_word"
}
}
},
"number_of_shards": "1",
"number_of_replicas": "1"
}
}'

定义类型

1
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
[root@localhost ~]# curl -XPOST "http://127.0.0.1:9200/db_test/tb_opus/_mapping?pretty=true" -H 'Content-Type: application/json' -d'
{
"properties": {
"aliasName": {
"type": "text",
"fields": {
"origin": {
"type": "keyword"
},
"pinyin": {
"type": "text",
"term_vector": "with_positions_offsets",
"analyzer": "ik_pinyin_analyzer"
},
"suggest": {
"type": "completion",
"analyzer": "ik_max_word",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
}
},
"analyzer": "ik_max_word"
},
"appId": {
"type": "long"
},
"author": {
"type": "text",
"fields": {
"origin": {
"type": "keyword"
},
"pinyin": {
"type": "text",
"term_vector": "with_positions_offsets",
"analyzer": "ik_pinyin_analyzer"
},
"suggest": {
"type": "completion",
"analyzer": "ik_max_word",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
}
},
"analyzer": "ik_smart"
},
"createTime": {
"type": "date"
},
"enabled": {
"type": "integer"
},
"favoriteTotal": {
"type": "long"
},
"fingerprint": {
"type": "keyword"
},
"id": {
"type": "long"
},
"images": {
"type": "keyword"
},
"introduce": {
"type": "text",
"fields": {
"pinyin": {
"type": "text",
"boost": 10.0,
"term_vector": "with_positions_offsets",
"analyzer": "ik_pinyin_analyzer"
}
},
"analyzer": "ik_smart"
},
"issueTime": {
"type": "long"
},
"opusName": {
"type": "text",
"fields": {
"origin": {
"type": "keyword"
},
"pinyin": {
"type": "text",
"term_vector": "with_positions_offsets",
"analyzer": "ik_pinyin_analyzer"
},
"suggest": {
"type": "completion",
"analyzer": "ik_max_word",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
}
},
"analyzer": "ik_max_word"
},
"sort": {
"type": "long"
},
"tags": {
"type": "text",
"fields": {
"origin": {
"type": "keyword"
},
"pinyin": {
"type": "text",
"term_vector": "with_positions_offsets",
"analyzer": "ik_pinyin_analyzer"
},
"suggest": {
"type": "completion",
"analyzer": "ik_max_word",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
}
},
"analyzer": "ik_max_word"
},
"type": {
"type": "integer"
},
"score": {
"type": "double"
},
"updateTime": {
"type": "date"
},
"userId": {
"type": "long"
},
"uuid": {
"type": "keyword"
},
"viewTotal": {
"type": "long"
}
}
}'

查看索引信息

1
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
[root@localhost elasticsearch-6.0.0 ]$ curl -XGET "http://127.0.0.1:9200/db_test?pretty=true"
{
"db_test" : {
"aliases" : { },
"mappings" : {
"tb_opus" : {
"properties" : {
"aliasName" : {
"type" : "text",
"fields" : {
"origin" : {
"type" : "keyword"
},
"pinyin" : {
"type" : "text",
"term_vector" : "with_positions_offsets",
"analyzer" : "ik_pinyin_analyzer"
},
"suggest" : {
"type" : "completion",
"analyzer" : "ik_max_word",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
}
},
"analyzer" : "ik_max_word"
},
"appId" : {
"type" : "long"
},
"author" : {
"type" : "text",
"fields" : {
"origin" : {
"type" : "keyword"
},
"pinyin" : {
"type" : "text",
"term_vector" : "with_positions_offsets",
"analyzer" : "ik_pinyin_analyzer"
},
"suggest" : {
"type" : "completion",
"analyzer" : "ik_max_word",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
}
},
"analyzer" : "ik_smart"
},
"createTime" : {
"type" : "date"
},
"enabled" : {
"type" : "integer"
},
"favoriteTotal" : {
"type" : "long"
},
"fingerprint" : {
"type" : "keyword"
},
"id" : {
"type" : "long"
},
"images" : {
"type" : "keyword"
},
"introduce" : {
"type" : "text",
"fields" : {
"pinyin" : {
"type" : "text",
"boost" : 10.0,
"term_vector" : "with_positions_offsets",
"analyzer" : "ik_pinyin_analyzer"
}
},
"analyzer" : "ik_smart"
},
"issueTime" : {
"type" : "long"
},
"opusName" : {
"type" : "text",
"fields" : {
"origin" : {
"type" : "keyword"
},
"pinyin" : {
"type" : "text",
"term_vector" : "with_positions_offsets",
"analyzer" : "ik_pinyin_analyzer"
},
"suggest" : {
"type" : "completion",
"analyzer" : "ik_max_word",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
}
},
"analyzer" : "ik_max_word"
},
"score" : {
"type" : "double"
},
"sort" : {
"type" : "long"
},
"tags" : {
"type" : "text",
"fields" : {
"origin" : {
"type" : "keyword"
},
"pinyin" : {
"type" : "text",
"term_vector" : "with_positions_offsets",
"analyzer" : "ik_pinyin_analyzer"
},
"suggest" : {
"type" : "completion",
"analyzer" : "ik_max_word",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
}
},
"analyzer" : "ik_max_word"
},
"type" : {
"type" : "integer"
},
"updateTime" : {
"type" : "date"
},
"userId" : {
"type" : "long"
},
"uuid" : {
"type" : "keyword"
},
"viewTotal" : {
"type" : "long"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : "1",
"provided_name" : "db_test",
"creation_date" : "1514353694378",
"analysis" : {
"filter" : {
"mix_pinyin" : {
"lowercase" : "true",
"padding_char" : " ",
"first_letter" : "prefix",
"keep_original" : "true",
"remove_duplicated_term" : "true",
"type" : "pinyin",
"keep_full_pinyin" : "true"
}
},
"analyzer" : {
"ik_pinyin_analyzer" : {
"filter" : [
"mix_pinyin",
"word_delimiter"
],
"type" : "custom",
"tokenizer" : "ik_max_word"
},
"default" : {
"tokenizer" : "ik_max_word"
}
}
},
"number_of_replicas" : "1",
"uuid" : "seg7yr55R121l8tRW3r7uA",
"version" : {
"created" : "6000099"
}
}
}
}
}