elasticated 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c6d361a271487eaaa00bad98fc637d71577f84f
4
- data.tar.gz: a1ad71c40b64d1681fe08558eaf0a6b7d19e49e2
3
+ metadata.gz: 652c62edebb74aa1b6d28929049fe5cd99d445b2
4
+ data.tar.gz: 759ce109407e8c30fda15f0fd9ad3cdcbfa8288a
5
5
  SHA512:
6
- metadata.gz: c3c712d491f5846c8445765b5532fc0c3de738a429be5d00e1bbd6c11f1812e711eaaaa6facf0edad4a6563570aa243b15e748652ebbc82d0aebd3d1d329eacc
7
- data.tar.gz: 40d195a39ecea6dc083487956a8442b69f7cf27e5947274a22f55c5fce64640f2708a53e16a3acd77fade4bb2e32cd38d4cff420e953d200293d28b5156cb524
6
+ metadata.gz: 555dd488f3bff9299d41898687609f244e8adbfd289e6a0e3826c0fe7c5ecf963269aff7feb83d25b1d67b42eb0cc5f52e03f5cb610a558430e5ea2ca712cf9f
7
+ data.tar.gz: 351b942f5927abdcd6effe9f315165a127df4dffdc1a5885da988b5b1e5a76f55edc9bcd92edb51977a658682309390a2b8b2ea7e6c1f99d02d91bf23e18d15e
data/README.md CHANGED
@@ -112,6 +112,7 @@ Elasticated.configure do |config|
112
112
  config.scroll_expiration_time = '3m'
113
113
  config.scroll_page_size = 500
114
114
  config.search_page_size = 1000
115
+ config.transport_options.request_timeout = 5*60
115
116
  end
116
117
  ```
117
118
 
@@ -122,4 +123,5 @@ repository.logger = Elasticated::Loggers::DefaultLogger.new
122
123
  repository.scroll_expiration_time = '3m'
123
124
  repository.scroll_page_size = 500
124
125
  repository.search_page_size = 1000
126
+ # transport_options cannot be setted for a single repository
125
127
  ```
@@ -5,7 +5,7 @@ module Elasticated
5
5
  attr_accessor :transport
6
6
 
7
7
  def initialize(opts={})
8
- self.transport = ::Elasticsearch::Client.new opts
8
+ self.transport = ::Elasticsearch::Client.new Configuration.transport_options.merge opts
9
9
  end
10
10
 
11
11
  def index_document(document_source, opts={})
@@ -18,6 +18,19 @@ module Elasticated
18
18
  log.debug "Document updated #{response.to_json}"
19
19
  end
20
20
 
21
+ def create_percolator(query_source, opts={})
22
+ transport.index index: opts.fetch(:index),
23
+ type: '.percolator',
24
+ id: opts.fetch(:id),
25
+ body: { query: query_source }
26
+ end
27
+
28
+ def percolate(document_source, opts={})
29
+ transport.percolate index: opts.fetch(:index),
30
+ type: opts.fetch(:type),
31
+ body: { doc: document_source }
32
+ end
33
+
21
34
  def index_exists?(index_name)
22
35
  transport.indices.exists index: index_name
23
36
  end
@@ -4,6 +4,7 @@ module Elasticated
4
4
  class << self
5
5
  attr_accessor :logger
6
6
  attr_accessor :scroll_expiration_time, :scroll_page_size, :search_page_size
7
+ attr_accessor :transport_options
7
8
  end
8
9
 
9
10
  # defaults
@@ -11,6 +12,7 @@ module Elasticated
11
12
  self.scroll_expiration_time = '3m'
12
13
  self.scroll_page_size = 500
13
14
  self.search_page_size = 1000
15
+ self.transport_options = Hash::Accessible.new request_timeout: 60 # 1 minute
14
16
 
15
17
  end
16
18
  end
@@ -23,6 +23,14 @@ module Elasticated
23
23
  indices.first
24
24
  end
25
25
 
26
+ def index_for_percolator(query)
27
+ params = strategy_params_for_percolator query
28
+ indices = strategy.call params
29
+ raise "Only one index can be affected for a percolator indexation" if indices.count > 1
30
+ raise "At least one index should be affected for a percolator indexation" if indices.count < 1
31
+ indices.first
32
+ end
33
+
26
34
  protected
27
35
 
28
36
  def strategy_params_for_document(document)
@@ -40,5 +48,9 @@ module Elasticated
40
48
  end
41
49
  end
42
50
 
51
+ def strategy_params_for_percolator(query)
52
+ { date: DateTime.now.iso8601 }
53
+ end
54
+
43
55
  end
44
56
  end
@@ -28,6 +28,12 @@ module Elasticated
28
28
  super action, document, opts.merge(index: affected_index)
29
29
  end
30
30
 
31
+ # override
32
+ def prepare_percolator(action, query, opts={})
33
+ affected_index = index_selector.index_for_percolator(query)
34
+ super action, query, opts.merge(index: affected_index)
35
+ end
36
+
31
37
  def affected_indices_for(query)
32
38
  index_selector.indices_for_query(query)
33
39
  end
@@ -43,6 +43,14 @@ module Elasticated
43
43
  prepare :update, document, opts
44
44
  end
45
45
 
46
+ def create_percolator(query, opts={})
47
+ prepare_percolator :create_percolator, query, opts
48
+ end
49
+
50
+ def percolate(document, opts={})
51
+ prepare_percolator :percolate, document, opts
52
+ end
53
+
46
54
  def prepare_search(query, opts={})
47
55
  execute :prepare_search, query, opts
48
56
  end
@@ -72,6 +80,11 @@ module Elasticated
72
80
  client.send "#{method}_document", document.source, opts
73
81
  end
74
82
 
83
+ def _exec_create_percolator(query, opts={})
84
+ query_source = query.build.fetch(:query)
85
+ client.create_percolator query_source, opts
86
+ end
87
+
75
88
  # read actions
76
89
 
77
90
  def _exec_aggregations(query, opts={})
@@ -125,6 +138,11 @@ module Elasticated
125
138
  ResumableSearch.new self, query, false, opts
126
139
  end
127
140
 
141
+ def _exec_percolate(document, opts={})
142
+ document_source = document.document_source
143
+ client.percolate document_source, opts
144
+ end
145
+
128
146
  # abstract methods
129
147
 
130
148
  def execute(action, query, opts={})
@@ -137,5 +155,10 @@ module Elasticated
137
155
  send "_exec_#{action}", document, opts
138
156
  end
139
157
 
158
+ def prepare_percolator(action, query, opts={})
159
+ # child's implementation here
160
+ send "_exec_#{action}", query, opts
161
+ end
162
+
140
163
  end
141
164
  end
@@ -7,13 +7,13 @@ module Elasticated
7
7
  # ------------ without sorting
8
8
  # without size, without offset => scan_scroll
9
9
  # with size, without offset => single_page or scan_scroll
10
- # without size, with offset => normal_pagination # TODO analizar si se puede usar scroll con offset
11
- # with size, with offset => single_page or normal_pagination # TODO analizar si se puede usar scroll con offset
10
+ # without size, with offset => normal_pagination
11
+ # with size, with offset => single_page or normal_pagination
12
12
  # ------------ with sorting
13
13
  # without size, without offset => scroll
14
14
  # with size, without offset => single_page or scroll
15
- # without size, with offset => normal_pagination # TODO analizar si se puede usar scroll con offset
16
- # with size, with offset => single_page or normal_pagination # TODO analizar si se puede usar scroll con offset
15
+ # without size, with offset => normal_pagination
16
+ # with size, with offset => single_page or normal_pagination
17
17
 
18
18
  # if the query is aggregated and the search strategy is use an
19
19
  # scroll-like alternative, we must do a 2-step search process
data/lib/version.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  module Elasticated
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
4
4
 
5
5
  # Changelog
6
6
 
7
+ # 2.1.0
8
+ # Se agrega la funcionalidad para crear percolators y consultarlos con documents
9
+
7
10
  # 2.0.0
8
11
  # Se renombra la aggregation 'count_distinct' por 'value_count'
9
12
  # Se separan los metodos de busqueda (scroll, paginacion normal, scan & scroll) en strategies
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticated
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Fernandez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-03 00:00:00.000000000 Z
11
+ date: 2016-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler