es-elasticity 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d72499e7492430676f282eea3890061607c2b875
4
- data.tar.gz: 7c912b62cb5c42c178454051ffab439315a4c7b5
3
+ metadata.gz: 1c5f0cdc13a933f514fc74015c2dc23b8733f8a0
4
+ data.tar.gz: f345594a1b7770bfc40ad274e947b3db3b3b5ffd
5
5
  SHA512:
6
- metadata.gz: 72078a3e8bbbb87bd6a34b31995df58da3380f87610870e77b415bbfa4330389d7ba918e6905a494007d11aef11254000931239a0a5844a40ab98c57a70b77c5
7
- data.tar.gz: 644b482f73d666e6e9ac22f38bbf36e16507b9b894e75191cebebaf734e5dd6549d5d7baa8b0ca374d9c55093dcc0ed1ad2bcab0f40d09244addc650691c585c
6
+ metadata.gz: 22d071dd3e4166f747022a8fb0202edbd468e108874a310408f98227738b99201f37e167208d6c663ce61913a502ceda3d4f4165c1cbb874b8c57da28556b676
7
+ data.tar.gz: b32c8f0fdfc9d27822f13125f18fc71248b3d41b3e5dd73c0465603fabf63eacac6844d6c4cd93b0838c7503f1b3b34dcf35ab8b0344e036cac5ac8a1bb1e478
@@ -1,11 +1,14 @@
1
1
  module Elasticity
2
2
  class InstrumentedClient
3
+ INDICES_METHODS = %w(exists create delete get_settings get_mapping flush get_alias get_aliases put_alias delete_alias exists_alias update_aliases)
4
+ INDEX_METHODS = %w(index delete get mget search count msearch scroll delete_by_query bulk)
5
+
3
6
  def initialize(client)
4
7
  @client = client
5
8
  end
6
9
 
7
10
  # Generate wrapper methods for @client.indices
8
- %w(exists create delete get_settings get_mapping flush get_alias get_aliases put_alias delete_alias exists_alias update_aliases).each do |method_name|
11
+ INDICES_METHODS.each do |method_name|
9
12
  full_name = "index_#{method_name}"
10
13
 
11
14
  define_method(full_name) do |*args, &block|
@@ -16,7 +19,7 @@ module Elasticity
16
19
  end
17
20
 
18
21
  # Generate wrapper methods for @client
19
- %w(index delete get mget search count msearch scroll delete_by_query bulk).each do |method_name|
22
+ INDEX_METHODS.each do |method_name|
20
23
  define_method(method_name) do |*args, &block|
21
24
  instrument(method_name, args) do
22
25
  @client.public_send(method_name, *args, &block)
@@ -5,13 +5,13 @@ module Elasticity
5
5
  GRAY = "\e[90m"
6
6
 
7
7
  class LogSubscriber < ::ActiveSupport::LogSubscriber
8
- %w(exists create delete get_settings get_mapping flush get_alias get_aliases put_alias delete_alias exists_alias update_aliases).each do |method_name|
8
+ InstrumentedClient::INDICES_METHODS.each do |method_name|
9
9
  define_method("index_#{method_name}") do |event|
10
10
  log_event(event)
11
11
  end
12
12
  end
13
13
 
14
- %w(index delete get search scroll delete_by_query bulk).each do |method_name|
14
+ InstrumentedClient::INDEX_METHODS.each do |method_name|
15
15
  define_method(method_name) do |event|
16
16
  log_event(event)
17
17
  end
@@ -21,7 +21,10 @@ module Elasticity
21
21
  end
22
22
 
23
23
  def to_count_args
24
- { index: @index_name, type: @document_type, body: { query: @body.fetch(:query) }}
24
+ { index: @index_name, type: @document_type}.tap do |args|
25
+ body = @body.slice(:query)
26
+ args[:body] = body if body.present?
27
+ end
25
28
  end
26
29
 
27
30
  def to_search_args
@@ -1,3 +1,3 @@
1
1
  module Elasticity
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -31,6 +31,11 @@ RSpec.describe "Persistence", elasticsearch: true do
31
31
  subject.delete_index
32
32
  end
33
33
 
34
+ it "counts empty search" do
35
+ count = subject.search({}).count
36
+ expect(count).to eq 0
37
+ end
38
+
34
39
  it "successfully index, update, search, count and delete" do
35
40
  john = subject.new(name: "John", birthdate: "1985-10-31")
36
41
  mari = subject.new(name: "Mari", birthdate: "1986-09-24")
@@ -92,6 +97,11 @@ RSpec.describe "Persistence", elasticsearch: true do
92
97
  subject.delete_index
93
98
  end
94
99
 
100
+ it "counts empty search" do
101
+ count = subject.search({}).count
102
+ expect(count).to eq 0
103
+ end
104
+
95
105
  it "remaps to a different index transparently" do
96
106
  john = subject.new(name: "John", birthdate: "1985-10-31")
97
107
  mari = subject.new(name: "Mari", birthdate: "1986-09-24")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es-elasticity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Kochenburger
@@ -242,3 +242,4 @@ test_files:
242
242
  - spec/units/multi_search_spec.rb
243
243
  - spec/units/search_spec.rb
244
244
  - spec/units/strategies/single_index_spec.rb
245
+ has_rdoc: