Skip to content

Commit b9eba78

Browse files
author
Gavin Williams
committed
Improve handling of Index templates across ES versions.
1 parent ab6c1be commit b9eba78

File tree

6 files changed

+71
-117
lines changed

6 files changed

+71
-117
lines changed

spec/fixtures/templates/post_6.0.json renamed to spec/fixtures/templates/6.x.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
}
5757
}
5858
}
59-
}
59+
}

spec/fixtures/templates/7.x.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"index_patterns": [ "logstash-*" ],
3+
"version": 123,
4+
"settings": {
5+
"index": {
6+
"refresh_interval": "5s",
7+
"analysis": {
8+
"analyzer": {
9+
"default": {
10+
"type": "standard",
11+
"stopwords": "_none_"
12+
}
13+
}
14+
}
15+
}
16+
},
17+
"mappings": {
18+
"dynamic_templates": [
19+
{
20+
"string_fields": {
21+
"match": "*",
22+
"match_mapping_type": "string",
23+
"mapping": {
24+
"type": "multi_field",
25+
"fields": {
26+
"{name}": {
27+
"type": "text",
28+
"index": "analyzed",
29+
"omit_norms": true
30+
},
31+
"raw": {
32+
"type ": "text",
33+
"index": "not_analyzed",
34+
"ignore_above": 256
35+
}
36+
}
37+
}
38+
}
39+
}
40+
]
41+
}
42+
}
Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,30 @@
11
{
2-
"index_patterns": [ "logstash-*" ],
3-
"version": 123,
4-
"settings": {
5-
"index": {
6-
"refresh_interval": "5s",
7-
"analysis": {
8-
"analyzer": {
9-
"default": {
10-
"type": "standard",
11-
"stopwords": "_none_"
12-
}
13-
}
14-
}
15-
}
16-
},
17-
"mappings": {
18-
"dynamic_templates": [
19-
{
20-
"string_fields": {
21-
"match": "*",
22-
"match_mapping_type": "string",
23-
"mapping": {
24-
"type": "multi_field",
25-
"fields": {
26-
"{name}": {
27-
"type": "text",
28-
"index": "analyzed",
29-
"omit_norms": true
30-
},
31-
"raw": {
32-
"type ": "text",
33-
"index": "not_analyzed",
34-
"ignore_above": 256
35-
}
36-
}
37-
}
38-
}
39-
}
40-
],
41-
"properties": {
42-
"@version": {
43-
"type": "text",
44-
"index": false
2+
"index_patterns": ["te*", "bar*"],
3+
"template": {
4+
"settings": {
5+
"number_of_shards": 1
6+
},
7+
"mappings": {
8+
"_source": {
9+
"enabled": false
4510
},
46-
"geoip": {
47-
"type": "object",
48-
"dynamic": true,
49-
"properties": {
50-
"location": {
51-
"type": "geo_point"
52-
}
11+
"properties": {
12+
"host_name": {
13+
"type": "keyword"
14+
},
15+
"created_at": {
16+
"type": "date",
17+
"format": "EEE MMM dd HH:mm:ss Z yyyy"
5318
}
5419
}
20+
},
21+
"aliases": {
22+
"mydata": { }
5523
}
24+
},
25+
"priority": 10,
26+
"version": 3,
27+
"_meta": {
28+
"description": "my custom"
5629
}
57-
}
30+
}

spec/fixtures/templates/pre_6.0.json

Lines changed: 0 additions & 61 deletions
This file was deleted.

spec/spec_helper_acceptance.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
v[:elasticsearch_full_version] = ENV['ELASTICSEARCH_VERSION'] || v[:snapshot_version]
3737
v[:elasticsearch_major_version] = v[:elasticsearch_full_version].split('.').first.to_i
3838
v[:elasticsearch_package] = {}
39-
v[:template] = if v[:elasticsearch_major_version] < 6
40-
JSON.load(File.new('spec/fixtures/templates/pre_6.0.json'))
39+
v[:template] = if v[:elasticsearch_major_version] == 6
40+
JSON.load(File.new('spec/fixtures/templates/6.x.json'))
4141
elsif v[:elasticsearch_major_version] >= 8
4242
JSON.load(File.new('spec/fixtures/templates/post_8.0.json'))
4343
else
44-
JSON.load(File.new('spec/fixtures/templates/post_6.0.json'))
44+
JSON.load(File.new('spec/fixtures/templates/7.x.json'))
4545
end
4646
v[:template] = Puppet_X::Elastic.deep_to_i(Puppet_X::Elastic.deep_to_s(v[:template]))
4747
v[:pipeline] = JSON.load(File.new('spec/fixtures/pipelines/example.json'))

spec/unit/type/elasticsearch_template_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def deep_stringify(obj)
115115
obj.to_s
116116
end
117117
end
118-
json = JSON.parse(File.read('spec/fixtures/templates/post_6.0.json'))
118+
json = JSON.parse(File.read('spec/fixtures/templates/6.x.json'))
119119

120120
is_template = described_class.new(
121121
:name => resource_name,

0 commit comments

Comments
 (0)