es-elasticity 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +7 -4
- data/lib/elasticity/base_document.rb +18 -1
- data/lib/elasticity/index_config.rb +5 -3
- data/lib/elasticity/strategies/alias_index.rb +8 -0
- data/lib/elasticity/strategies/single_index.rb +8 -0
- data/lib/elasticity/version.rb +1 -1
- data/spec/units/document_spec.rb +1 -1
- data/spec/units/index_config_spec.rb +29 -0
- data/spec/units/strategies/single_index_spec.rb +4 -4
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 720cd13dc5ba2ce7e66491cf089672f11d8a755d
|
4
|
+
data.tar.gz: 203824852dd40864503b465430fa401fec2d758e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bfd03d5807b389ba5d9cd38105ce26d997c1ae2d028462b1f28a6f271d1220e375c32c48af8c700cd232a881648599524a56e0ccc912c0489739d55509820af
|
7
|
+
data.tar.gz: 9246d84d925302de828eab261f940039b64bf28c6b72df57ae512c9854aeda14dd095a57cf62aa5da2f88ddd3769ba5ae226ec8ac60b70c8a0b05cb02da8e01b
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
v0.8.0
|
2
|
+
- Make Elasticity::Strategies::AliasIndex the default
|
3
|
+
- Use mapping instead of mappings, we wanna be consistent to ES not to elasticsearch-ruby
|
4
|
+
- Better automatic index name and document type
|
1
5
|
v0.7.1
|
2
6
|
- add more response info to raised exceptions from reindexing
|
3
7
|
v0.6.5
|
data/README.md
CHANGED
@@ -391,17 +391,20 @@ Note that the method takes a relation and not a class, so the following is also
|
|
391
391
|
Search::User.adults.active_records(User.where(active: true))
|
392
392
|
```
|
393
393
|
|
394
|
-
##
|
394
|
+
## Upgrading from 0.7.0 to 0.8.0
|
395
|
+
The default persistance strategy changed from SingleIndex to AliasIndex in version 0.8.0 Add the following to your Document configuration to maintain the legacy behaviour.
|
395
396
|
|
396
|
-
|
397
|
-
|
397
|
+
```ruby
|
398
|
+
c.strategy = Elasticity::Strategies::SingleIndex
|
399
|
+
```
|
400
|
+
|
401
|
+
## Roadmap
|
398
402
|
- [ ] Define from_active_record interface
|
399
403
|
- [ ] Write more detailed documentation section for:
|
400
404
|
- [ ] Model definition
|
401
405
|
- [ ] Indexing, Bulk Indexing and Delete By Query
|
402
406
|
- [ ] Search and Multi Search
|
403
407
|
- [ ] ActiveRecord integration
|
404
|
-
- [ ] Better automatic index name and document type
|
405
408
|
- [ ] Support for multiple document types
|
406
409
|
- [ ] Get rid of to_document, generate automatically based on attributes
|
407
410
|
- [ ] Add some delegations on Document to Index
|
@@ -8,7 +8,7 @@ module Elasticity
|
|
8
8
|
# Configure the given klass, changing default parameters and resetting
|
9
9
|
# some of the internal state.
|
10
10
|
def self.configure(&block)
|
11
|
-
self.config = IndexConfig.new(Elasticity.config, self.
|
11
|
+
self.config = IndexConfig.new(Elasticity.config, self.index_config_defaults, &block)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Define common attributes for all documents
|
@@ -49,5 +49,22 @@ module Elasticity
|
|
49
49
|
def created?
|
50
50
|
@created || false
|
51
51
|
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def self.index_config_defaults
|
56
|
+
{
|
57
|
+
document_type: default_document_type,
|
58
|
+
index_base_name: default_index_base_name
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.default_document_type
|
63
|
+
self.name.gsub('::', '_').underscore
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.default_index_base_name
|
67
|
+
ActiveSupport::Inflector.pluralize(default_document_type)
|
68
|
+
end
|
52
69
|
end
|
53
70
|
end
|
@@ -5,8 +5,10 @@ module Elasticity
|
|
5
5
|
|
6
6
|
attr_accessor *ATTRS
|
7
7
|
|
8
|
-
def initialize(elasticity_config,
|
9
|
-
|
8
|
+
def initialize(elasticity_config, defaults = {})
|
9
|
+
defaults.each do |k,v|
|
10
|
+
instance_variable_set("@#{k}",v)
|
11
|
+
end
|
10
12
|
@elasticity_config = elasticity_config
|
11
13
|
yield(self)
|
12
14
|
validate!
|
@@ -48,7 +50,7 @@ module Elasticity
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def strategy
|
51
|
-
@strategy ||= Strategies::
|
53
|
+
@strategy ||= Strategies::AliasIndex
|
52
54
|
end
|
53
55
|
|
54
56
|
private
|
@@ -238,6 +238,14 @@ module Elasticity
|
|
238
238
|
end
|
239
239
|
|
240
240
|
def mappings
|
241
|
+
ActiveSupport::Deprecation.warn(
|
242
|
+
'Elasticity::Strategies::AliasIndex#mappings is deprecated, '\
|
243
|
+
'use mapping instead'
|
244
|
+
)
|
245
|
+
mapping
|
246
|
+
end
|
247
|
+
|
248
|
+
def mapping
|
241
249
|
@client.index_get_mapping(index: @main_alias, type: @document_type).values.first
|
242
250
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
243
251
|
nil
|
@@ -85,6 +85,14 @@ module Elasticity
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def mappings
|
88
|
+
ActiveSupport::Deprecation.warn(
|
89
|
+
'Elasticity::Strategies::SingleIndex#mappings is deprecated, '\
|
90
|
+
'use mapping instead'
|
91
|
+
)
|
92
|
+
mapping
|
93
|
+
end
|
94
|
+
|
95
|
+
def mapping
|
88
96
|
@client.index_get_mapping(index: @index_name, type: @document_type).values.first
|
89
97
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
90
98
|
nil
|
data/lib/elasticity/version.rb
CHANGED
data/spec/units/document_spec.rb
CHANGED
@@ -39,7 +39,7 @@ RSpec.describe Elasticity::Document do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
before :each do
|
42
|
-
allow(Elasticity::Strategies::
|
42
|
+
allow(Elasticity::Strategies::AliasIndex).to receive(:new).and_return(strategy)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "requires subclasses to define to_document method" do
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'elasticity/index_config'
|
2
|
+
|
3
|
+
RSpec.describe Elasticity::IndexConfig do
|
4
|
+
let(:elasticity_config) { double }
|
5
|
+
subject { }
|
6
|
+
|
7
|
+
let(:defaults) do
|
8
|
+
{
|
9
|
+
index_base_name: 'users',
|
10
|
+
document_type: 'user'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'accepts default configuration options' do
|
15
|
+
config = described_class.new(elasticity_config, defaults) {}
|
16
|
+
expect(config.index_base_name).to eql('users')
|
17
|
+
expect(config.document_type).to eql('user')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'overrides defaults' do
|
21
|
+
config = described_class.new(elasticity_config, defaults) do |c|
|
22
|
+
c.index_base_name = 'user_documents'
|
23
|
+
c.document_type = 'users'
|
24
|
+
end
|
25
|
+
|
26
|
+
expect(config.index_base_name).to eql('user_documents')
|
27
|
+
expect(config.document_type).to eql('users')
|
28
|
+
end
|
29
|
+
end
|
@@ -21,17 +21,17 @@ RSpec.describe Elasticity::Strategies::SingleIndex, elasticsearch: true do
|
|
21
21
|
|
22
22
|
it "allows creating, recreating and deleting an index" do
|
23
23
|
subject.create(index_def)
|
24
|
-
expect(subject.
|
24
|
+
expect(subject.mapping).to eq(index_def)
|
25
25
|
|
26
26
|
subject.recreate(index_def)
|
27
|
-
expect(subject.
|
27
|
+
expect(subject.mapping).to eq(index_def)
|
28
28
|
|
29
29
|
subject.delete
|
30
|
-
expect(subject.
|
30
|
+
expect(subject.mapping).to be nil
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns nil for mapping and settings when index does not exist" do
|
34
|
-
expect(subject.
|
34
|
+
expect(subject.mapping).to be nil
|
35
35
|
expect(subject.settings).to be nil
|
36
36
|
end
|
37
37
|
|
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.
|
4
|
+
version: 0.8.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: 2017-02-
|
11
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- spec/functional/segmented_spec.rb
|
219
219
|
- spec/rspec_config.rb
|
220
220
|
- spec/units/document_spec.rb
|
221
|
+
- spec/units/index_config_spec.rb
|
221
222
|
- spec/units/index_mapper_spec.rb
|
222
223
|
- spec/units/multi_search_spec.rb
|
223
224
|
- spec/units/search_spec.rb
|
@@ -242,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
243
|
version: '0'
|
243
244
|
requirements: []
|
244
245
|
rubyforge_project:
|
245
|
-
rubygems_version: 2.
|
246
|
+
rubygems_version: 2.2.3
|
246
247
|
signing_key:
|
247
248
|
specification_version: 4
|
248
249
|
summary: ActiveModel-based library for working with Elasticsearch
|
@@ -251,7 +252,9 @@ test_files:
|
|
251
252
|
- spec/functional/segmented_spec.rb
|
252
253
|
- spec/rspec_config.rb
|
253
254
|
- spec/units/document_spec.rb
|
255
|
+
- spec/units/index_config_spec.rb
|
254
256
|
- spec/units/index_mapper_spec.rb
|
255
257
|
- spec/units/multi_search_spec.rb
|
256
258
|
- spec/units/search_spec.rb
|
257
259
|
- spec/units/strategies/single_index_spec.rb
|
260
|
+
has_rdoc:
|