elastic-rails 0.1.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +46 -0
- data/elastic.gemspec +13 -4
- data/lib/elastic/commands/build_agg_from_params.rb +63 -0
- data/lib/elastic/commands/build_query_from_params.rb +132 -0
- data/lib/elastic/commands/import_index_documents.rb +63 -0
- data/lib/elastic/configuration.rb +61 -0
- data/lib/elastic/core/adaptor.rb +102 -0
- data/lib/elastic/core/base_middleware.rb +43 -0
- data/lib/elastic/core/default_middleware.rb +64 -0
- data/lib/elastic/core/definition.rb +118 -0
- data/lib/elastic/core/mapping_manager.rb +120 -0
- data/lib/elastic/core/middleware.rb +26 -0
- data/lib/elastic/core/query_assembler.rb +84 -0
- data/lib/elastic/core/query_config.rb +25 -0
- data/lib/elastic/core/serializer.rb +45 -0
- data/lib/elastic/core/source_formatter.rb +40 -0
- data/lib/elastic/dsl/bool_query_builder.rb +52 -0
- data/lib/elastic/dsl/bool_query_context.rb +42 -0
- data/lib/elastic/dsl/metric_builder.rb +34 -0
- data/lib/elastic/fields/nested.rb +42 -0
- data/lib/elastic/fields/value.rb +60 -0
- data/lib/elastic/nested_type.rb +5 -0
- data/lib/elastic/nodes/agg/average.rb +7 -0
- data/lib/elastic/nodes/agg/base_metric.rb +42 -0
- data/lib/elastic/nodes/agg/date_histogram.rb +48 -0
- data/lib/elastic/nodes/agg/maximum.rb +7 -0
- data/lib/elastic/nodes/agg/minimum.rb +7 -0
- data/lib/elastic/nodes/agg/stats.rb +7 -0
- data/lib/elastic/nodes/agg/sum.rb +7 -0
- data/lib/elastic/nodes/agg/terms.rb +38 -0
- data/lib/elastic/nodes/agg/top_hits.rb +17 -0
- data/lib/elastic/nodes/and.rb +45 -0
- data/lib/elastic/nodes/base.rb +34 -0
- data/lib/elastic/nodes/base_agg.rb +32 -0
- data/lib/elastic/nodes/boolean.rb +87 -0
- data/lib/elastic/nodes/concerns/aggregable.rb +52 -0
- data/lib/elastic/nodes/concerns/boostable.rb +25 -0
- data/lib/elastic/nodes/concerns/bucketed.rb +17 -0
- data/lib/elastic/nodes/concerns/hit_provider.rb +39 -0
- data/lib/elastic/nodes/function_score.rb +116 -0
- data/lib/elastic/nodes/match.rb +45 -0
- data/lib/elastic/nodes/nested.rb +42 -0
- data/lib/elastic/nodes/or.rb +9 -0
- data/lib/elastic/nodes/range.rb +36 -0
- data/lib/elastic/nodes/search.rb +48 -0
- data/lib/elastic/nodes/term.rb +58 -0
- data/lib/elastic/query.rb +84 -22
- data/lib/elastic/railtie.rb +41 -0
- data/lib/elastic/railties/ar_helpers.rb +51 -0
- data/lib/elastic/railties/ar_middleware.rb +45 -0
- data/lib/elastic/{indexable_record.rb → railties/indexable_record.rb} +21 -18
- data/lib/elastic/railties/query_extensions.rb +9 -0
- data/lib/elastic/railties/rspec.rb +6 -0
- data/lib/elastic/railties/tasks/es.rake +19 -0
- data/lib/elastic/railties/type_extensions.rb +14 -0
- data/lib/elastic/railties/utils.rb +62 -0
- data/lib/elastic/results/aggregations.rb +29 -0
- data/lib/elastic/results/base.rb +13 -0
- data/lib/elastic/results/bucket.rb +15 -0
- data/lib/elastic/results/bucket_collection.rb +17 -0
- data/lib/elastic/results/grouped_result.rb +37 -0
- data/lib/elastic/results/hit.rb +25 -0
- data/lib/elastic/results/hit_collection.rb +38 -0
- data/lib/elastic/results/metric.rb +13 -0
- data/lib/elastic/results/result_group.rb +19 -0
- data/lib/elastic/results/root.rb +15 -0
- data/lib/elastic/shims/base.rb +23 -0
- data/lib/elastic/shims/grouping.rb +23 -0
- data/lib/elastic/shims/populating.rb +69 -0
- data/lib/elastic/shims/reducing.rb +20 -0
- data/lib/elastic/support/command.rb +34 -0
- data/lib/elastic/support/transform.rb +37 -0
- data/lib/elastic/support/traversable.rb +22 -0
- data/lib/elastic/type.rb +56 -84
- data/lib/elastic/types/base_type.rb +38 -0
- data/lib/elastic/types/faceted_type.rb +16 -0
- data/lib/elastic/types/nestable_type.rb +14 -0
- data/lib/elastic/version.rb +1 -1
- data/lib/elastic.rb +72 -30
- data/lib/generators/elastic/index_generator.rb +10 -0
- data/lib/generators/elastic/templates/index.rb +17 -0
- metadata +222 -16
- data/lib/elastic/capabilities/aggregation_builder.rb +0 -64
- data/lib/elastic/capabilities/bool_query_builder.rb +0 -74
- data/lib/elastic/capabilities/context_handler.rb +0 -31
- data/lib/elastic/histogram.rb +0 -49
- data/lib/elastic/index.rb +0 -113
- data/lib/elastic/indexable.rb +0 -25
- data/lib/elastic/value_transform.rb +0 -15
data/lib/elastic.rb
CHANGED
@@ -1,44 +1,86 @@
|
|
1
1
|
require "elasticsearch"
|
2
|
+
|
2
3
|
require "elastic/version"
|
4
|
+
require "elastic/configuration"
|
3
5
|
|
4
|
-
require "elastic/
|
5
|
-
require "elastic/
|
6
|
-
require "elastic/
|
6
|
+
require "elastic/support/command"
|
7
|
+
require "elastic/support/transform"
|
8
|
+
require "elastic/support/traversable"
|
7
9
|
|
8
|
-
require "elastic/
|
9
|
-
require "elastic/
|
10
|
-
require "elastic/
|
11
|
-
require "elastic/histogram"
|
12
|
-
require "elastic/value_transform"
|
13
|
-
require "elastic/indexable"
|
14
|
-
require "elastic/indexable_record"
|
10
|
+
require "elastic/commands/import_index_documents"
|
11
|
+
require "elastic/commands/build_query_from_params"
|
12
|
+
require "elastic/commands/build_agg_from_params"
|
15
13
|
|
16
|
-
|
17
|
-
|
14
|
+
require "elastic/results/base"
|
15
|
+
require "elastic/results/aggregations"
|
16
|
+
require "elastic/results/hit"
|
17
|
+
require "elastic/results/hit_collection"
|
18
|
+
require "elastic/results/metric"
|
19
|
+
require "elastic/results/bucket_collection"
|
20
|
+
require "elastic/results/bucket"
|
21
|
+
require "elastic/results/grouped_result"
|
22
|
+
require "elastic/results/result_group"
|
23
|
+
require "elastic/results/root"
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
25
|
+
require "elastic/nodes/base"
|
26
|
+
require "elastic/nodes/base_agg"
|
27
|
+
require "elastic/nodes/search"
|
28
|
+
require "elastic/nodes/term"
|
29
|
+
require "elastic/nodes/range"
|
30
|
+
require "elastic/nodes/match"
|
31
|
+
require "elastic/nodes/and"
|
32
|
+
require "elastic/nodes/or"
|
33
|
+
require "elastic/nodes/boolean"
|
34
|
+
require "elastic/nodes/function_score"
|
35
|
+
require "elastic/nodes/nested"
|
36
|
+
require "elastic/nodes/agg/base_metric"
|
37
|
+
require "elastic/nodes/agg/stats"
|
38
|
+
require "elastic/nodes/agg/average"
|
39
|
+
require "elastic/nodes/agg/minimum"
|
40
|
+
require "elastic/nodes/agg/maximum"
|
41
|
+
require "elastic/nodes/agg/sum"
|
42
|
+
require "elastic/nodes/agg/terms"
|
43
|
+
require "elastic/nodes/agg/date_histogram"
|
44
|
+
require "elastic/nodes/agg/top_hits"
|
22
45
|
|
23
|
-
|
46
|
+
require "elastic/shims/base"
|
47
|
+
require "elastic/shims/populating"
|
48
|
+
require "elastic/shims/grouping"
|
49
|
+
require "elastic/shims/reducing"
|
24
50
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
51
|
+
require "elastic/fields/value"
|
52
|
+
require "elastic/fields/nested"
|
28
53
|
|
29
|
-
|
30
|
-
|
31
|
-
|
54
|
+
require "elastic/core/definition"
|
55
|
+
require "elastic/core/adaptor"
|
56
|
+
require "elastic/core/mapping_manager"
|
57
|
+
require "elastic/core/serializer"
|
58
|
+
require "elastic/core/middleware"
|
59
|
+
require "elastic/core/base_middleware"
|
60
|
+
require "elastic/core/default_middleware"
|
61
|
+
require "elastic/core/source_formatter"
|
62
|
+
require "elastic/core/query_config"
|
63
|
+
require "elastic/core/query_assembler"
|
32
64
|
|
33
|
-
|
34
|
-
|
65
|
+
require "elastic/dsl/bool_query_builder"
|
66
|
+
require "elastic/dsl/bool_query_context"
|
67
|
+
require "elastic/dsl/metric_builder"
|
68
|
+
|
69
|
+
require "elastic/types/base_type"
|
70
|
+
require "elastic/types/faceted_type"
|
71
|
+
require "elastic/types/nestable_type"
|
72
|
+
require "elastic/type"
|
73
|
+
require "elastic/nested_type"
|
74
|
+
require "elastic/query"
|
75
|
+
|
76
|
+
module Elastic
|
77
|
+
def self.configure(*_args)
|
78
|
+
Configuration.configure(*_args)
|
35
79
|
end
|
36
80
|
|
37
|
-
def
|
38
|
-
|
39
|
-
Elasticsearch::Client.new(
|
40
|
-
host: uri ? uri.host : config['host'],
|
41
|
-
port: uri ? uri.port : config['port']
|
42
|
-
)
|
81
|
+
def self.register_middleware(_middleware)
|
82
|
+
Core::Middleware.register _middleware
|
43
83
|
end
|
44
84
|
end
|
85
|
+
|
86
|
+
require "elastic/railtie" if defined? Rails
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Elastic
|
2
|
+
class IndexGenerator < Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path("../templates", __FILE__)
|
4
|
+
|
5
|
+
desc "This generator creates a new model index definition at app/indices"
|
6
|
+
def create_index
|
7
|
+
template('index.rb', "app/indices/#{file_name.underscore}_index.rb")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class <%= class_name %>Index < Elastic::Type
|
2
|
+
# Index model fields by adding field definitions.
|
3
|
+
#
|
4
|
+
# Some examples:
|
5
|
+
#
|
6
|
+
# fields :foo, :bar
|
7
|
+
# field :timestamp, type: :date
|
8
|
+
# field :category, type: :term
|
9
|
+
# field :complex, transform: -> { "#{property_1}/#{property_2}" }
|
10
|
+
# field :custom
|
11
|
+
#
|
12
|
+
# def custom
|
13
|
+
# "foobar"
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
end
|
17
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Baixas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.18
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,48 +27,183 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.18
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: bundler
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
30
50
|
requirements:
|
31
51
|
- - "~>"
|
32
52
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
53
|
+
version: '1.6'
|
34
54
|
type: :development
|
35
55
|
prerelease: false
|
36
56
|
version_requirements: !ruby/object:Gem::Requirement
|
37
57
|
requirements:
|
38
58
|
- - "~>"
|
39
59
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
60
|
+
version: '1.6'
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: rake
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
44
64
|
requirements:
|
45
65
|
- - "~>"
|
46
66
|
- !ruby/object:Gem::Version
|
47
|
-
version: '10.
|
67
|
+
version: '10.4'
|
48
68
|
type: :development
|
49
69
|
prerelease: false
|
50
70
|
version_requirements: !ruby/object:Gem::Requirement
|
51
71
|
requirements:
|
52
72
|
- - "~>"
|
53
73
|
- !ruby/object:Gem::Version
|
54
|
-
version: '10.
|
74
|
+
version: '10.4'
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: rspec
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
58
78
|
requirements:
|
59
79
|
- - "~>"
|
60
80
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
81
|
+
version: '3.1'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.1'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec-nc
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.2'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.2'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: guard
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.11'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '2.11'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: guard-rspec
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '4.5'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '4.5'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: terminal-notifier-guard
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.6'
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 1.6.1
|
141
|
+
type: :development
|
142
|
+
prerelease: false
|
143
|
+
version_requirements: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '1.6'
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 1.6.1
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: pry
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - "~>"
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0.10'
|
158
|
+
type: :development
|
159
|
+
prerelease: false
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - "~>"
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0.10'
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
name: pry-remote
|
167
|
+
requirement: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - "~>"
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0.1'
|
172
|
+
type: :development
|
173
|
+
prerelease: false
|
174
|
+
version_requirements: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - "~>"
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0.1'
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: pry-byebug
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - "~>"
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '3.2'
|
186
|
+
type: :development
|
187
|
+
prerelease: false
|
188
|
+
version_requirements: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - "~>"
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '3.2'
|
193
|
+
- !ruby/object:Gem::Dependency
|
194
|
+
name: pry-nav
|
195
|
+
requirement: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - "~>"
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '0.2'
|
62
200
|
type: :development
|
63
201
|
prerelease: false
|
64
202
|
version_requirements: !ruby/object:Gem::Requirement
|
65
203
|
requirements:
|
66
204
|
- - "~>"
|
67
205
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
206
|
+
version: '0.2'
|
69
207
|
description: Elasticsearch integration for Ruby on Rails by Platanus
|
70
208
|
email:
|
71
209
|
- ignacio@platan.us
|
@@ -78,6 +216,7 @@ files:
|
|
78
216
|
- ".travis.yml"
|
79
217
|
- CODE_OF_CONDUCT.md
|
80
218
|
- Gemfile
|
219
|
+
- Guardfile
|
81
220
|
- LICENSE.txt
|
82
221
|
- README.md
|
83
222
|
- Rakefile
|
@@ -86,17 +225,84 @@ files:
|
|
86
225
|
- elastic.gemspec
|
87
226
|
- lib/elastic-rails.rb
|
88
227
|
- lib/elastic.rb
|
89
|
-
- lib/elastic/
|
90
|
-
- lib/elastic/
|
91
|
-
- lib/elastic/
|
92
|
-
- lib/elastic/
|
93
|
-
- lib/elastic/
|
94
|
-
- lib/elastic/
|
95
|
-
- lib/elastic/
|
228
|
+
- lib/elastic/commands/build_agg_from_params.rb
|
229
|
+
- lib/elastic/commands/build_query_from_params.rb
|
230
|
+
- lib/elastic/commands/import_index_documents.rb
|
231
|
+
- lib/elastic/configuration.rb
|
232
|
+
- lib/elastic/core/adaptor.rb
|
233
|
+
- lib/elastic/core/base_middleware.rb
|
234
|
+
- lib/elastic/core/default_middleware.rb
|
235
|
+
- lib/elastic/core/definition.rb
|
236
|
+
- lib/elastic/core/mapping_manager.rb
|
237
|
+
- lib/elastic/core/middleware.rb
|
238
|
+
- lib/elastic/core/query_assembler.rb
|
239
|
+
- lib/elastic/core/query_config.rb
|
240
|
+
- lib/elastic/core/serializer.rb
|
241
|
+
- lib/elastic/core/source_formatter.rb
|
242
|
+
- lib/elastic/dsl/bool_query_builder.rb
|
243
|
+
- lib/elastic/dsl/bool_query_context.rb
|
244
|
+
- lib/elastic/dsl/metric_builder.rb
|
245
|
+
- lib/elastic/fields/nested.rb
|
246
|
+
- lib/elastic/fields/value.rb
|
247
|
+
- lib/elastic/nested_type.rb
|
248
|
+
- lib/elastic/nodes/agg/average.rb
|
249
|
+
- lib/elastic/nodes/agg/base_metric.rb
|
250
|
+
- lib/elastic/nodes/agg/date_histogram.rb
|
251
|
+
- lib/elastic/nodes/agg/maximum.rb
|
252
|
+
- lib/elastic/nodes/agg/minimum.rb
|
253
|
+
- lib/elastic/nodes/agg/stats.rb
|
254
|
+
- lib/elastic/nodes/agg/sum.rb
|
255
|
+
- lib/elastic/nodes/agg/terms.rb
|
256
|
+
- lib/elastic/nodes/agg/top_hits.rb
|
257
|
+
- lib/elastic/nodes/and.rb
|
258
|
+
- lib/elastic/nodes/base.rb
|
259
|
+
- lib/elastic/nodes/base_agg.rb
|
260
|
+
- lib/elastic/nodes/boolean.rb
|
261
|
+
- lib/elastic/nodes/concerns/aggregable.rb
|
262
|
+
- lib/elastic/nodes/concerns/boostable.rb
|
263
|
+
- lib/elastic/nodes/concerns/bucketed.rb
|
264
|
+
- lib/elastic/nodes/concerns/hit_provider.rb
|
265
|
+
- lib/elastic/nodes/function_score.rb
|
266
|
+
- lib/elastic/nodes/match.rb
|
267
|
+
- lib/elastic/nodes/nested.rb
|
268
|
+
- lib/elastic/nodes/or.rb
|
269
|
+
- lib/elastic/nodes/range.rb
|
270
|
+
- lib/elastic/nodes/search.rb
|
271
|
+
- lib/elastic/nodes/term.rb
|
96
272
|
- lib/elastic/query.rb
|
273
|
+
- lib/elastic/railtie.rb
|
274
|
+
- lib/elastic/railties/ar_helpers.rb
|
275
|
+
- lib/elastic/railties/ar_middleware.rb
|
276
|
+
- lib/elastic/railties/indexable_record.rb
|
277
|
+
- lib/elastic/railties/query_extensions.rb
|
278
|
+
- lib/elastic/railties/rspec.rb
|
279
|
+
- lib/elastic/railties/tasks/es.rake
|
280
|
+
- lib/elastic/railties/type_extensions.rb
|
281
|
+
- lib/elastic/railties/utils.rb
|
282
|
+
- lib/elastic/results/aggregations.rb
|
283
|
+
- lib/elastic/results/base.rb
|
284
|
+
- lib/elastic/results/bucket.rb
|
285
|
+
- lib/elastic/results/bucket_collection.rb
|
286
|
+
- lib/elastic/results/grouped_result.rb
|
287
|
+
- lib/elastic/results/hit.rb
|
288
|
+
- lib/elastic/results/hit_collection.rb
|
289
|
+
- lib/elastic/results/metric.rb
|
290
|
+
- lib/elastic/results/result_group.rb
|
291
|
+
- lib/elastic/results/root.rb
|
292
|
+
- lib/elastic/shims/base.rb
|
293
|
+
- lib/elastic/shims/grouping.rb
|
294
|
+
- lib/elastic/shims/populating.rb
|
295
|
+
- lib/elastic/shims/reducing.rb
|
296
|
+
- lib/elastic/support/command.rb
|
297
|
+
- lib/elastic/support/transform.rb
|
298
|
+
- lib/elastic/support/traversable.rb
|
97
299
|
- lib/elastic/type.rb
|
98
|
-
- lib/elastic/
|
300
|
+
- lib/elastic/types/base_type.rb
|
301
|
+
- lib/elastic/types/faceted_type.rb
|
302
|
+
- lib/elastic/types/nestable_type.rb
|
99
303
|
- lib/elastic/version.rb
|
304
|
+
- lib/generators/elastic/index_generator.rb
|
305
|
+
- lib/generators/elastic/templates/index.rb
|
100
306
|
homepage: https://github.com/surbtc/elastic-rails
|
101
307
|
licenses:
|
102
308
|
- MIT
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Elastic::Capabilities
|
2
|
-
module AggregationBuilder
|
3
|
-
def aggregate_in(_name)
|
4
|
-
set_context(:aggregate, _name)
|
5
|
-
end
|
6
|
-
|
7
|
-
def aggregate
|
8
|
-
set_context(:aggregate, nil)
|
9
|
-
end
|
10
|
-
|
11
|
-
def sum_of(_field)
|
12
|
-
with_context(:aggregate, :sum_of) do |name|
|
13
|
-
register_aggregation(name || _field, { "sum" => { "field" => _field } })
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def minimum_for(_field)
|
18
|
-
with_context(:aggregate, :minimum_for) do |name|
|
19
|
-
register_aggregation(name || _field, { "min" => { "field" => _field } })
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def maximum_for(_field)
|
24
|
-
with_context(:aggregate, :maximum_for) do |name|
|
25
|
-
register_aggregation(name || _field, { "max" => { "field" => _field } })
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def average_for(_field)
|
30
|
-
with_context(:aggregate, :average_for) do |name|
|
31
|
-
register_aggregation(name || _field, { "avg" => { "field" => _field } })
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def date_histogram_for(_field, resolution: '1d', &_block)
|
36
|
-
with_context(:aggregate, :date_histogram_for) do |name|
|
37
|
-
histogram = Elastic::Histogram.new _field, resolution
|
38
|
-
_block.call(histogram) if _block
|
39
|
-
register_aggregation(name || _field, histogram)
|
40
|
-
return histogram unless _block
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def aggregations
|
47
|
-
@aggregations ||= []
|
48
|
-
end
|
49
|
-
|
50
|
-
def register_aggregation(_name, _definition)
|
51
|
-
aggregations << [_name, _definition]
|
52
|
-
end
|
53
|
-
|
54
|
-
def render_aggregations_to(_to)
|
55
|
-
return if aggregations.length == 0
|
56
|
-
|
57
|
-
_to['aggs'] = aggs = {}
|
58
|
-
|
59
|
-
aggregations.each do |name, definition|
|
60
|
-
aggs[name] = definition.respond_to?(:render) ? definition.render : definition
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module Elastic::Capabilities
|
2
|
-
module BoolQueryBuilder
|
3
|
-
def minimum_should_match
|
4
|
-
@minimum_should_match || 1
|
5
|
-
end
|
6
|
-
|
7
|
-
def minimum_should_match=(_value)
|
8
|
-
@minimum_should_match = _value
|
9
|
-
end
|
10
|
-
|
11
|
-
def should_have(_field)
|
12
|
-
set_context(:should_have, [should_parts, _field])
|
13
|
-
end
|
14
|
-
|
15
|
-
def must_have(_field)
|
16
|
-
set_context(:must_have, [must_parts, _field])
|
17
|
-
end
|
18
|
-
|
19
|
-
def in(*_terms)
|
20
|
-
with_context([:should_have, :must_have], :in) do |context, field|
|
21
|
-
raise ArgumentError, 'must provide at least one term' if _terms.length == 0
|
22
|
-
|
23
|
-
_terms = _terms.map { |t| transform_input(field, t) }
|
24
|
-
|
25
|
-
context << (_terms.length > 1 ?
|
26
|
-
{ "terms" => { field.to_s => _terms } } :
|
27
|
-
{ "term" => { field.to_s => _terms.first } }
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
alias :equal_to :in
|
33
|
-
|
34
|
-
def in_range(_range)
|
35
|
-
with_context([:should_have, :must_have], :in_range) do |context, field|
|
36
|
-
options = { }
|
37
|
-
|
38
|
-
case _range
|
39
|
-
when Range
|
40
|
-
options['gte'] = _range.begin
|
41
|
-
options['lt'] = _range.end if _range.exclude_end?
|
42
|
-
options['lte'] = _range.end if !_range.exclude_end?
|
43
|
-
when Hash
|
44
|
-
[:gte, :gt, :lte, :lt].each do |opt|
|
45
|
-
options[opt.to_s] = _range[opt] if _range.key? opt
|
46
|
-
end
|
47
|
-
else
|
48
|
-
raise ArgumentError, 'must provide a range or a set of options'
|
49
|
-
end
|
50
|
-
|
51
|
-
context << { "range" => { field.to_s => options } }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def must_parts
|
58
|
-
@must_parts ||= []
|
59
|
-
end
|
60
|
-
|
61
|
-
def should_parts
|
62
|
-
@should_parts ||= []
|
63
|
-
end
|
64
|
-
|
65
|
-
def render_bool_query_to(_to)
|
66
|
-
return if should_parts.length == 0 && must_parts.length == 0
|
67
|
-
|
68
|
-
bool = _to['bool'] = {}
|
69
|
-
bool['must'] = must_parts if must_parts.length > 0
|
70
|
-
bool['should'] = should_parts if should_parts.length > 0
|
71
|
-
bool['minimum_should_match'] = minimum_should_match if should_parts.length > 0
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Elastic::Capabilities
|
2
|
-
module ContextHandler
|
3
|
-
private
|
4
|
-
|
5
|
-
def set_context(_name, _data)
|
6
|
-
unless @context_name.nil?
|
7
|
-
raise ArgumentError, "#{_name} should not be called right after #{@context_name}"
|
8
|
-
end
|
9
|
-
|
10
|
-
@context_name = _name.to_sym
|
11
|
-
@context_data = _data
|
12
|
-
self
|
13
|
-
end
|
14
|
-
|
15
|
-
def with_context(_names, _caller)
|
16
|
-
_names = [_names] unless _names.is_a? Array
|
17
|
-
_names = _names.map(&:to_sym)
|
18
|
-
|
19
|
-
if @context_name.nil?
|
20
|
-
raise ArgumentError, "#{_caller} should be called after #{_names.join(' or ')}"
|
21
|
-
elsif !_names.include? @context_name
|
22
|
-
raise ArgumentError, "#{_caller} should not be called after #{@context_name}"
|
23
|
-
end
|
24
|
-
|
25
|
-
yield @context_data
|
26
|
-
return self
|
27
|
-
ensure
|
28
|
-
@context_name = @context_data = nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/elastic/histogram.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
module Elastic
|
2
|
-
class Histogram
|
3
|
-
include Capabilities::ContextHandler
|
4
|
-
include Capabilities::AggregationBuilder
|
5
|
-
|
6
|
-
attr_accessor :resolution
|
7
|
-
|
8
|
-
def initialize(_time_field, _resolution)
|
9
|
-
@time_field = _time_field
|
10
|
-
@resolution = _resolution
|
11
|
-
end
|
12
|
-
|
13
|
-
def open_for(_field)
|
14
|
-
with_context(:aggregate, :open_for) do |name|
|
15
|
-
register_aggregation(name, {
|
16
|
-
top_hits: {
|
17
|
-
sort: [{ @time_field => { order: "asc" } }],
|
18
|
-
_source: { include: [ _field ] },
|
19
|
-
size: 1
|
20
|
-
}
|
21
|
-
})
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def close_for(_field)
|
26
|
-
with_context(:aggregate, :close_for) do |name|
|
27
|
-
register_aggregation(name, {
|
28
|
-
top_hits: {
|
29
|
-
sort: [{ @time_field => { order: "desc" } }],
|
30
|
-
_source: { include: [ _field ] },
|
31
|
-
size: 1
|
32
|
-
}
|
33
|
-
})
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def render
|
38
|
-
json = {
|
39
|
-
date_histogram: {
|
40
|
-
field: @time_field,
|
41
|
-
interval: @resolution,
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
render_aggregations_to json
|
46
|
-
json
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|