es-elasticity 0.5.1 → 0.5.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: 81bec50770ad1681435091821100f72489c99522
4
- data.tar.gz: e01e698ea9fd852b9a886063ae5072cfbc9ed930
3
+ metadata.gz: 34c481f8fef0f48b348e3c487aea2f38992fd83f
4
+ data.tar.gz: 9fce147cb9df7c2ae369d795dc4d31a6777ce2a4
5
5
  SHA512:
6
- metadata.gz: da2ddc9b326281ccef128a4a502cdfc8344cb3a5ddc01b2d8564ca29a7d34b5bfdbe652cc6102ef508c53e920e2176ef6c7df1afa82bb911584055b19c7100fd
7
- data.tar.gz: f5cf61f522db5424dc54cea8ba20578ee3919ae18bc087d9eb2be1928968be619364fe264e4b8632d16525f02e42e247d50d11a341e672aedc2e55abd360675c
6
+ metadata.gz: 2b2f8782e944c7adfcd11023829d0031657bc669945f65794e04cbd6389f6043569dd06d776e1b39b9589b227f5d1a653c8b594e9f92e6a6ec471c6bd605d1f5
7
+ data.tar.gz: 5c7abac9d356d50d60617231fef6ccc7746be8106aa3ad356b49873143f2ccd6815e568334f8c118fe5229339089f27778d0bc51022c696a9159ca062c284bc9
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.5.2
2
+ - Add aggregations to multi_search
1
3
  v0.5.1
2
4
  - Add ability to reindex individual attributes of a document using the
3
5
  bulk_update API.
@@ -85,7 +85,7 @@ module Elasticity
85
85
  include Enumerable
86
86
 
87
87
  delegate :each, :size, :length, :[], :+, :-, :&, :|, :total, :per_page,
88
- :total_pages, :current_page, to: :search_results
88
+ :total_pages, :current_page, :aggregations, to: :search_results
89
89
 
90
90
  attr_accessor :search_definition
91
91
 
@@ -103,10 +103,6 @@ module Elasticity
103
103
  empty?
104
104
  end
105
105
 
106
- def aggregations
107
- response["aggregations"] ||= {}
108
- end
109
-
110
106
  def suggestions
111
107
  response["hits"]["suggest"] ||= {}
112
108
  end
@@ -200,7 +196,7 @@ module Elasticity
200
196
 
201
197
  class Relation < ActiveSupport::ProxyObject
202
198
 
203
- delegate :total, :per_page, :total_pages, :current_page, to: :@results
199
+ delegate :total, :per_page, :total_pages, :current_page, :aggregations, to: :@results
204
200
 
205
201
  def initialize(relation, search_definition, response)
206
202
  @relation = relation
@@ -308,6 +304,10 @@ module Elasticity
308
304
  @response["hits"]["total"]
309
305
  end
310
306
 
307
+ def aggregations
308
+ @response["aggregations"] ||= {}
309
+ end
310
+
311
311
  # for pagination
312
312
  def per_page
313
313
  @body[:size] || DEFAULT_SIZE
@@ -1,3 +1,3 @@
1
1
  module Elasticity
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -21,11 +21,60 @@ RSpec.describe Elasticity::MultiSearch do
21
21
  end
22
22
  end
23
23
 
24
+ let :index_with_one_hit do
25
+ {
26
+ "hits" => {
27
+ "total" => 1,
28
+ "hits" => [
29
+ { "_id" => 3, "_source" => { "name" => "baz" }}
30
+ ]
31
+ }
32
+ }
33
+ end
34
+
35
+ let :index_with_two_hits do
36
+ {
37
+ "hits" => {
38
+ "total" => 2,
39
+ "hits" => [
40
+ { "_id" => 1, "_source" => { "name" => "foo" }},
41
+ { "_id" => 2, "_source" => { "name" => "bar" }}
42
+ ]
43
+ }
44
+ }
45
+ end
46
+
47
+ let :aggregations do
48
+ {
49
+ "aggregations" => {
50
+ "logins_count" => { "value" => 1495 },
51
+ "gender" => {
52
+ "buckets" => [
53
+ {
54
+ "doc_count" => 100,
55
+ "key" => "M"
56
+ },
57
+ {
58
+ "doc_count" => 100,
59
+ "key" => "F"
60
+ }
61
+ ],
62
+ "doc_count_error_upper_bound" => 0,
63
+ "sum_other_doc_count" => 0
64
+ }
65
+ }
66
+ }
67
+ end
68
+
69
+ let :index_with_two_hits_and_aggregations do
70
+ index_with_two_hits.merge(aggregations)
71
+ end
72
+
24
73
  let :response do
25
74
  {
26
75
  "responses" => [
27
- { "hits" => { "total" => 2, "hits" => [{ "_id" => 1, "_source" => { "name" => "foo" }}, { "_id" => 2, "_source" => { "name" => "bar" }}]}},
28
- { "hits" => { "total" => 1, "hits" => [{ "_id" => 3, "_source" => { "name" => "baz" }}]}},
76
+ index_with_two_hits_and_aggregations,
77
+ index_with_one_hit
29
78
  ]
30
79
  }
31
80
  end
@@ -44,5 +93,7 @@ RSpec.describe Elasticity::MultiSearch do
44
93
  expect(subject[:first].total).to eq 2
45
94
  expect(subject[:first].total_pages).to eq 1
46
95
  expect(subject[:first].current_page).to eq 1
96
+ expect(subject[:first].aggregations).to eq aggregations["aggregations"]
97
+ expect(subject[:second].aggregations).to eq Hash.new
47
98
  end
48
99
  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.5.1
4
+ version: 0.5.2
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-03-03 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler