searchkick 4.0.1 → 4.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf57aedd7e85672dd9bc5f60f22719af2f5cb1797e1afa8f16c426ea291dd4db
4
- data.tar.gz: 54542375eb2cb3c5b7917304cd7e68530a826641c8f1a556af551083964a8849
3
+ metadata.gz: cb0777c063adddb2c339761f92c7ffaf3646daf869b7360dafe662ce0b38056b
4
+ data.tar.gz: '062070815d5b78a2cb3b7c4f0dc9408730e8facd72ce223d25a6bafe9bd46d12'
5
5
  SHA512:
6
- metadata.gz: 5029c0fc16c139f4358786400aad6c36751c6335221e9985f66e5ac308152817db9cd41e709ff6f2b18e731842c85b1a17b9aaeb649b7895393e7001aad8426d
7
- data.tar.gz: 63bd24be4b7b41c539c0acd0c0c8bc6502095707539d235f8ddc9fc49aa2634c2fb602e40ce77e771d151945118d2c4da73d26bcda8c4290d61eae4b6c44b468
6
+ metadata.gz: b3c08562e9a52dc950ff74ebb532beac936367e75c3a2e794079217caed899c566df50265e602c75d13e44eafd03c09821cfb10a88398d0897e5b0a85c76cf7d
7
+ data.tar.gz: c211a672924cec7627d0bf9b1e700c8ef6d037a745a7867e39b3cf8302f8f84d163d6911a893b0f8adf4073bf3f624cb517224e96522d0b5e209b081300a12f7
@@ -1,3 +1,9 @@
1
+ ## 4.0.2
2
+
3
+ - Added block form of `scroll`
4
+ - Added `clear_scroll` method
5
+ - Fixed custom mappings
6
+
1
7
  ## 4.0.1
2
8
 
3
9
  - Added support for scroll API
data/README.md CHANGED
@@ -37,6 +37,7 @@ Plus:
37
37
  - [Performance](#performance)
38
38
  - [Elasticsearch DSL](#advanced)
39
39
  - [Reference](#reference)
40
+ - [Testing](#testing)
40
41
 
41
42
  ## Getting Started
42
43
 
@@ -1479,18 +1480,26 @@ indices_boost: {Category => 2, Product => 1}
1479
1480
 
1480
1481
  ## Scroll API
1481
1482
 
1482
- To retrieve a very large number of results, use the [scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html).
1483
+ Searchkick also supports the [scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html). Scrolling is not intended for real time user requests, but rather for processing large amounts of data.
1484
+
1485
+ ```ruby
1486
+ Product.search("*", scroll: "1m").scroll do |batch|
1487
+ # process batch ...
1488
+ end
1489
+ ```
1490
+
1491
+ You can also scroll batches manually.
1483
1492
 
1484
1493
  ```ruby
1485
1494
  products = Product.search "*", scroll: "1m"
1486
1495
  while products.any?
1487
- # do something ...
1496
+ # process batch ...
1488
1497
 
1489
1498
  products = products.scroll
1490
1499
  end
1491
- ```
1492
1500
 
1493
- You should call `scroll` on each new set of results, not the original result.
1501
+ products.clear_scroll
1502
+ ```
1494
1503
 
1495
1504
  ## Nested Data
1496
1505
 
@@ -13,7 +13,7 @@ module Searchkick
13
13
  index_type = index_type.call if index_type.respond_to?(:call)
14
14
  end
15
15
 
16
- custom_mapping = options[:mapping] || {}
16
+ custom_mapping = options[:mappings] || {}
17
17
  if below70 && custom_mapping.keys.map(&:to_sym).include?(:properties)
18
18
  # add type
19
19
  custom_mapping = {index_type => custom_mapping}
@@ -23,7 +23,6 @@ module Searchkick
23
23
  settings = options[:settings] || {}
24
24
  mappings = custom_mapping
25
25
  else
26
-
27
26
  default_type = "text"
28
27
  default_analyzer = :searchkick_index
29
28
  keyword_mapping = {type: "keyword"}
@@ -435,6 +435,7 @@ module Searchkick
435
435
  warn "[searchkick] WARNING: Passing child models to models option throws off hits and pagination - use type option instead"
436
436
 
437
437
  # uncomment once aliases are supported with _index
438
+ # see https://github.com/elastic/elasticsearch/issues/23306
438
439
  # index_type_or =
439
440
  # models.map do |m|
440
441
  # v = {_index: m.searchkick_index.name}
@@ -228,22 +228,44 @@ module Searchkick
228
228
  def scroll
229
229
  raise Searchkick::Error, "Pass `scroll` option to the search method for scrolling" unless scroll_id
230
230
 
231
- params = {
232
- scroll: options[:scroll],
233
- scroll_id: scroll_id
234
- }
231
+ if block_given?
232
+ records = self
233
+ while records.any?
234
+ yield records
235
+ records = records.scroll
236
+ end
235
237
 
236
- begin
237
- Searchkick::Results.new(@klass, Searchkick.client.scroll(params), @options)
238
- rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
239
- if e.class.to_s =~ /NotFound/ && e.message =~ /search_context_missing_exception/i
240
- raise Searchkick::Error, "Scroll id has expired"
241
- else
242
- raise e
238
+ records.clear_scroll
239
+ else
240
+ params = {
241
+ scroll: options[:scroll],
242
+ scroll_id: scroll_id
243
+ }
244
+
245
+ begin
246
+ # TODO Active Support notifications for this scroll call
247
+ Searchkick::Results.new(@klass, Searchkick.client.scroll(params), @options)
248
+ rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
249
+ if e.class.to_s =~ /NotFound/ && e.message =~ /search_context_missing_exception/i
250
+ raise Searchkick::Error, "Scroll id has expired"
251
+ else
252
+ raise e
253
+ end
243
254
  end
244
255
  end
245
256
  end
246
257
 
258
+ def clear_scroll
259
+ begin
260
+ # try to clear scroll
261
+ # not required as scroll will expire
262
+ # but there is a cost to open scrolls
263
+ Searchkick.client.clear_scroll(scroll_id: scroll_id)
264
+ rescue Elasticsearch::Transport::Transport::Error
265
+ # do nothing
266
+ end
267
+ end
268
+
247
269
  private
248
270
 
249
271
  def results_query(records, hits)
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "4.0.1"
2
+ VERSION = "4.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-30 00:00:00.000000000 Z
11
+ date: 2019-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel