From b9eba78832894d5bf517507fcdd4ead77ee583e7 Mon Sep 17 00:00:00 2001 From: Gavin Williams Date: Thu, 18 Jun 2020 14:50:04 +0100 Subject: [PATCH] Improve handling of Index templates across ES versions. --- .../templates/{post_6.0.json => 6.x.json} | 2 +- spec/fixtures/templates/7.x.json | 42 +++++++++++ spec/fixtures/templates/post_8.0.json | 75 ++++++------------- spec/fixtures/templates/pre_6.0.json | 61 --------------- spec/spec_helper_acceptance.rb | 6 +- spec/unit/type/elasticsearch_template_spec.rb | 2 +- 6 files changed, 71 insertions(+), 117 deletions(-) rename spec/fixtures/templates/{post_6.0.json => 6.x.json} (99%) create mode 100644 spec/fixtures/templates/7.x.json delete mode 100644 spec/fixtures/templates/pre_6.0.json diff --git a/spec/fixtures/templates/post_6.0.json b/spec/fixtures/templates/6.x.json similarity index 99% rename from spec/fixtures/templates/post_6.0.json rename to spec/fixtures/templates/6.x.json index e118ec181..e1f9ba10c 100644 --- a/spec/fixtures/templates/post_6.0.json +++ b/spec/fixtures/templates/6.x.json @@ -56,4 +56,4 @@ } } } -} +} \ No newline at end of file diff --git a/spec/fixtures/templates/7.x.json b/spec/fixtures/templates/7.x.json new file mode 100644 index 000000000..54569e0f4 --- /dev/null +++ b/spec/fixtures/templates/7.x.json @@ -0,0 +1,42 @@ +{ + "index_patterns": [ "logstash-*" ], + "version": 123, + "settings": { + "index": { + "refresh_interval": "5s", + "analysis": { + "analyzer": { + "default": { + "type": "standard", + "stopwords": "_none_" + } + } + } + } + }, + "mappings": { + "dynamic_templates": [ + { + "string_fields": { + "match": "*", + "match_mapping_type": "string", + "mapping": { + "type": "multi_field", + "fields": { + "{name}": { + "type": "text", + "index": "analyzed", + "omit_norms": true + }, + "raw": { + "type ": "text", + "index": "not_analyzed", + "ignore_above": 256 + } + } + } + } + } + ] + } +} \ No newline at end of file diff --git a/spec/fixtures/templates/post_8.0.json b/spec/fixtures/templates/post_8.0.json index db8c484db..91cade100 100644 --- a/spec/fixtures/templates/post_8.0.json +++ b/spec/fixtures/templates/post_8.0.json @@ -1,57 +1,30 @@ { - "index_patterns": [ "logstash-*" ], - "version": 123, - "settings": { - "index": { - "refresh_interval": "5s", - "analysis": { - "analyzer": { - "default": { - "type": "standard", - "stopwords": "_none_" - } - } - } - } - }, - "mappings": { - "dynamic_templates": [ - { - "string_fields": { - "match": "*", - "match_mapping_type": "string", - "mapping": { - "type": "multi_field", - "fields": { - "{name}": { - "type": "text", - "index": "analyzed", - "omit_norms": true - }, - "raw": { - "type ": "text", - "index": "not_analyzed", - "ignore_above": 256 - } - } - } - } - } - ], - "properties": { - "@version": { - "type": "text", - "index": false + "index_patterns": ["te*", "bar*"], + "template": { + "settings": { + "number_of_shards": 1 + }, + "mappings": { + "_source": { + "enabled": false }, - "geoip": { - "type": "object", - "dynamic": true, - "properties": { - "location": { - "type": "geo_point" - } + "properties": { + "host_name": { + "type": "keyword" + }, + "created_at": { + "type": "date", + "format": "EEE MMM dd HH:mm:ss Z yyyy" } } + }, + "aliases": { + "mydata": { } } + }, + "priority": 10, + "version": 3, + "_meta": { + "description": "my custom" } -} +} \ No newline at end of file diff --git a/spec/fixtures/templates/pre_6.0.json b/spec/fixtures/templates/pre_6.0.json deleted file mode 100644 index 38a237986..000000000 --- a/spec/fixtures/templates/pre_6.0.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "template": "logstash-*", - "settings": { - "index": { - "refresh_interval": "5s", - "analysis": { - "analyzer": { - "default": { - "type": "standard", - "stopwords": "_none_" - } - } - } - } - }, - "mappings": { - "_default_": { - "_all": { - "enabled": true - }, - "dynamic_templates": [ - { - "string_fields": { - "match": "*", - "match_mapping_type": "string", - "mapping": { - "type": "multi_field", - "fields": { - "{name}": { - "type": "string", - "index": "analyzed", - "omit_norms": true - }, - "raw": { - "type ": "string", - "index": "not_analyzed", - "ignore_above": 256 - } - } - } - } - } - ], - "properties": { - "@version": { - "type": "string", - "index": "not_analyzed" - }, - "geoip": { - "type": "object", - "dynamic": true, - "properties": { - "location": { - "type": "geo_point" - } - } - } - } - } - } -} diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e22289a7c..7a11b60e1 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -36,12 +36,12 @@ v[:elasticsearch_full_version] = ENV['ELASTICSEARCH_VERSION'] || v[:snapshot_version] v[:elasticsearch_major_version] = v[:elasticsearch_full_version].split('.').first.to_i v[:elasticsearch_package] = {} - v[:template] = if v[:elasticsearch_major_version] < 6 - JSON.load(File.new('spec/fixtures/templates/pre_6.0.json')) + v[:template] = if v[:elasticsearch_major_version] == 6 + JSON.load(File.new('spec/fixtures/templates/6.x.json')) elsif v[:elasticsearch_major_version] >= 8 JSON.load(File.new('spec/fixtures/templates/post_8.0.json')) else - JSON.load(File.new('spec/fixtures/templates/post_6.0.json')) + JSON.load(File.new('spec/fixtures/templates/7.x.json')) end v[:template] = Puppet_X::Elastic.deep_to_i(Puppet_X::Elastic.deep_to_s(v[:template])) v[:pipeline] = JSON.load(File.new('spec/fixtures/pipelines/example.json')) diff --git a/spec/unit/type/elasticsearch_template_spec.rb b/spec/unit/type/elasticsearch_template_spec.rb index 0d50347a5..abeabf0e3 100644 --- a/spec/unit/type/elasticsearch_template_spec.rb +++ b/spec/unit/type/elasticsearch_template_spec.rb @@ -115,7 +115,7 @@ def deep_stringify(obj) obj.to_s end end - json = JSON.parse(File.read('spec/fixtures/templates/post_6.0.json')) + json = JSON.parse(File.read('spec/fixtures/templates/6.x.json')) is_template = described_class.new( :name => resource_name,