Elasticsearch(5.x) Template的使用

官方模板定义
Dynamic templates

template字段用来匹配索引名字
keyword是String的一种子类型,说明字段是not not_analyzed
使用的时候将//开头的两行注释去掉

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
PUT /_template/template1
{
"order": 0,
"template": "index*",
"mappings": {
"_default_": {
"dynamic_templates": [

//针对特别字段进行定义
{
"long_to_date": {
"mapping": {
"doc_values": true,
"type": "date"
},
"match": "dt",
"match_mapping_type": "long"
}
},

//以下是通用字段定义
{
"long2integer": {
"mapping": {
"doc_values": true,
"type": "integer"
},
"match": "*",
"unmatch":"dt",
"match_mapping_type": "long"
}
},
{
"string2keyword": {
"mapping": {
"index": "not_analyzed",
"omit_norms": true,
"doc_values": true,
"type": "keyword"
},
"match": "*",
"match_mapping_type": "string"
}
},

{
"date": {
"mapping": {
"doc_values": true,
"type": "date",
"format":"strict_date_optional_time||epoch_millis"
},
"match": "*",
"match_mapping_type": "date"
}
}

],
"_all": {
"enabled": false
}
}
}
}

Share