|
1 | 1 | require_relative "../../../spec/es_spec_helper" |
2 | 2 | require "logstash/outputs/elasticsearch" |
3 | 3 |
|
4 | | -if ESHelper.es_version_satisfies?("<= 5.x") |
5 | | - context "when using elasticsearch 5.x and before", :integration => true do |
6 | | - shared_examples "a type based parent indexer" do |
7 | | - let(:index) { 10.times.collect { rand(10).to_s }.join("") } |
8 | | - let(:type) { 10.times.collect { rand(10).to_s }.join("") } |
9 | | - let(:event_count) { 10000 + rand(500) } |
10 | | - let(:parent) { "not_implemented" } |
11 | | - let(:config) { "not_implemented" } |
12 | | - let(:default_headers) { |
13 | | - {"Content-Type" => "application/json"} |
14 | | - } |
15 | | - subject { LogStash::Outputs::ElasticSearch.new(config) } |
16 | | - |
17 | | - before do |
18 | | - # Add mapping and a parent document |
19 | | - index_url = "http://#{get_host_port()}/#{index}" |
20 | | - mapping = { "mappings" => { "#{type}" => { "_parent" => { "type" => "#{type}_parent" } } } } |
21 | | - Manticore.put("#{index_url}", {:body => mapping.to_json, :headers => default_headers}).call |
22 | | - pdoc = { "foo" => "bar" } |
23 | | - Manticore.put("#{index_url}/#{type}_parent/test", {:body => pdoc.to_json, :headers => default_headers}).call |
24 | | - |
25 | | - subject.register |
26 | | - subject.multi_receive(event_count.times.map { LogStash::Event.new("link_to" => "test", "message" => "Hello World!", "type" => type) }) |
27 | | - end |
28 | | - |
29 | | - |
30 | | - it "ships events" do |
31 | | - index_url = "http://#{get_host_port()}/#{index}" |
32 | | - |
33 | | - Manticore.post("#{index_url}/_refresh").call |
34 | | - |
35 | | - # Wait until all events are available. |
36 | | - Stud::try(10.times) do |
37 | | - query = { "query" => { "has_parent" => { "type" => "#{type}_parent", "query" => { "match" => { "foo" => "bar" } } } } } |
38 | | - response = Manticore.post("#{index_url}/_count", {:body => query.to_json, :headers => default_headers}) |
39 | | - data = response.body |
40 | | - result = LogStash::Json.load(data) |
41 | | - cur_count = result["count"] |
42 | | - expect(cur_count).to eq(event_count) |
43 | | - end |
44 | | - end |
45 | | - end |
46 | | - |
47 | | - describe "(http protocol) index events with static parent" do |
48 | | - it_behaves_like 'a type based parent indexer' do |
49 | | - let(:parent) { "test" } |
50 | | - let(:config) { |
51 | | - { |
52 | | - "hosts" => get_host_port, |
53 | | - "index" => index, |
54 | | - "parent" => parent |
55 | | - } |
56 | | - } |
57 | | - end |
58 | | - end |
59 | | - |
60 | | - describe "(http_protocol) index events with fieldref in parent value" do |
61 | | - it_behaves_like 'a type based parent indexer' do |
62 | | - let(:config) { |
63 | | - { |
64 | | - "hosts" => get_host_port, |
65 | | - "index" => index, |
66 | | - "parent" => "%{link_to}" |
67 | | - } |
68 | | - } |
69 | | - end |
70 | | - end |
71 | | - end |
72 | | -end |
73 | | - |
74 | 4 | if ESHelper.es_version_satisfies?(">= 5.6") |
75 | 5 | context "when using elasticsearch 5.6 and above", :integration => true do |
76 | 6 |
|
|
0 commit comments