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
192
193
194
195
196
197
198
199
200
201
202
203
|
#Create a default template
PUT _template/template_default
{
"index_patterns": ["*"],
"order" : 0,
"version": 1,
"settings": {
"number_of_shards": 1,
"number_of_replicas":1
}
}
PUT _template/template_test
{
"index_patterns" : ["test*"],
"order" : 1,
"settings" : {
"number_of_shards": 1,
"number_of_replicas" : 2
},
"mappings" : {
"date_detection": false,
"numeric_detection": true
}
}
#查看template信息
GET /_template/template_default
# 返回如下:
{
"template_default" : {
"order" : 0,
"version" : 1,
"index_patterns" : [
"*"
],
"settings" : {
"index" : {
"number_of_shards" : "1",
"number_of_replicas" : "1"
}
},
"mappings" : { },
"aliases" : { }
}
}
#使用通配符查看template信息
GET /_template/temp*
{
"template_test" : {
"order" : 1,
"index_patterns" : [
"test*"
],
"settings" : {
"index" : {
"number_of_shards" : "1",
"number_of_replicas" : "2"
}
},
"mappings" : {
"numeric_detection" : true,
"date_detection" : false
},
"aliases" : { }
},
"template_default" : {
"order" : 0,
"version" : 1,
"index_patterns" : [
"*"
],
"settings" : {
"index" : {
"number_of_shards" : "1",
"number_of_replicas" : "1"
}
},
"mappings" : { },
"aliases" : { }
}
}
#数字字符串被映射成text,日期字符串被映射成日期
PUT ttemplate/_doc/1
{
"someNumber":"1",
"someDate":"2019/01/01"
}
GET ttemplate/_mapping
#返回如下:
{
"ttemplate" : {
"mappings" : {
"properties" : {
"someDate" : {
"type" : "date",
"format" : "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
},
"someNumber" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
#写入新的数据,index以test开头
PUT testtemplate/_doc/1
{
"someNumber":"1",
"someDate":"2019/01/01"
}
GET testtemplate/_mapping
#返回如下:
{
"testtemplate" : {
"mappings" : {
"date_detection" : false,
"numeric_detection" : true,
"properties" : {
"someDate" : { #可以看到这里并没有命中字段类型日期匹配
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"someNumber" : {
"type" : "long"
}
}
}
}
}
get testtemplate/_settings
#返回如下:
{
"testtemplate" : {
"settings" : {
"index" : {
"creation_date" : "1646703465756",
"number_of_shards" : "1",
"number_of_replicas" : "2",
"uuid" : "wLIqiv5VToSVKctGSbT1Kg",
"version" : {
"created" : "7010099"
},
"provided_name" : "testtemplate"
}
}
}
}
PUT testmy
{
"settings":{
"number_of_replicas":5
}
}
put testmy/_doc/1
{
"key":"value"
}
get testmy/_settings
#返回如下
{
"testmy" : {
"settings" : {
"index" : {
"creation_date" : "1646703533380",
"number_of_shards" : "1",
"number_of_replicas" : "5", #可以看到模板被覆盖
"uuid" : "EAS7QZZtSTGcYSN-8MlEEA",
"version" : {
"created" : "7010099"
},
"provided_name" : "testmy"
}
}
}
}
|