From 3a7b1521b17e31981703a02e07f1d488aebd0c33 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 17 Jan 2019 15:17:47 -0500 Subject: [PATCH 1/2] Fix tests for 7.x after type removal --- spec/es_spec_helper.rb | 6 +++++- spec/integration/outputs/parent_spec.rb | 10 +++++++++- spec/integration/outputs/templates_5x_spec.rb | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/spec/es_spec_helper.rb b/spec/es_spec_helper.rb index 6e2ea466d..6b049917c 100644 --- a/spec/es_spec_helper.rb +++ b/spec/es_spec_helper.rb @@ -32,11 +32,15 @@ def todays_date def mapping_name if ESHelper.es_version_satisfies?(">=7") - "_doc" + nil else "_default_" end + end + def field_properties_from_template(template_name, field) + mappings = @es.indices.get_template(name: template_name)[template_name]["mappings"] + (mapping_name.nil?) ? mappings["properties"][field]["properties"] : mappings[mapping_name]["properties"][field]["properties"] end def routing_field_name diff --git a/spec/integration/outputs/parent_spec.rb b/spec/integration/outputs/parent_spec.rb index 117ba1b8e..a6bfb38c1 100644 --- a/spec/integration/outputs/parent_spec.rb +++ b/spec/integration/outputs/parent_spec.rb @@ -76,7 +76,15 @@ shared_examples "a join field based parent indexer" do let(:index) { 10.times.collect { rand(10).to_s }.join("") } - let(:type) { 10.times.collect { rand(10).to_s }.join("") } + + let(:type) do + if ESHelper.es_version_satisfies?('<7') + 10.times.collect { rand(10).to_s }.join("") + else + "_doc" + end + end + let(:event_count) { 10000 + rand(500) } let(:parent) { "not_implemented" } let(:config) { "not_implemented" } diff --git a/spec/integration/outputs/templates_5x_spec.rb b/spec/integration/outputs/templates_5x_spec.rb index 2f923a0ed..1959ab73d 100644 --- a/spec/integration/outputs/templates_5x_spec.rb +++ b/spec/integration/outputs/templates_5x_spec.rb @@ -82,7 +82,7 @@ end it "make [geoip][location] a geo_point" do - expect(@es.indices.get_template(name: "logstash")["logstash"]["mappings"][mapping_name]["properties"]["geoip"]["properties"]["location"]["type"]).to eq("geo_point") + expect(field_properties_from_template("logstash", "geoip")["location"]["type"]).to eq("geo_point") end it "aggregate .keyword results correctly " do From d7dd60c10f4fe43e06ccf8b8ef2065e37ad79722 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Tue, 22 Jan 2019 10:46:11 -0500 Subject: [PATCH 2/2] Include suggestions from code review --- spec/es_spec_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/es_spec_helper.rb b/spec/es_spec_helper.rb index 6b049917c..8bd5bf659 100644 --- a/spec/es_spec_helper.rb +++ b/spec/es_spec_helper.rb @@ -30,17 +30,19 @@ def todays_date Time.now.strftime("%Y.%m.%d") end - def mapping_name + + def default_mapping_from_mappings(mappings) if ESHelper.es_version_satisfies?(">=7") - nil + mappings else - "_default_" + mappings["_default_"] end end def field_properties_from_template(template_name, field) mappings = @es.indices.get_template(name: template_name)[template_name]["mappings"] - (mapping_name.nil?) ? mappings["properties"][field]["properties"] : mappings[mapping_name]["properties"][field]["properties"] + mapping = default_mapping_from_mappings(mappings) + mapping["properties"][field]["properties"] end def routing_field_name