scalastic 0.8.1 → 0.8.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
  SHA1:
3
- metadata.gz: aabee929f6467976bbb5a816048e1c22fba92020
4
- data.tar.gz: b007176e8b386a2980ba01b7a0bd00f38b2e1706
3
+ metadata.gz: d9c85a4c8ce641aeb06c69d512a7a89bf5f7f17b
4
+ data.tar.gz: fa1fceadf8d9e1e149e5d20b64e94a31b43364de
5
5
  SHA512:
6
- metadata.gz: a64d2f4512f8d281c28306e303d9e9039eb6597c5d60bc7039bd5360b3582392616432a75437e5e788869221a34fbfc7644c10c958e89b0c1ff56a1c53044cf5
7
- data.tar.gz: a1ca18eb3fc0ff85003d8f087efa795254276218b84148a30b10ed815c074c0dc4ef32fa59300ccbee6814556eea166ca657b6b1fe4fd5cb00ba2f21cdd64c76
6
+ metadata.gz: 504345904505bdf7b63732a8ebc48caf1f535911fc9620510f67f066ac47c772f780d23d8288bcc4ae430610404e195fc01468fa46b54009887c40ccee53c34f
7
+ data.tar.gz: e3eea7ac3814e88f7889a64a65f1e3fb9570b81db57ebc85c67dc0bab72a1810bf3ee93a5bf086adcb59726e59f370dd3715f9eed7357973492c34da427fc50b
@@ -0,0 +1,22 @@
1
+ module Scalastic
2
+ module Normalizer
3
+ extend self
4
+
5
+ def normalized(hash)
6
+ return hash if hash.keys.first.is_a?(String)
7
+ normalize_internal(hash)
8
+ end
9
+
10
+ private
11
+
12
+ def normalize_internal(object)
13
+ if (object.is_a?(Hash))
14
+ object.map{|k, v| [k.to_s, normalize_internal(v)]}.to_h
15
+ elsif object.respond_to?(:map)
16
+ object.map{|i| normalize_internal(i)}
17
+ else
18
+ object
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,9 +1,12 @@
1
1
  require 'scalastic/es_actions_generator'
2
2
  require 'scalastic/partition_selector'
3
3
  require 'scalastic/scroller'
4
+ require 'scalastic/normalizer'
4
5
 
5
6
  module Scalastic
6
7
  class Partition
8
+ include Normalizer
9
+
7
10
  Endpoint = Struct.new(:index, :routing)
8
11
  Endpoints = Struct.new(:index, :search)
9
12
 
@@ -26,7 +29,7 @@ module Scalastic
26
29
  raise(ArgumentError, 'Missing required argument :index') if index.nil? || index.to_s.empty?
27
30
 
28
31
  index_alias = config.index_endpoint(id)
29
- indices = es_client.indices.get_aliases(name: index_alias).select{|i, d| d['aliases'].any?}.keys
32
+ indices = normalized(es_client.indices.get_aliases(name: index_alias)).select{|i, d| d['aliases'].any?}.keys
30
33
  actions = indices.map{|i| {remove: {index: i, alias: index_alias}}}
31
34
  actions << {add: EsActionsGenerator.new_index_alias(config, args.merge(id: id))}
32
35
  actions << {add: EsActionsGenerator.new_search_alias(config, args.merge(id: id))}
@@ -69,7 +72,7 @@ module Scalastic
69
72
 
70
73
  def exists?
71
74
  names = [config.search_endpoint(id), config.index_endpoint(id)]
72
- all_aliases = es_client.indices.get_aliases name: names.join(',')
75
+ all_aliases = normalized(es_client.indices.get_aliases name: names.join(','))
73
76
  all_aliases.any?{|_index, data| data['aliases'].any?}
74
77
  end
75
78
 
@@ -101,7 +104,7 @@ module Scalastic
101
104
  def get_endpoints
102
105
  sa = config.search_endpoint(id)
103
106
  ia = config.index_endpoint(id)
104
- aliases = es_client.indices.get_aliases name: [sa, ia].join(',')
107
+ aliases = normalized(es_client.indices.get_aliases name: [sa, ia].join(','))
105
108
  sas = aliases.map{|i, d| [i, d['aliases'][sa]]}.reject{|_i, sa| sa.nil?}
106
109
  ias = aliases.map{|i, d| [i, d['aliases'][ia]]}.reject{|_i, ia| ia.nil?}
107
110
  Endpoints.new(
@@ -1,9 +1,11 @@
1
- require "scalastic/partition"
2
- require "scalastic/es_actions_generator"
1
+ require 'scalastic/partition'
2
+ require 'scalastic/es_actions_generator'
3
+ require 'scalastic/normalizer'
3
4
 
4
5
  module Scalastic
5
6
  class PartitionsClient
6
7
  include Enumerable
8
+ include Normalizer
7
9
 
8
10
  attr_reader(:es_client)
9
11
  attr_reader(:config)
@@ -27,7 +29,7 @@ module Scalastic
27
29
  def delete(args = {})
28
30
  id = args[:id].to_s
29
31
  raise(ArgumentError, 'Missing required argument :id') if id.nil? || id.empty?
30
- pairs = es_client.indices.get_aliases.map{|i, d| d['aliases'].keys.select{|a| config.get_partition_id(a) == id}.map{|a| [i, a]}}.flatten(1)
32
+ pairs = normalized(es_client.indices.get_aliases).map{|i, d| d['aliases'].keys.select{|a| config.get_partition_id(a) == id}.map{|a| [i, a]}}.flatten(1)
31
33
  unless pairs.any?
32
34
  #TODO: log a warning
33
35
  return
@@ -54,7 +56,7 @@ module Scalastic
54
56
  private
55
57
 
56
58
  def partition_ids
57
- aliases = es_client.indices.get_aliases
59
+ aliases = normalized(es_client.indices.get_aliases)
58
60
  partition_ids = aliases.map{|_, data| data['aliases'].keys}.flatten.map{|a| config.get_partition_id(a)}.compact.uniq
59
61
  end
60
62
  end
@@ -1,6 +1,9 @@
1
+ require 'scalastic/normalizer'
2
+
1
3
  module Scalastic
2
4
  class Scroller
3
5
  include Enumerable
6
+ include Normalizer
4
7
 
5
8
  def initialize(es_client, args)
6
9
  @es_client = es_client
@@ -18,10 +21,10 @@ module Scalastic
18
21
  def each(&block)
19
22
  Enumerator.new do |enum|
20
23
  args = @args.merge(search_type: 'scan', scroll: scroll)
21
- res = @es_client.search(args)
24
+ res = normalized(@es_client.search(args))
22
25
  loop do
23
26
  scroll_id = res['_scroll_id']
24
- res = @es_client.scroll(body: scroll_id, scroll: scroll)
27
+ res = normalized(@es_client.scroll(body: scroll_id, scroll: scroll))
25
28
  hits = res['hits']['hits']
26
29
  break unless hits.any?
27
30
  hits.each{|h| enum << h}
@@ -1,3 +1,3 @@
1
1
  module Scalastic
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
@@ -21,9 +21,11 @@ module RegressionTests
21
21
  p.index id: i + 1, type: 'test', body: {subject: "Test ##{i + 1}"}
22
22
  end
23
23
 
24
+ sleep 1.5
25
+
24
26
  # Get the hits. Size is set to 7 to test multiple calls to scroll
25
27
  actual_hits = p.scroll(type: 'test', size: 7).to_a.sort{|h1, h2| h1['_id'].to_i <=> h2['_id'].to_i}
26
- expected_hits = 10.times.map{|i| {'_id' => "#{i + }", '_type' => 'test', '_source' => {'_subject' => "Test ##{i + 1}"} }}
28
+ expected_hits = 10.times.map{|i| {'_index' => 'scrolling', '_type' => 'test', '_id' => "#{i + 1}", '_score' => 0.0, '_source' => {'subject' => "Test ##{i + 1}", 'scalastic_partition_id' => 1} }}
27
29
 
28
30
  raise "Expected: #{expected_hits}, got: #{actual_hits}" unless expected_hits == actual_hits
29
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scalastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksei Baturytski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-04 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,6 +119,7 @@ files:
119
119
  - lib/scalastic.rb
120
120
  - lib/scalastic/config.rb
121
121
  - lib/scalastic/es_actions_generator.rb
122
+ - lib/scalastic/normalizer.rb
122
123
  - lib/scalastic/partition.rb
123
124
  - lib/scalastic/partition_selector.rb
124
125
  - lib/scalastic/partitions_client.rb
@@ -164,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
165
  version: '0'
165
166
  requirements: []
166
167
  rubyforge_project:
167
- rubygems_version: 2.4.5
168
+ rubygems_version: 2.5.1
168
169
  signing_key:
169
170
  specification_version: 4
170
171
  summary: Elasticsearch document partitions