logstash-output-elasticsearch 8.1.1-java → 8.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,7 +38,10 @@ describe "pool sniffer", :integration => true do
38
38
  end
39
39
 
40
40
  # We do a more thorough check on these versions because we can more reliably guess the ip
41
- describe("Complex sniff parsing ES 6x/5x/2x", :version_greater_than_equal_to_2x => true) do
42
- include_examples("sniff parsing", true)
41
+
42
+ if ESHelper.es_version_satisfies?(">= 2")
43
+ describe("Complex sniff parsing ES 6x/5x/2x") do
44
+ include_examples("sniff parsing", true)
45
+ end
43
46
  end
44
47
  end
@@ -1,99 +1,98 @@
1
1
  require_relative "../../../spec/es_spec_helper"
2
2
 
3
- # This file is a copy of template test for 2.x. We can DRY this up later.
4
- describe "index template expected behavior for 5.x", :integration => true, :version_greater_than_equal_to_5x => true do
5
- subject! do
6
- require "logstash/outputs/elasticsearch"
7
- settings = {
8
- "manage_template" => true,
9
- "template_overwrite" => true,
10
- "hosts" => "#{get_host_port()}"
11
- }
12
- next LogStash::Outputs::ElasticSearch.new(settings)
13
- end
14
-
15
- before :each do
16
- # Delete all templates first.
17
- require "elasticsearch"
18
-
19
- # Clean ES of data before we start.
20
- @es = get_client
21
- @es.indices.delete_template(:name => "*")
22
-
23
- # This can fail if there are no indexes, ignore failure.
24
- @es.indices.delete(:index => "*") rescue nil
25
-
26
- subject.register
27
-
28
- subject.multi_receive([
29
- LogStash::Event.new("message" => "sample message here"),
30
- LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
31
- LogStash::Event.new("somevalue" => 100),
32
- LogStash::Event.new("somevalue" => 10),
33
- LogStash::Event.new("somevalue" => 1),
34
- LogStash::Event.new("country" => "us"),
35
- LogStash::Event.new("country" => "at"),
36
- LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
37
- ])
38
-
39
- @es.indices.refresh
3
+ if ESHelper.es_version_satisfies?(">= 5")
4
+ describe "index template expected behavior for 5.x", :integration => true do
5
+ subject! do
6
+ require "logstash/outputs/elasticsearch"
7
+ settings = {
8
+ "manage_template" => true,
9
+ "template_overwrite" => true,
10
+ "hosts" => "#{get_host_port()}"
11
+ }
12
+ next LogStash::Outputs::ElasticSearch.new(settings)
13
+ end
40
14
 
41
- # Wait or fail until everything's indexed.
42
- Stud::try(20.times) do
43
- r = @es.search
44
- insist { r["hits"]["total"] } == 8
15
+ before :each do
16
+ # Delete all templates first.
17
+ require "elasticsearch"
18
+
19
+ # Clean ES of data before we start.
20
+ @es = get_client
21
+ @es.indices.delete_template(:name => "*")
22
+
23
+ # This can fail if there are no indexes, ignore failure.
24
+ @es.indices.delete(:index => "*") rescue nil
25
+
26
+ subject.register
27
+
28
+ subject.multi_receive([
29
+ LogStash::Event.new("message" => "sample message here"),
30
+ LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
31
+ LogStash::Event.new("somevalue" => 100),
32
+ LogStash::Event.new("somevalue" => 10),
33
+ LogStash::Event.new("somevalue" => 1),
34
+ LogStash::Event.new("country" => "us"),
35
+ LogStash::Event.new("country" => "at"),
36
+ LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
37
+ ])
38
+
39
+ @es.indices.refresh
40
+
41
+ # Wait or fail until everything's indexed.
42
+ Stud::try(20.times) do
43
+ r = @es.search
44
+ insist { r["hits"]["total"] } == 8
45
+ end
45
46
  end
46
- end
47
47
 
48
- it "permits phrase searching on string fields" do
49
- results = @es.search(:q => "message:\"sample message\"")
50
- insist { results["hits"]["total"] } == 1
51
- insist { results["hits"]["hits"][0]["_source"]["message"] } == "sample message here"
52
- end
48
+ it "permits phrase searching on string fields" do
49
+ results = @es.search(:q => "message:\"sample message\"")
50
+ insist { results["hits"]["total"] } == 1
51
+ insist { results["hits"]["hits"][0]["_source"]["message"] } == "sample message here"
52
+ end
53
53
 
54
- it "numbers dynamically map to a numeric type and permit range queries" do
55
- results = @es.search(:q => "somevalue:[5 TO 105]")
56
- insist { results["hits"]["total"] } == 2
54
+ it "numbers dynamically map to a numeric type and permit range queries" do
55
+ results = @es.search(:q => "somevalue:[5 TO 105]")
56
+ insist { results["hits"]["total"] } == 2
57
57
 
58
- values = results["hits"]["hits"].collect { |r| r["_source"]["somevalue"] }
59
- insist { values }.include?(10)
60
- insist { values }.include?(100)
61
- reject { values }.include?(1)
62
- end
58
+ values = results["hits"]["hits"].collect { |r| r["_source"]["somevalue"] }
59
+ insist { values }.include?(10)
60
+ insist { values }.include?(100)
61
+ reject { values }.include?(1)
62
+ end
63
63
 
64
- it "does not create .keyword field for top-level message field" do
65
- results = @es.search(:q => "message.keyword:\"sample message here\"")
66
- insist { results["hits"]["total"] } == 0
67
- end
64
+ it "does not create .keyword field for top-level message field" do
65
+ results = @es.search(:q => "message.keyword:\"sample message here\"")
66
+ insist { results["hits"]["total"] } == 0
67
+ end
68
68
 
69
- it "creates .keyword field for nested message fields" do
70
- results = @es.search(:q => "somemessage.message.keyword:\"sample nested message here\"")
71
- insist { results["hits"]["total"] } == 1
72
- end
69
+ it "creates .keyword field for nested message fields" do
70
+ results = @es.search(:q => "somemessage.message.keyword:\"sample nested message here\"")
71
+ insist { results["hits"]["total"] } == 1
72
+ end
73
73
 
74
- it "creates .keyword field from any string field which is not_analyzed" do
75
- results = @es.search(:q => "country.keyword:\"us\"")
76
- insist { results["hits"]["total"] } == 1
77
- insist { results["hits"]["hits"][0]["_source"]["country"] } == "us"
74
+ it "creates .keyword field from any string field which is not_analyzed" do
75
+ results = @es.search(:q => "country.keyword:\"us\"")
76
+ insist { results["hits"]["total"] } == 1
77
+ insist { results["hits"]["hits"][0]["_source"]["country"] } == "us"
78
78
 
79
- # partial or terms should not work.
80
- results = @es.search(:q => "country.keyword:\"u\"")
81
- insist { results["hits"]["total"] } == 0
82
- end
79
+ # partial or terms should not work.
80
+ results = @es.search(:q => "country.keyword:\"u\"")
81
+ insist { results["hits"]["total"] } == 0
82
+ end
83
83
 
84
- it "make [geoip][location] a geo_point" do
85
- expect(@es.indices.get_template(name: "logstash")["logstash"]["mappings"]["_default_"]["properties"]["geoip"]["properties"]["location"]["type"]).to eq("geo_point")
86
- end
84
+ it "make [geoip][location] a geo_point" do
85
+ expect(@es.indices.get_template(name: "logstash")["logstash"]["mappings"]["_default_"]["properties"]["geoip"]["properties"]["location"]["type"]).to eq("geo_point")
86
+ end
87
87
 
88
- it "aggregate .keyword results correctly " do
89
- results = @es.search(:body => { "aggregations" => { "my_agg" => { "terms" => { "field" => "country.keyword" } } } })["aggregations"]["my_agg"]
90
- terms = results["buckets"].collect { |b| b["key"] }
88
+ it "aggregate .keyword results correctly " do
89
+ results = @es.search(:body => { "aggregations" => { "my_agg" => { "terms" => { "field" => "country.keyword" } } } })["aggregations"]["my_agg"]
90
+ terms = results["buckets"].collect { |b| b["key"] }
91
91
 
92
- insist { terms }.include?("us")
92
+ insist { terms }.include?("us")
93
93
 
94
- # 'at' is a stopword, make sure stopwords are not ignored.
95
- insist { terms }.include?("at")
94
+ # 'at' is a stopword, make sure stopwords are not ignored.
95
+ insist { terms }.include?("at")
96
+ end
96
97
  end
97
98
  end
98
-
99
-
@@ -1,98 +1,98 @@
1
1
  require_relative "../../../spec/es_spec_helper"
2
2
 
3
- describe "index template expected behavior", :integration => true, :version_less_than_5x => true do
4
- subject! do
5
- require "logstash/outputs/elasticsearch"
6
- settings = {
7
- "manage_template" => true,
8
- "template_overwrite" => true,
9
- "hosts" => "#{get_host_port()}"
10
- }
11
- next LogStash::Outputs::ElasticSearch.new(settings)
12
- end
13
-
14
- before :each do
15
- # Delete all templates first.
16
- require "elasticsearch"
17
-
18
- # Clean ES of data before we start.
19
- @es = get_client
20
- @es.indices.delete_template(:name => "*")
21
-
22
- # This can fail if there are no indexes, ignore failure.
23
- @es.indices.delete(:index => "*") rescue nil
24
-
25
- subject.register
26
-
27
- subject.multi_receive([
28
- LogStash::Event.new("message" => "sample message here"),
29
- LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
30
- LogStash::Event.new("somevalue" => 100),
31
- LogStash::Event.new("somevalue" => 10),
32
- LogStash::Event.new("somevalue" => 1),
33
- LogStash::Event.new("country" => "us"),
34
- LogStash::Event.new("country" => "at"),
35
- LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
36
- ])
37
-
38
- @es.indices.refresh
3
+ if ESHelper.es_version_satisfies?("< 5")
4
+ describe "index template expected behavior", :integration => true do
5
+ subject! do
6
+ require "logstash/outputs/elasticsearch"
7
+ settings = {
8
+ "manage_template" => true,
9
+ "template_overwrite" => true,
10
+ "hosts" => "#{get_host_port()}"
11
+ }
12
+ next LogStash::Outputs::ElasticSearch.new(settings)
13
+ end
39
14
 
40
- # Wait or fail until everything's indexed.
41
- Stud::try(20.times) do
42
- r = @es.search
43
- insist { r["hits"]["total"] } == 8
15
+ before :each do
16
+ # Delete all templates first.
17
+ require "elasticsearch"
18
+
19
+ # Clean ES of data before we start.
20
+ @es = get_client
21
+ @es.indices.delete_template(:name => "*")
22
+
23
+ # This can fail if there are no indexes, ignore failure.
24
+ @es.indices.delete(:index => "*") rescue nil
25
+
26
+ subject.register
27
+
28
+ subject.multi_receive([
29
+ LogStash::Event.new("message" => "sample message here"),
30
+ LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
31
+ LogStash::Event.new("somevalue" => 100),
32
+ LogStash::Event.new("somevalue" => 10),
33
+ LogStash::Event.new("somevalue" => 1),
34
+ LogStash::Event.new("country" => "us"),
35
+ LogStash::Event.new("country" => "at"),
36
+ LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
37
+ ])
38
+
39
+ @es.indices.refresh
40
+
41
+ # Wait or fail until everything's indexed.
42
+ Stud::try(20.times) do
43
+ r = @es.search
44
+ insist { r["hits"]["total"] } == 8
45
+ end
44
46
  end
45
- end
46
47
 
47
- it "permits phrase searching on string fields" do
48
- results = @es.search(:q => "message:\"sample message\"")
49
- insist { results["hits"]["total"] } == 1
50
- insist { results["hits"]["hits"][0]["_source"]["message"] } == "sample message here"
51
- end
48
+ it "permits phrase searching on string fields" do
49
+ results = @es.search(:q => "message:\"sample message\"")
50
+ insist { results["hits"]["total"] } == 1
51
+ insist { results["hits"]["hits"][0]["_source"]["message"] } == "sample message here"
52
+ end
52
53
 
53
- it "numbers dynamically map to a numeric type and permit range queries" do
54
- results = @es.search(:q => "somevalue:[5 TO 105]")
55
- insist { results["hits"]["total"] } == 2
54
+ it "numbers dynamically map to a numeric type and permit range queries" do
55
+ results = @es.search(:q => "somevalue:[5 TO 105]")
56
+ insist { results["hits"]["total"] } == 2
56
57
 
57
- values = results["hits"]["hits"].collect { |r| r["_source"]["somevalue"] }
58
- insist { values }.include?(10)
59
- insist { values }.include?(100)
60
- reject { values }.include?(1)
61
- end
58
+ values = results["hits"]["hits"].collect { |r| r["_source"]["somevalue"] }
59
+ insist { values }.include?(10)
60
+ insist { values }.include?(100)
61
+ reject { values }.include?(1)
62
+ end
62
63
 
63
- it "does not create .raw field for the message field" do
64
- results = @es.search(:q => "message.raw:\"sample message here\"")
65
- insist { results["hits"]["total"] } == 0
66
- end
64
+ it "does not create .raw field for the message field" do
65
+ results = @es.search(:q => "message.raw:\"sample message here\"")
66
+ insist { results["hits"]["total"] } == 0
67
+ end
67
68
 
68
- it "creates .raw field for nested message fields" do
69
- results = @es.search(:q => "somemessage.message.raw:\"sample nested message here\"")
70
- insist { results["hits"]["total"] } == 1
71
- end
69
+ it "creates .raw field for nested message fields" do
70
+ results = @es.search(:q => "somemessage.message.raw:\"sample nested message here\"")
71
+ insist { results["hits"]["total"] } == 1
72
+ end
72
73
 
73
- it "creates .raw field from any string field which is not_analyzed" do
74
- results = @es.search(:q => "country.raw:\"us\"")
75
- insist { results["hits"]["total"] } == 1
76
- insist { results["hits"]["hits"][0]["_source"]["country"] } == "us"
74
+ it "creates .raw field from any string field which is not_analyzed" do
75
+ results = @es.search(:q => "country.raw:\"us\"")
76
+ insist { results["hits"]["total"] } == 1
77
+ insist { results["hits"]["hits"][0]["_source"]["country"] } == "us"
77
78
 
78
- # partial or terms should not work.
79
- results = @es.search(:q => "country.raw:\"u\"")
80
- insist { results["hits"]["total"] } == 0
81
- end
79
+ # partial or terms should not work.
80
+ results = @es.search(:q => "country.raw:\"u\"")
81
+ insist { results["hits"]["total"] } == 0
82
+ end
82
83
 
83
- it "make [geoip][location] a geo_point" do
84
- expect(@es.indices.get_template(name: "logstash")["logstash"]["mappings"]["_default_"]["properties"]["geoip"]["properties"]["location"]["type"]).to eq("geo_point")
85
- end
84
+ it "make [geoip][location] a geo_point" do
85
+ expect(@es.indices.get_template(name: "logstash")["logstash"]["mappings"]["_default_"]["properties"]["geoip"]["properties"]["location"]["type"]).to eq("geo_point")
86
+ end
86
87
 
87
- it "aggregate .raw results correctly " do
88
- results = @es.search(:body => { "aggregations" => { "my_agg" => { "terms" => { "field" => "country.raw" } } } })["aggregations"]["my_agg"]
89
- terms = results["buckets"].collect { |b| b["key"] }
88
+ it "aggregate .raw results correctly " do
89
+ results = @es.search(:body => { "aggregations" => { "my_agg" => { "terms" => { "field" => "country.raw" } } } })["aggregations"]["my_agg"]
90
+ terms = results["buckets"].collect { |b| b["key"] }
90
91
 
91
- insist { terms }.include?("us")
92
+ insist { terms }.include?("us")
92
93
 
93
- # 'at' is a stopword, make sure stopwords are not ignored.
94
- insist { terms }.include?("at")
94
+ # 'at' is a stopword, make sure stopwords are not ignored.
95
+ insist { terms }.include?("at")
96
+ end
95
97
  end
96
98
  end
97
-
98
-
@@ -1,114 +1,116 @@
1
1
  require_relative "../../../spec/es_spec_helper"
2
2
 
3
- describe "Update actions without scripts", :integration => true, :version_greater_than_equal_to_2x => true do
4
- require "logstash/outputs/elasticsearch"
5
-
6
- def get_es_output( options={} )
7
- settings = {
8
- "manage_template" => true,
9
- "index" => "logstash-update",
10
- "template_overwrite" => true,
11
- "hosts" => get_host_port(),
12
- "action" => "update"
13
- }
14
- LogStash::Outputs::ElasticSearch.new(settings.merge!(options))
15
- end
16
-
17
- before :each do
18
- @es = get_client
19
- # Delete all templates first.
20
- # Clean ES of data before we start.
21
- @es.indices.delete_template(:name => "*")
22
- # This can fail if there are no indexes, ignore failure.
23
- @es.indices.delete(:index => "*") rescue nil
24
- @es.index(
25
- :index => 'logstash-update',
26
- :type => 'logs',
27
- :id => "123",
28
- :body => { :message => 'Test', :counter => 1 }
29
- )
30
- @es.indices.refresh
31
- end
32
-
33
- it "should fail without a document_id" do
34
- subject = get_es_output
35
- expect { subject.register }.to raise_error(LogStash::ConfigurationError)
36
- end
37
-
38
- context "when update only" do
39
- it "should not create new document" do
40
- subject = get_es_output({ 'document_id' => "456" } )
41
- subject.register
42
- subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
43
- expect {@es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
44
- end
45
-
46
- it "should update existing document" do
47
- subject = get_es_output({ 'document_id' => "123" })
48
- subject.register
49
- subject.multi_receive([LogStash::Event.new("message" => "updated message here")])
50
- r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
51
- insist { r["_source"]["message"] } == 'updated message here'
52
- end
53
-
54
- # The es ruby client treats the data field differently. Make sure this doesn't
55
- # raise an exception
56
- it "should update an existing document that has a 'data' field" do
57
- subject = get_es_output({ 'document_id' => "123" })
58
- subject.register
59
- subject.multi_receive([LogStash::Event.new("data" => "updated message here", "message" => "foo")])
60
- r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
61
- insist { r["_source"]["data"] } == 'updated message here'
62
- insist { r["_source"]["message"] } == 'foo'
63
- end
64
-
65
- it "should allow default (internal) version" do
66
- subject = get_es_output({ 'document_id' => "123", "version" => "99" })
67
- subject.register
3
+ if ESHelper.es_version_satisfies?(">= 2")
4
+ describe "Update actions without scripts", :integration => true do
5
+ require "logstash/outputs/elasticsearch"
6
+
7
+ def get_es_output( options={} )
8
+ settings = {
9
+ "manage_template" => true,
10
+ "index" => "logstash-update",
11
+ "template_overwrite" => true,
12
+ "hosts" => get_host_port(),
13
+ "action" => "update"
14
+ }
15
+ LogStash::Outputs::ElasticSearch.new(settings.merge!(options))
68
16
  end
69
17
 
70
- it "should allow internal version" do
71
- subject = get_es_output({ 'document_id' => "123", "version" => "99", "version_type" => "internal" })
72
- subject.register
18
+ before :each do
19
+ @es = get_client
20
+ # Delete all templates first.
21
+ # Clean ES of data before we start.
22
+ @es.indices.delete_template(:name => "*")
23
+ # This can fail if there are no indexes, ignore failure.
24
+ @es.indices.delete(:index => "*") rescue nil
25
+ @es.index(
26
+ :index => 'logstash-update',
27
+ :type => 'logs',
28
+ :id => "123",
29
+ :body => { :message => 'Test', :counter => 1 }
30
+ )
31
+ @es.indices.refresh
73
32
  end
74
33
 
75
- it "should not allow external version" do
76
- subject = get_es_output({ 'document_id' => "123", "version" => "99", "version_type" => "external" })
34
+ it "should fail without a document_id" do
35
+ subject = get_es_output
77
36
  expect { subject.register }.to raise_error(LogStash::ConfigurationError)
78
37
  end
79
38
 
80
- it "should not allow external_gt version" do
81
- subject = get_es_output({ 'document_id' => "123", "version" => "99", "version_type" => "external_gt" })
82
- expect { subject.register }.to raise_error(LogStash::ConfigurationError)
83
- end
39
+ context "when update only" do
40
+ it "should not create new document" do
41
+ subject = get_es_output({ 'document_id' => "456" } )
42
+ subject.register
43
+ subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
44
+ expect {@es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
45
+ end
46
+
47
+ it "should update existing document" do
48
+ subject = get_es_output({ 'document_id' => "123" })
49
+ subject.register
50
+ subject.multi_receive([LogStash::Event.new("message" => "updated message here")])
51
+ r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
52
+ insist { r["_source"]["message"] } == 'updated message here'
53
+ end
54
+
55
+ # The es ruby client treats the data field differently. Make sure this doesn't
56
+ # raise an exception
57
+ it "should update an existing document that has a 'data' field" do
58
+ subject = get_es_output({ 'document_id' => "123" })
59
+ subject.register
60
+ subject.multi_receive([LogStash::Event.new("data" => "updated message here", "message" => "foo")])
61
+ r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
62
+ insist { r["_source"]["data"] } == 'updated message here'
63
+ insist { r["_source"]["message"] } == 'foo'
64
+ end
65
+
66
+ it "should allow default (internal) version" do
67
+ subject = get_es_output({ 'document_id' => "123", "version" => "99" })
68
+ subject.register
69
+ end
70
+
71
+ it "should allow internal version" do
72
+ subject = get_es_output({ 'document_id' => "123", "version" => "99", "version_type" => "internal" })
73
+ subject.register
74
+ end
75
+
76
+ it "should not allow external version" do
77
+ subject = get_es_output({ 'document_id' => "123", "version" => "99", "version_type" => "external" })
78
+ expect { subject.register }.to raise_error(LogStash::ConfigurationError)
79
+ end
80
+
81
+ it "should not allow external_gt version" do
82
+ subject = get_es_output({ 'document_id' => "123", "version" => "99", "version_type" => "external_gt" })
83
+ expect { subject.register }.to raise_error(LogStash::ConfigurationError)
84
+ end
85
+
86
+ it "should not allow external_gte version" do
87
+ subject = get_es_output({ 'document_id' => "123", "version" => "99", "version_type" => "external_gte" })
88
+ expect { subject.register }.to raise_error(LogStash::ConfigurationError)
89
+ end
84
90
 
85
- it "should not allow external_gte version" do
86
- subject = get_es_output({ 'document_id' => "123", "version" => "99", "version_type" => "external_gte" })
87
- expect { subject.register }.to raise_error(LogStash::ConfigurationError)
88
91
  end
89
92
 
90
- end
91
-
92
- context "when update with upsert" do
93
- it "should create new documents with provided upsert" do
94
- subject = get_es_output({ 'document_id' => "456", 'upsert' => '{"message": "upsert message"}' })
95
- subject.register
96
- subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
97
- r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
98
- insist { r["_source"]["message"] } == 'upsert message'
99
- end
100
-
101
- it "should create new documents with event/doc as upsert" do
102
- subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true })
103
- subject.register
104
- subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
105
- r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
106
- insist { r["_source"]["message"] } == 'sample message here'
107
- end
108
-
109
- it "should fail on documents with event/doc as upsert at external version" do
110
- subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true, 'version' => 999, "version_type" => "external" })
111
- expect { subject.register }.to raise_error(LogStash::ConfigurationError)
93
+ context "when update with upsert" do
94
+ it "should create new documents with provided upsert" do
95
+ subject = get_es_output({ 'document_id' => "456", 'upsert' => '{"message": "upsert message"}' })
96
+ subject.register
97
+ subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
98
+ r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
99
+ insist { r["_source"]["message"] } == 'upsert message'
100
+ end
101
+
102
+ it "should create new documents with event/doc as upsert" do
103
+ subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true })
104
+ subject.register
105
+ subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
106
+ r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
107
+ insist { r["_source"]["message"] } == 'sample message here'
108
+ end
109
+
110
+ it "should fail on documents with event/doc as upsert at external version" do
111
+ subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true, 'version' => 999, "version_type" => "external" })
112
+ expect { subject.register }.to raise_error(LogStash::ConfigurationError)
113
+ end
112
114
  end
113
115
  end
114
116
  end