es-elasticity 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/README.md +4 -4
- data/lib/elasticity/multi_search.rb +4 -4
- data/lib/elasticity/search.rb +11 -10
- data/lib/elasticity/version.rb +1 -1
- data/spec/units/multi_search_spec.rb +13 -0
- data/spec/units/search_spec.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf031d70eec61e290731d0e3c92aa70d369052ed
|
4
|
+
data.tar.gz: 6340aec039146f81aeadcfee37feaa388beb63c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4d8a7fd73ae3724848e194d7850ab178bd62e39bd9c806a609adf3e460792ffc3fe3bdaaf330331950fa5762c7721f23304c2316a1c0c90c8c0929c04b0d9cb
|
7
|
+
data.tar.gz: b0ed024340bc2e8df1bccbd4bd2618016a61db97bc16e7ed7c1d292457dadd3d56a881c609fcb63c5184232412df211576f0b874e5a290ac0dca9c2711cce565
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
v0.6.5
|
2
|
+
- update search and multi search interfaces to allow passing of general
|
3
|
+
search definition arguments found in https://github.com/elastic/elasticsearch-ruby/blob/bdf5e145e5acc21726dddcd34492debbbddde568/elasticsearch-api/lib/elasticsearch/api/actions/search.rb#L125-L162
|
1
4
|
v0.6.4
|
2
5
|
- update suggestions to pull from the proper key
|
3
6
|
v0.6.3
|
data/README.md
CHANGED
@@ -181,10 +181,10 @@ cursor.each_batch { |batch| ... }
|
|
181
181
|
cursor.each { |doc| ... }
|
182
182
|
|
183
183
|
# Lastly, a search that maps back to an ActiveRecord::Relation.
|
184
|
-
adults = adults.
|
184
|
+
adults = adults.active_records(User)
|
185
185
|
```
|
186
186
|
|
187
|
-
For more information about the `
|
187
|
+
For more information about the `active_records` method, read [ActiveRecord integration](#activerecord-integration).
|
188
188
|
|
189
189
|
### Segmented Documents
|
190
190
|
|
@@ -378,7 +378,7 @@ end
|
|
378
378
|
Because the return of that method is a lazy-evaluated search, it allows specific search strategies to be used, one of them being ActiveRecord specific:
|
379
379
|
|
380
380
|
```ruby
|
381
|
-
adults = Search::User.adults.
|
381
|
+
adults = Search::User.adults.active_records(User)
|
382
382
|
adults.class # => ActiveRecord::Relation
|
383
383
|
adults.all # => [#<User: id: 1, name: "John", birthdate: 1985-10-31>, ...]
|
384
384
|
```
|
@@ -386,7 +386,7 @@ adults.all # => [#<User: id: 1, name: "John", birthdate: 1985-10-31>, ...]
|
|
386
386
|
Note that the method takes a relation and not a class, so the following is also possible:
|
387
387
|
|
388
388
|
```ruby
|
389
|
-
Search::User.adults.
|
389
|
+
Search::User.adults.active_records(User.where(active: true))
|
390
390
|
```
|
391
391
|
|
392
392
|
## Roadmap
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Elasticity
|
2
2
|
class MultiSearch
|
3
3
|
|
4
|
-
def initialize
|
4
|
+
def initialize(msearch_args = {})
|
5
5
|
@searches = {}
|
6
6
|
@mappers = {}
|
7
|
+
@msearch_args = msearch_args
|
7
8
|
yield self if block_given?
|
8
9
|
end
|
9
10
|
|
@@ -25,8 +26,6 @@ module Elasticity
|
|
25
26
|
|
26
27
|
def [](name)
|
27
28
|
results_collection[name]
|
28
|
-
rescue NoMethodError => e
|
29
|
-
raise "#{e.inspect} with key #{name}"
|
30
29
|
end
|
31
30
|
|
32
31
|
private
|
@@ -41,7 +40,8 @@ module Elasticity
|
|
41
40
|
end
|
42
41
|
|
43
42
|
response = ActiveSupport::Notifications.instrument("multi_search.elasticity", args: { body: bodies }) do
|
44
|
-
|
43
|
+
args = { body: bodies.map(&:dup) }.reverse_merge(@msearch_args)
|
44
|
+
Elasticity.config.client.msearch(args)
|
45
45
|
end
|
46
46
|
results = {}
|
47
47
|
|
data/lib/elasticity/search.rb
CHANGED
@@ -11,9 +11,9 @@ module Elasticity
|
|
11
11
|
attr_accessor :index_name, :document_types, :body
|
12
12
|
|
13
13
|
def initialize(index_name, document_types, body)
|
14
|
-
@index_name
|
14
|
+
@index_name = index_name
|
15
15
|
@document_types = document_types
|
16
|
-
@body
|
16
|
+
@body = body.deep_symbolize_keys!
|
17
17
|
end
|
18
18
|
|
19
19
|
def update(body_changes)
|
@@ -51,16 +51,16 @@ module Elasticity
|
|
51
51
|
|
52
52
|
# Performs the search using the default search type and returning an iterator that will yield
|
53
53
|
# hash representations of the documents.
|
54
|
-
def document_hashes
|
54
|
+
def document_hashes(search_args = {})
|
55
55
|
return @document_hashes if defined?(@document_hashes)
|
56
|
-
@document_hashes = LazySearch.new(@client, @search_definition)
|
56
|
+
@document_hashes = LazySearch.new(@client, @search_definition, search_args)
|
57
57
|
end
|
58
58
|
|
59
59
|
# Performs the search using the default search type and returning an iterator that will yield
|
60
60
|
# each document, converted using the provided mapper
|
61
|
-
def documents(mapper)
|
61
|
+
def documents(mapper, search_args = {})
|
62
62
|
return @documents if defined?(@documents)
|
63
|
-
@documents = LazySearch.new(@client, @search_definition) do |hit|
|
63
|
+
@documents = LazySearch.new(@client, @search_definition, search_args) do |hit|
|
64
64
|
mapper.(hit)
|
65
65
|
end
|
66
66
|
end
|
@@ -89,10 +89,11 @@ module Elasticity
|
|
89
89
|
|
90
90
|
attr_accessor :search_definition
|
91
91
|
|
92
|
-
def initialize(client, search_definition, &mapper)
|
92
|
+
def initialize(client, search_definition, search_args, &mapper)
|
93
93
|
@client = client
|
94
94
|
@search_definition = search_definition
|
95
95
|
@mapper = mapper
|
96
|
+
@search_args = search_args
|
96
97
|
end
|
97
98
|
|
98
99
|
def empty?
|
@@ -119,7 +120,7 @@ module Elasticity
|
|
119
120
|
|
120
121
|
def response
|
121
122
|
return @response if defined?(@response)
|
122
|
-
@response = @client.search(@search_definition.to_search_args)
|
123
|
+
@response = @client.search(@search_definition.to_search_args.reverse_merge(@search_args))
|
123
124
|
end
|
124
125
|
end
|
125
126
|
|
@@ -263,8 +264,8 @@ module Elasticity
|
|
263
264
|
|
264
265
|
delegate :search_definition, :active_records, to: :@search
|
265
266
|
|
266
|
-
def documents
|
267
|
-
@search.documents(@document_klass)
|
267
|
+
def documents(search_args = {})
|
268
|
+
@search.documents(@document_klass, search_args)
|
268
269
|
end
|
269
270
|
|
270
271
|
def scan_documents(**options)
|
data/lib/elasticity/version.rb
CHANGED
@@ -96,4 +96,17 @@ RSpec.describe Elasticity::MultiSearch do
|
|
96
96
|
expect(subject[:first].aggregations).to eq aggregations["aggregations"]
|
97
97
|
expect(subject[:second].aggregations).to eq Hash.new
|
98
98
|
end
|
99
|
+
|
100
|
+
it "performs multi search with additional arguments" do
|
101
|
+
msearch = Elasticity::MultiSearch.new(search_type: :dfs_query_then_fetch)
|
102
|
+
msearch.add(:first, Elasticity::Search::Facade.new(client, Elasticity::Search::Definition.new("index_first", "document_first", { search: :first, size: 2 })), documents: klass)
|
103
|
+
msearch.add(:second, Elasticity::Search::Facade.new(client, Elasticity::Search::Definition.new("index_second", "document_second", { search: :second })), documents: klass)
|
104
|
+
|
105
|
+
expect(Elasticity.config.client).to receive(:msearch).with(search_type: :dfs_query_then_fetch, body: [
|
106
|
+
{ index: "index_first", type: "document_first", search: { search: :first, size: 2 } },
|
107
|
+
{ index: "index_second", type: "document_second", search: { search: :second } },
|
108
|
+
]).and_return(response)
|
109
|
+
|
110
|
+
expect(Array(msearch[:first])).to eq([klass.new(_id: 1, name: "foo"), klass.new(_id: 2, name: "bar")])
|
111
|
+
end
|
99
112
|
end
|
data/spec/units/search_spec.rb
CHANGED
@@ -179,6 +179,22 @@ RSpec.describe "Search" do
|
|
179
179
|
expect(docs.next_page).to eq(3)
|
180
180
|
expect(docs.previous_page).to eq(1)
|
181
181
|
end
|
182
|
+
|
183
|
+
it "merges in additional arguments for search" do
|
184
|
+
results = double(:results, :[] => { "hits" => [] })
|
185
|
+
subject = Elasticity::Search::Facade.new(
|
186
|
+
client,
|
187
|
+
Elasticity::Search::Definition.new(index_name, document_type, {})
|
188
|
+
)
|
189
|
+
|
190
|
+
expect(client).to receive(:search).with(
|
191
|
+
index: index_name,
|
192
|
+
type: document_type,
|
193
|
+
body: {},
|
194
|
+
search_type: :dfs_query_and_fetch
|
195
|
+
).and_return(results)
|
196
|
+
subject.documents(mapper, search_type: :dfs_query_and_fetch).search_results
|
197
|
+
end
|
182
198
|
end
|
183
199
|
|
184
200
|
describe Elasticity::Search::DocumentProxy do
|
@@ -201,5 +217,13 @@ RSpec.describe "Search" do
|
|
201
217
|
expect(search).to receive(:active_records).with(rel).and_return(records)
|
202
218
|
expect(subject.active_records(rel)).to be records
|
203
219
|
end
|
220
|
+
|
221
|
+
it "accepts additional arguments for a search" do
|
222
|
+
results = double(:results)
|
223
|
+
|
224
|
+
expect(search).to receive(:documents).with(mapper, search_type: :dfs_query_then_fetch).and_return(results)
|
225
|
+
expect(subject.documents(search_type: :dfs_query_then_fetch)).to eq(results)
|
226
|
+
end
|
227
|
+
|
204
228
|
end
|
205
229
|
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.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Kochenburger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|