rom-elasticsearch 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -8
- data/README.md +7 -7
- data/lib/rom-elasticsearch.rb +2 -0
- data/lib/rom/elasticsearch.rb +3 -1
- data/lib/rom/elasticsearch/attribute.rb +2 -0
- data/lib/rom/elasticsearch/commands.rb +2 -0
- data/lib/rom/elasticsearch/dataset.rb +6 -0
- data/lib/rom/elasticsearch/errors.rb +2 -0
- data/lib/rom/elasticsearch/gateway.rb +2 -0
- data/lib/rom/elasticsearch/index_name.rb +2 -0
- data/lib/rom/elasticsearch/plugins/relation/query_dsl.rb +2 -0
- data/lib/rom/elasticsearch/query_methods.rb +2 -0
- data/lib/rom/elasticsearch/relation.rb +60 -0
- data/lib/rom/elasticsearch/relation/loaded.rb +2 -0
- data/lib/rom/elasticsearch/schema.rb +5 -1
- data/lib/rom/elasticsearch/scroll_methods.rb +40 -0
- data/lib/rom/elasticsearch/types.rb +7 -5
- data/lib/rom/elasticsearch/version.rb +3 -1
- metadata +18 -78
- data/.codeclimate.yml +0 -6
- data/.gitignore +0 -22
- data/.rspec +0 -3
- data/.travis.yml +0 -27
- data/.yardopts +0 -7
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -19
- data/Rakefile +0 -19
- data/docker-compose.yml +0 -7
- data/rom-elasticsearch.gemspec +0 -27
- data/spec/integration/rom/elasticsearch/relation/command_spec.rb +0 -47
- data/spec/integration/rom/elasticsearch/relation/multi_index_spec.rb +0 -60
- data/spec/integration/rom/elasticsearch/relation/schema_spec.rb +0 -25
- data/spec/shared/setup.rb +0 -16
- data/spec/shared/unit/user_fixtures.rb +0 -15
- data/spec/shared/unit/users.rb +0 -18
- data/spec/spec_helper.rb +0 -42
- data/spec/unit/rom/elasticsearch/dataset/body_spec.rb +0 -13
- data/spec/unit/rom/elasticsearch/dataset/delete_spec.rb +0 -17
- data/spec/unit/rom/elasticsearch/dataset/params_spec.rb +0 -13
- data/spec/unit/rom/elasticsearch/dataset/put_spec.rb +0 -14
- data/spec/unit/rom/elasticsearch/dataset/query_string_spec.rb +0 -12
- data/spec/unit/rom/elasticsearch/dataset/search_spec.rb +0 -20
- data/spec/unit/rom/elasticsearch/gateway_spec.rb +0 -10
- data/spec/unit/rom/elasticsearch/plugins/relation/query_dsl_spec.rb +0 -34
- data/spec/unit/rom/elasticsearch/relation/call_spec.rb +0 -22
- data/spec/unit/rom/elasticsearch/relation/create_index_spec.rb +0 -75
- data/spec/unit/rom/elasticsearch/relation/dataset_spec.rb +0 -51
- data/spec/unit/rom/elasticsearch/relation/delete_spec.rb +0 -32
- data/spec/unit/rom/elasticsearch/relation/get_spec.rb +0 -22
- data/spec/unit/rom/elasticsearch/relation/map_spec.rb +0 -18
- data/spec/unit/rom/elasticsearch/relation/order_spec.rb +0 -40
- data/spec/unit/rom/elasticsearch/relation/page_spec.rb +0 -20
- data/spec/unit/rom/elasticsearch/relation/pluck_spec.rb +0 -18
- data/spec/unit/rom/elasticsearch/relation/query_spec.rb +0 -18
- data/spec/unit/rom/elasticsearch/relation/query_string_spec.rb +0 -18
- data/spec/unit/rom/elasticsearch/relation/search_spec.rb +0 -18
- data/spec/unit/rom/elasticsearch/relation/to_a_spec.rb +0 -28
@@ -1,13 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Elasticsearch::Dataset, '#params' do
|
2
|
-
subject(:dataset) do
|
3
|
-
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
|
4
|
-
end
|
5
|
-
|
6
|
-
include_context 'user fixtures'
|
7
|
-
|
8
|
-
it 'returns a new dataset with updated params' do
|
9
|
-
new_ds = dataset.params(size: 100)
|
10
|
-
|
11
|
-
expect(new_ds.params).to eql(size: 100, index: :users, type: :user)
|
12
|
-
end
|
13
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Elasticsearch::Dataset, '#put' do
|
2
|
-
subject(:dataset) do
|
3
|
-
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
|
4
|
-
end
|
5
|
-
|
6
|
-
include_context 'setup'
|
7
|
-
|
8
|
-
it 'puts new data' do
|
9
|
-
result = dataset.put(username: 'eve')
|
10
|
-
|
11
|
-
expect(result['_id']).to_not be(nil)
|
12
|
-
expect(result['result']).to eql('created')
|
13
|
-
end
|
14
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Elasticsearch::Dataset, '#query_string' do
|
2
|
-
subject(:dataset) do
|
3
|
-
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
|
4
|
-
end
|
5
|
-
|
6
|
-
include_context 'user fixtures'
|
7
|
-
|
8
|
-
it 'returns data matching query string' do
|
9
|
-
expect(dataset.query_string('username:alice').to_a).to eql([{'username' => 'alice'}])
|
10
|
-
expect(dataset.query_string('username:nisse').to_a).to eql([])
|
11
|
-
end
|
12
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
RSpec.describe ROM::Elasticsearch::Dataset, '#search' do
|
2
|
-
subject(:dataset) do
|
3
|
-
ROM::Elasticsearch::Dataset.new(client, params: { index: :users, type: :user })
|
4
|
-
end
|
5
|
-
|
6
|
-
include_context 'setup'
|
7
|
-
|
8
|
-
before do
|
9
|
-
dataset.put(username: 'eve')
|
10
|
-
dataset.put(username: 'bob')
|
11
|
-
dataset.put(username: 'alice')
|
12
|
-
|
13
|
-
dataset.refresh
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'returns data matching query options' do
|
17
|
-
expect(dataset.search(query: {query_string: {query: 'username:eve'}}).to_a).
|
18
|
-
to eql([{'username' => 'eve'}])
|
19
|
-
end
|
20
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/plugins/relation/query_dsl'
|
2
|
-
require 'rom/elasticsearch/relation'
|
3
|
-
|
4
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#search' do
|
5
|
-
subject(:relation) { relations[:users] }
|
6
|
-
|
7
|
-
include_context 'setup'
|
8
|
-
|
9
|
-
before do
|
10
|
-
conf.relation(:users) do
|
11
|
-
schema do
|
12
|
-
attribute :id, ROM::Types::Int.meta(type: "integer")
|
13
|
-
attribute :name, ROM::Types::Int.meta(type: "text")
|
14
|
-
end
|
15
|
-
|
16
|
-
use :query_dsl
|
17
|
-
end
|
18
|
-
|
19
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
20
|
-
relation.command(:create).(id: 2, name: 'John')
|
21
|
-
|
22
|
-
relation.refresh
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'builds a query using a block-based DSL' do
|
26
|
-
result = relation.search do
|
27
|
-
query do
|
28
|
-
match name: 'Jane'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
expect(result.to_a).to eql([{ id: 1, name: 'Jane' }])
|
33
|
-
end
|
34
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#call' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
10
|
-
relation.command(:create).(id: 2, name: 'John')
|
11
|
-
|
12
|
-
relation.refresh
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns loaded relation' do
|
16
|
-
result = relation.call
|
17
|
-
|
18
|
-
expect(result).to match_array([{ id: 1, name: 'Jane' }, { id: 2, name: 'John' }])
|
19
|
-
|
20
|
-
expect(result.total_hits).to be(2)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#create_index' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'setup'
|
7
|
-
|
8
|
-
context 'when custom :index is configured' do
|
9
|
-
after do
|
10
|
-
relation.delete_index
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'with default settings' do
|
14
|
-
before do
|
15
|
-
conf.relation(:users) do
|
16
|
-
schema do
|
17
|
-
attribute :id, ROM::Elasticsearch::Types::ID
|
18
|
-
attribute :name, ROM::Types::String
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'creates an index' do
|
24
|
-
relation.create_index
|
25
|
-
|
26
|
-
expect(gateway.index?(:users)).to be(true)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with customized settings' do
|
31
|
-
before do
|
32
|
-
conf.relation(:users) do
|
33
|
-
schema do
|
34
|
-
attribute :id, ROM::Types::Int
|
35
|
-
attribute :name, ROM::Types::String
|
36
|
-
end
|
37
|
-
|
38
|
-
index_settings number_of_shards: 2
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'creates an index' do
|
43
|
-
relation.create_index
|
44
|
-
|
45
|
-
expect(gateway.index?(:users)).to be(true)
|
46
|
-
expect(relation.dataset.settings['number_of_shards']).to eql("2")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'with customized attribute mappings' do
|
51
|
-
before do
|
52
|
-
conf.relation(:users) do
|
53
|
-
schema do
|
54
|
-
attribute :id, ROM::Elasticsearch::Types::ID
|
55
|
-
attribute :name, ROM::Elasticsearch::Types.Keyword
|
56
|
-
attribute :desc, ROM::Elasticsearch::Types.Text(analyzer: "snowball")
|
57
|
-
end
|
58
|
-
|
59
|
-
index_settings number_of_shards: 2
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'creates an index' do
|
64
|
-
relation.create_index
|
65
|
-
|
66
|
-
expect(gateway.index?(:users)).to be(true)
|
67
|
-
|
68
|
-
expect(relation.dataset.mappings).
|
69
|
-
to eql("properties" => {
|
70
|
-
"name" => { "type" => "keyword" },
|
71
|
-
"desc" => { "type" => "text", "analyzer" => "snowball" }})
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#dataset' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'setup'
|
7
|
-
|
8
|
-
context 'with default index settings' do
|
9
|
-
before do
|
10
|
-
conf.relation(:users) do
|
11
|
-
schema do
|
12
|
-
attribute :id, ROM::Types::Int
|
13
|
-
attribute :name, ROM::Types::String
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'sets up correct index name' do
|
19
|
-
expect(relation.dataset.index).to eql(:users)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'sets up default index type' do
|
23
|
-
expect(relation.dataset.type).to eql(:user)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'overridding default dataset object' do
|
28
|
-
let(:users) { relations[:users] }
|
29
|
-
|
30
|
-
before do
|
31
|
-
conf.relation(:users) do
|
32
|
-
dataset do
|
33
|
-
with(include_metadata: true)
|
34
|
-
end
|
35
|
-
|
36
|
-
schema do
|
37
|
-
attribute :id, ROM::Types::Int
|
38
|
-
attribute :name, ROM::Types::String
|
39
|
-
attribute :_metadata, ROM::Types::Hash.symbolized(_index: 'string')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
users.create_index
|
44
|
-
users.command(:create).call(id: 1, name: 'Jane')
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'uses customized dataset' do
|
48
|
-
expect(relation.to_a).to eql([{ id: 1, name: 'Jane', _metadata: { _index: 'users' } }])
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#delete' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
10
|
-
relation.command(:create).(id: 2, name: 'John')
|
11
|
-
|
12
|
-
relation.refresh
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'deletes all data' do
|
16
|
-
relation.delete
|
17
|
-
|
18
|
-
expect(relation.refresh.to_a).to be_empty
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'deletes all data from a relation restricted by id' do
|
22
|
-
relation.get(2).delete
|
23
|
-
|
24
|
-
expect(relation.refresh.to_a).to eql([{ id: 1, name: 'Jane' }])
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'deletes all data from a relation restricted by a query' do
|
28
|
-
relation.query(match: { name: 'Jane' }).delete
|
29
|
-
|
30
|
-
expect(relation.refresh.to_a).to eql([{ id: 2, name: 'John' }])
|
31
|
-
end
|
32
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#get' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
10
|
-
relation.command(:create).(id: 2, name: 'John')
|
11
|
-
|
12
|
-
relation.refresh
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns user tuple by its id' do
|
16
|
-
expect(relation.get(1).one).to eql(id: 1, name: 'Jane')
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'raises search error' do
|
20
|
-
expect { relation.get(12421).one }.to raise_error(ROM::Elasticsearch::SearchError)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#map' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
10
|
-
relation.command(:create).(id: 2, name: 'John')
|
11
|
-
|
12
|
-
relation.refresh
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'yields result tuples' do
|
16
|
-
expect(relation.map { |t| t[:name] }).to match_array(%w[Jane John])
|
17
|
-
end
|
18
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#order' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'John')
|
10
|
-
relation.command(:create).(id: 2, name: 'Jane')
|
11
|
-
relation.command(:create).(id: 3, name: 'Jade')
|
12
|
-
relation.command(:create).(id: 4, name: 'Joe')
|
13
|
-
|
14
|
-
relation.refresh
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'with ascending direction' do
|
18
|
-
result = relation.order(:id).to_a
|
19
|
-
|
20
|
-
expect(result).
|
21
|
-
to eql([
|
22
|
-
{ id: 1, name: 'John' },
|
23
|
-
{ id: 2, name: 'Jane' },
|
24
|
-
{ id: 3, name: 'Jade' },
|
25
|
-
{ id: 4, name: 'Joe' }
|
26
|
-
])
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'with descending direction' do
|
30
|
-
result = relation.order(relation[:id].desc).to_a
|
31
|
-
|
32
|
-
expect(result).
|
33
|
-
to eql([
|
34
|
-
{ id: 4, name: 'Joe' },
|
35
|
-
{ id: 3, name: 'Jade' },
|
36
|
-
{ id: 2, name: 'Jane' },
|
37
|
-
{ id: 1, name: 'John' }
|
38
|
-
])
|
39
|
-
end
|
40
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#page' do
|
4
|
-
subject(:relation) { relations[:users].order(:id) }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
10
|
-
relation.command(:create).(id: 2, name: 'John')
|
11
|
-
|
12
|
-
relation.refresh
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns relation with page set' do
|
16
|
-
result = relation.per_page(1).page(2).to_a
|
17
|
-
|
18
|
-
expect(result).to match_array([{ id: 2, name: 'John' }])
|
19
|
-
end
|
20
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#pluck' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
10
|
-
relation.command(:create).(id: 2, name: 'John')
|
11
|
-
|
12
|
-
relation.refresh
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns an array with plucked values' do
|
16
|
-
expect(relation.pluck(:name)).to match_array(%w[Jane John])
|
17
|
-
end
|
18
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#query' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
10
|
-
relation.command(:create).(id: 2, name: 'John')
|
11
|
-
|
12
|
-
relation.refresh
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns data matching query options' do
|
16
|
-
expect(relation.query(match: { name: 'Jane' }).one).to eql(id: 1, name: 'Jane')
|
17
|
-
end
|
18
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rom/elasticsearch/relation'
|
2
|
-
|
3
|
-
RSpec.describe ROM::Elasticsearch::Relation, '#query_string' do
|
4
|
-
subject(:relation) { relations[:users] }
|
5
|
-
|
6
|
-
include_context 'users'
|
7
|
-
|
8
|
-
before do
|
9
|
-
relation.command(:create).(id: 1, name: 'Jane')
|
10
|
-
relation.command(:create).(id: 2, name: 'John')
|
11
|
-
|
12
|
-
relation.refresh
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns data matching query string' do
|
16
|
-
expect(relation.query_string('name:Jane').one).to eql(id: 1, name: 'Jane')
|
17
|
-
end
|
18
|
-
end
|