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 +4 -4
- data/CHANGELOG +2 -0
- data/lib/elasticity/search.rb +6 -6
- data/lib/elasticity/version.rb +1 -1
- data/spec/units/multi_search_spec.rb +53 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34c481f8fef0f48b348e3c487aea2f38992fd83f
|
4
|
+
data.tar.gz: 9fce147cb9df7c2ae369d795dc4d31a6777ce2a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b2f8782e944c7adfcd11023829d0031657bc669945f65794e04cbd6389f6043569dd06d776e1b39b9589b227f5d1a653c8b594e9f92e6a6ec471c6bd605d1f5
|
7
|
+
data.tar.gz: 5c7abac9d356d50d60617231fef6ccc7746be8106aa3ad356b49873143f2ccd6815e568334f8c118fe5229339089f27778d0bc51022c696a9159ca062c284bc9
|
data/CHANGELOG
CHANGED
data/lib/elasticity/search.rb
CHANGED
@@ -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
|
data/lib/elasticity/version.rb
CHANGED
@@ -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
|
-
|
28
|
-
|
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.
|
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-
|
11
|
+
date: 2016-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|