es-elasticity 0.11.5 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b90fa843196b6ec0a4ed99f4605d089f1127696a
4
- data.tar.gz: 16e810b1114f1829e21c8e655f2fd7ad40fa1022
3
+ metadata.gz: affbf27c1edb733d94a8e47e2081e15e4f6a1b24
4
+ data.tar.gz: 6cc26c4485266ea6fcac7210cc49204eeaf804bf
5
5
  SHA512:
6
- metadata.gz: 9d54bd8d914de323f3ce7d430e7477eda5b74d4b1dbd3bb9127a2a5b460ec7facbbef5fcbc5e00fe2f9f3df674834cca6641724191acb5c2b81922874c6d32a6
7
- data.tar.gz: cf91125f554221f3ea89364fc8aab76395cfa9f0376fd03369bcfb02bf6235cd7b35b668ea952d7669123883c3c93c83e20cdb8024087b887fe9d95f481865e7
6
+ metadata.gz: fe6dc007658a6364ccacc71305f1f72156c05206c20e48f77a70314e05485de84537eb8bd9f99ecfcbaf84b4fdad916a203ac5820b094eda46a7463c70df159b
7
+ data.tar.gz: cdf109a324e17b044808efa20865aad86f2873c62deef66b59d5577d4ba2b3c76f9a646e41643dfa8d15110545734ff2b6551ef739ecc74b2f150e0248039cb4
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v0.12.0
2
+ - warn when configuring a index with subclasses if using ES version that does support them
3
+ - raise exception when creating or adding document to an index configured with subclasses if using
4
+ an ES version that does not support them
1
5
  v0.11.5
2
6
  - Give the option of retrying the deletion for certain exceptions during remap
3
7
  v0.11.4
@@ -1,5 +1,13 @@
1
1
  module Elasticity
2
2
  class IndexConfig
3
+ class SubclassError < StandardError; end
4
+
5
+ SUBCLASSES_WARNING = "Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. " +
6
+ "Therefore, doument-type based inheritance has been disabled by Elasticity"
7
+ SUBCLASSES_ERROR = "Mapping types have been completely removed in Elasticsearch 7.0.0. " +
8
+ "Therefore, doument-type based inheritance has been disabled by Elasticity"
9
+ VERSION_FOR_SUBCLASS_WARNING = "6.0.0".freeze
10
+ VERSION_FOR_SUBCLASS_ERROR = "7.0.0".freeze
3
11
  ATTRS = [
4
12
  :index_base_name, :document_type, :mapping, :strategy, :subclasses,
5
13
  :settings
@@ -14,6 +22,7 @@ module Elasticity
14
22
  end
15
23
  @elasticity_config = elasticity_config
16
24
  yield(self)
25
+ subclasses_warning_or_exception
17
26
  validate!
18
27
  end
19
28
 
@@ -69,5 +78,15 @@ module Elasticity
69
78
  def merge_settings
70
79
  @elasticity_config.settings.merge(settings || {})
71
80
  end
81
+
82
+ def subclasses_warning_or_exception
83
+ return if subclasses.nil? || subclasses.empty?
84
+ raise(SubclassError.new(SUBCLASSES_ERROR)) if es_version_meets_or_exceeds?(VERSION_FOR_SUBCLASS_ERROR)
85
+ warn(SUBCLASSES_WARNING) if es_version_meets_or_exceeds?(VERSION_FOR_SUBCLASS_WARNING)
86
+ end
87
+
88
+ def es_version_meets_or_exceeds?(test_version)
89
+ client.versions.any?{ |v| v >= test_version }
90
+ end
72
91
  end
73
92
  end
@@ -7,6 +7,10 @@ module Elasticity
7
7
  @client = client
8
8
  end
9
9
 
10
+ def versions
11
+ (@client.cluster.stats["nodes"] && @client.cluster.stats["nodes"]["versions"]) || []
12
+ end
13
+
10
14
  # Generate wrapper methods for @client.indices
11
15
  INDICES_METHODS.each do |method_name|
12
16
  full_name = "index_#{method_name}"
@@ -1,3 +1,3 @@
1
1
  module Elasticity
2
- VERSION = "0.11.5"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'elasticity/index_config'
2
2
 
3
3
  RSpec.describe Elasticity::IndexConfig do
4
- let(:elasticity_config) { double }
4
+ let(:elasticity_config) { double("config", client: double("client", versions: ["5.3.4"])) }
5
5
  subject { }
6
6
 
7
7
  let(:defaults) do
@@ -26,4 +26,72 @@ RSpec.describe Elasticity::IndexConfig do
26
26
  expect(config.index_base_name).to eql('user_documents')
27
27
  expect(config.document_type).to eql('users')
28
28
  end
29
+
30
+ context "subclass warnings and exceptions" do
31
+ class Multied < Elasticity::Document
32
+ end
33
+ describe "multi_mapping exceptions" do
34
+ it "raises an exception for version 7 and above if subclasses are configured" do
35
+ stub_version("7.0.0")
36
+ expect do
37
+ Multied.configure do |c|
38
+ c.index_base_name = "cats_and_dogs"
39
+ c.strategy = Elasticity::Strategies::SingleIndex
40
+ c.subclasses = { cat: "Cat", dog: "Dog" }
41
+ end
42
+ end.to raise_error(
43
+ Elasticity::IndexConfig::SubclassError,
44
+ Elasticity::IndexConfig::SUBCLASSES_ERROR
45
+ )
46
+ end
47
+
48
+ it "does not raise an exception for version 7 and above if no subclasses are configured" do
49
+ stub_version("7.0.0")
50
+ expect do
51
+ Multied.configure do |c|
52
+ c.index_base_name = "cats_and_dogs"
53
+ c.strategy = Elasticity::Strategies::SingleIndex
54
+ end
55
+ end.to_not raise_error
56
+ end
57
+ end
58
+
59
+ describe "multi_mapping warnings" do
60
+ it "warns if multi_mapping is not supported by the ES version" do
61
+ stub_version("6.0.2")
62
+ expect do
63
+ Multied.configure do |c|
64
+ c.index_base_name = "cats_and_dogs"
65
+ c.strategy = Elasticity::Strategies::SingleIndex
66
+ c.subclasses = { cat: "Cat", dog: "Dog" }
67
+ end
68
+ end.to output("#{Elasticity::IndexConfig::SUBCLASSES_WARNING}\n").to_stderr
69
+ end
70
+
71
+ it "does not warn if multi_mapping is supported by the ES version" do
72
+ stub_version("5.3.1")
73
+ expect do
74
+ Multied.configure do |c|
75
+ c.index_base_name = "cats_and_dogs"
76
+ c.strategy = Elasticity::Strategies::SingleIndex
77
+ c.subclasses = { cat: "Cat", dog: "Dog" }
78
+ end
79
+ end.to_not output.to_stderr
80
+ end
81
+
82
+ it "does not warn when no subclasses are configured" do
83
+ stub_version("6.0.2")
84
+ expect do
85
+ Multied.configure do |c|
86
+ c.index_base_name = "cats_and_dogs"
87
+ c.strategy = Elasticity::Strategies::SingleIndex
88
+ end
89
+ end.to_not output.to_stderr
90
+ end
91
+ end
92
+
93
+ def stub_version(version)
94
+ allow_any_instance_of(Elasticity::InstrumentedClient).to receive(:versions).and_return([version])
95
+ end
96
+ end
29
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es-elasticity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.5
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Kochenburger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-29 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -211,6 +211,7 @@ files:
211
211
  - bin/rake
212
212
  - bin/rspec
213
213
  - elasticity.gemspec
214
+ - es-elasticity-0.12.0.pre.rc1.gem
214
215
  - lib/elasticity.rb
215
216
  - lib/elasticity/base_document.rb
216
217
  - lib/elasticity/bulk.rb