elasticsearch_record 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/docs/CHANGELOG.md +14 -0
- data/lib/active_record/connection_adapters/elasticsearch/schema_definitions/column_methods.rb +13 -4
- data/lib/elasticsearch_record/gem_version.rb +1 -1
- data/lib/elasticsearch_record/model_api.rb +5 -2
- data/lib/elasticsearch_record/relation/calculation_methods.rb +57 -13
- data/lib/elasticsearch_record/relation/result_methods.rb +1 -2
- data/lib/elasticsearch_record/relation/value_methods.rb +1 -1
- data/lib/elasticsearch_record/schema_migration.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef01a33de054cbae1fe582ba5f7d8a5910c73dd81e3395f8b6c07ec9d3a5fbe2
|
4
|
+
data.tar.gz: d574bafc90b201869727539fd0a0c148118d6f666f9f29400690613bd7cbbaa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89ac7c99f35a36650c2ac8f00600f0c702ed8ec4c4aaa5d28ad86c329a66be3625d063ada9dd8c6630b8b30eea1a5283a0231a60c0d8021242adeae4efe86316
|
7
|
+
data.tar.gz: b44f713a1650100a925c94349fcb9fdce4b72bf5acb901c5ff04b871e0586115bf5e08e42f38cd9ecb0e550663977da48e430a739b67230ced4eb29aa4f5bb8b
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ _ElasticsearchRecord is a ActiveRecord adapter and provides similar functionalit
|
|
14
14
|
|
15
15
|
**PLEASE NOTE:**
|
16
16
|
|
17
|
-
- This is the `
|
17
|
+
- This is the `rails-7-1-stable`-branch, which only supports rails **7.1** _(see section 'Rails_Versions' for supported versions)_
|
18
18
|
- supports ActiveRecord ~> 7.1 + Elasticsearch >= 7.17
|
19
19
|
|
20
20
|
-----
|
@@ -44,11 +44,10 @@ https://github.com/ruby-smart/elasticsearch_record/tree/rails-7-0-stable
|
|
44
44
|
Add this line to your application's Gemfile:
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
gem 'elasticsearch_record'
|
47
|
+
gem 'elasticsearch_record', '~> 1.8'
|
48
48
|
|
49
|
-
#
|
49
|
+
# alternative
|
50
50
|
gem 'elasticsearch_record', git: 'https://github.com/ruby-smart/elasticsearch_record', branch: 'rails-7-1-stable'
|
51
|
-
gem 'elasticsearch_record', git: 'https://github.com/ruby-smart/elasticsearch_record', branch: 'rails-7-0-stable'
|
52
51
|
|
53
52
|
```
|
54
53
|
|
@@ -88,7 +87,7 @@ To raise an exception while using transactions on a ElasticsearchRecord model, t
|
|
88
87
|
However enabling this flag will surely fail transactional tests _(prevent this with 'use_transactional_tests=false')_
|
89
88
|
|
90
89
|
```ruby
|
91
|
-
# config/initializers/elasticsearch_record.
|
90
|
+
# config/initializers/elasticsearch_record.rb
|
92
91
|
|
93
92
|
# enable transactional exceptions
|
94
93
|
ElasticsearchRecord.error_on_transaction = true
|
data/docs/CHANGELOG.md
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
# ElasticsearchRecord - CHANGELOG
|
2
2
|
|
3
|
+
## [1.8.1] - 2024-05-07
|
4
|
+
* [add] new elasticsearch mapping types _(percolator, geo, vector, texts, ...)_
|
5
|
+
* [ref] `ElasticsearchRecord::Relation#limit` to detect `Float::INFINITY` to also set the **max_result_window**
|
6
|
+
* [fix] `ElasticsearchRecord::SchemaMigration` only returning the first ten migrations (broke migrated migrations)
|
7
|
+
* [fix] `ElasticsearchRecord::Relation::CalculationMethods#calculate` method incompatibility - renamed to `#calculate_aggregation` (+ alias to `#calculate`)
|
8
|
+
* [fix] `ElasticsearchRecord::ModelApi#bulk` method not correctly generating data for 'delete'
|
9
|
+
|
3
10
|
## [1.8.0] - 2024-01-10
|
4
11
|
* [ref] major method & dependency refactoring for `rails 7.1` - _(Does **NOT** work with rails 7.0)_
|
5
12
|
* [add] new repository branch `rails-7-1-stable` to support different rails version
|
6
13
|
* [ref] gemspec to lock on rails 7.1
|
7
14
|
|
15
|
+
## [1.7.3] - 2024-05-07 _(no gem release)_
|
16
|
+
* [add] new elasticsearch mapping types _(percolator, geo, vector, texts, ...)_
|
17
|
+
* [ref] `ElasticsearchRecord::Relation#limit` to detect `Float::INFINITY` to also set the **max_result_window**
|
18
|
+
* [fix] `ElasticsearchRecord::SchemaMigration` only returning the first ten migrations (broke migrated migrations)
|
19
|
+
* [fix] `ElasticsearchRecord::Relation::CalculationMethods#calculate` method incompatibility - renamed to `#calculate_aggregation` (+ alias to `#calculate`)
|
20
|
+
* [fix] `ElasticsearchRecord::ModelApi#bulk` method not correctly generating data for 'delete'
|
21
|
+
|
8
22
|
## [1.7.2] - 2024-01-10
|
9
23
|
* [ref] gemspec to lock on rails 7.0
|
10
24
|
|
data/lib/active_record/connection_adapters/elasticsearch/schema_definitions/column_methods.rb
CHANGED
@@ -8,11 +8,20 @@ module ActiveRecord
|
|
8
8
|
|
9
9
|
included do
|
10
10
|
# see @ ::ActiveRecord::ConnectionAdapters::ElasticsearchAdapter::NATIVE_DATABASE_TYPES.keys
|
11
|
-
define_column_methods :string, :blob, :datetime, :bigint, :json,
|
12
|
-
:
|
13
|
-
:
|
11
|
+
define_column_methods :string, :blob, :datetime, :bigint, :json,
|
12
|
+
:binary, :boolean,
|
13
|
+
:keyword, :constant_keyword, :wildcard,
|
14
|
+
:long, :integer, :short, :byte, :double, :float, :half_float, :scaled_float, :unsigned_long,
|
15
|
+
:date, :date_nanos,
|
16
|
+
:alias,
|
17
|
+
:object, :flattened, :nested, :join,
|
14
18
|
:integer_range, :float_range, :long_range, :double_range, :date_range, :ip_range,
|
15
|
-
:ip, :version, :
|
19
|
+
:ip, :version, :murmur3,
|
20
|
+
:aggregate_metric_double, :histogram,
|
21
|
+
:text, :match_only_text, :completion, :search_as_you_type, :token_count,
|
22
|
+
:dense_vector, :sparse_vector, :rank_feature, :rank_features,
|
23
|
+
:geo_point, :geo_shape, :point, :shape,
|
24
|
+
:percolator
|
16
25
|
|
17
26
|
# Appends a primary key definition to the table definition.
|
18
27
|
# Can be called multiple times, but this is probably not a good idea.
|
@@ -269,8 +269,11 @@ module ElasticsearchRecord
|
|
269
269
|
|
270
270
|
_connection.api(:core, :bulk, {
|
271
271
|
index: _index_name,
|
272
|
-
body:
|
273
|
-
|
272
|
+
body: case operation
|
273
|
+
when :update
|
274
|
+
data.map { |item| { update: { _id: (item[:_id].presence || item['_id']), data: { doc: item.except(:_id, '_id') } } } }
|
275
|
+
when :delete
|
276
|
+
data.map { |item| { delete: { _id: (item[:_id].presence || item['_id']) } } }
|
274
277
|
else
|
275
278
|
data.map { |item| { operation => { _id: (item[:_id].presence || item['_id']), data: item.except(:_id, '_id') } } }
|
276
279
|
end,
|
@@ -64,9 +64,12 @@ module ElasticsearchRecord
|
|
64
64
|
#
|
65
65
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-boxplot-aggregation.html
|
66
66
|
#
|
67
|
+
# @note returns *nil* on a *NullRelation*
|
68
|
+
#
|
67
69
|
# @param [Symbol, String] column_name
|
70
|
+
# @return [Hash,nil]
|
68
71
|
def boxplot(column_name)
|
69
|
-
|
72
|
+
calculate_aggregation(:boxplot, column_name)
|
70
73
|
end
|
71
74
|
|
72
75
|
# A multi-value metrics aggregation that computes stats over numeric values extracted from the aggregated documents. #
|
@@ -83,9 +86,12 @@ module ElasticsearchRecord
|
|
83
86
|
#
|
84
87
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
|
85
88
|
#
|
89
|
+
# @note returns *nil* on a *NullRelation*
|
90
|
+
#
|
86
91
|
# @param [Symbol, String] column_name
|
92
|
+
# @return [Hash,nil]
|
87
93
|
def stats(column_name)
|
88
|
-
|
94
|
+
calculate_aggregation(:stats, column_name)
|
89
95
|
end
|
90
96
|
|
91
97
|
# A multi-value metrics aggregation that computes statistics over string values extracted from the aggregated documents.
|
@@ -102,9 +108,12 @@ module ElasticsearchRecord
|
|
102
108
|
#
|
103
109
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-string-stats-aggregation.html
|
104
110
|
#
|
111
|
+
# @note returns *nil* on a *NullRelation*
|
112
|
+
#
|
105
113
|
# @param [Symbol, String] column_name
|
114
|
+
# @return [Hash,nil]
|
106
115
|
def string_stats(column_name)
|
107
|
-
|
116
|
+
calculate_aggregation(:string_stats, column_name)
|
108
117
|
end
|
109
118
|
|
110
119
|
# The matrix_stats aggregation is a numeric aggregation that computes the following statistics over a set of document fields:
|
@@ -118,9 +127,12 @@ module ElasticsearchRecord
|
|
118
127
|
#
|
119
128
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-matrix-stats-aggregation.html
|
120
129
|
#
|
130
|
+
# @note returns *nil* on a *NullRelation*
|
131
|
+
#
|
121
132
|
# @param [Array<Symbol|String>] column_names
|
133
|
+
# @return [Hash,nil]
|
122
134
|
def matrix_stats(*column_names)
|
123
|
-
|
135
|
+
calculate_aggregation(:matrix_stats, *column_names)
|
124
136
|
end
|
125
137
|
|
126
138
|
# A multi-value metrics aggregation that calculates one or more
|
@@ -140,9 +152,12 @@ module ElasticsearchRecord
|
|
140
152
|
#
|
141
153
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
|
142
154
|
#
|
155
|
+
# @note returns *nil* on a *NullRelation*
|
156
|
+
#
|
143
157
|
# @param [Symbol, String] column_name
|
158
|
+
# @return [Hash,nil]
|
144
159
|
def percentiles(column_name)
|
145
|
-
|
160
|
+
calculate_aggregation(:percentiles, column_name, node: :values)
|
146
161
|
end
|
147
162
|
|
148
163
|
# A multi-value metrics aggregation that calculates one or more
|
@@ -165,10 +180,13 @@ module ElasticsearchRecord
|
|
165
180
|
#
|
166
181
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-rank-aggregation.html
|
167
182
|
#
|
183
|
+
# @note returns *nil* on a *NullRelation*
|
184
|
+
#
|
168
185
|
# @param [Symbol, String] column_name
|
169
186
|
# @param [Array] values
|
187
|
+
# @return [Hash,nil]
|
170
188
|
def percentile_ranks(column_name, values)
|
171
|
-
|
189
|
+
calculate_aggregation(:percentile_ranks, column_name, opts: { values: values }, node: :values)
|
172
190
|
end
|
173
191
|
|
174
192
|
# Calculates the cardinality on a given column. Returns +0+ if there's no row.
|
@@ -178,9 +196,12 @@ module ElasticsearchRecord
|
|
178
196
|
#
|
179
197
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
|
180
198
|
#
|
199
|
+
# @note returns *nil* on a *NullRelation*
|
200
|
+
#
|
181
201
|
# @param [Symbol, String] column_name
|
202
|
+
# @return [Integer,nil]
|
182
203
|
def cardinality(column_name)
|
183
|
-
|
204
|
+
calculate_aggregation(:cardinality, column_name, node: :value)
|
184
205
|
end
|
185
206
|
|
186
207
|
# Calculates the average value on a given column. Returns +nil+ if there's no row. See #calculate for examples with options.
|
@@ -189,9 +210,12 @@ module ElasticsearchRecord
|
|
189
210
|
#
|
190
211
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
|
191
212
|
#
|
213
|
+
# @note returns *nil* on a *NullRelation*
|
214
|
+
#
|
192
215
|
# @param [Symbol, String] column_name
|
216
|
+
# @return [Float,nil]
|
193
217
|
def average(column_name)
|
194
|
-
|
218
|
+
calculate_aggregation(:avg, column_name, node: :value)
|
195
219
|
end
|
196
220
|
|
197
221
|
# Calculates the minimum value on a given column. The value is returned
|
@@ -202,9 +226,12 @@ module ElasticsearchRecord
|
|
202
226
|
#
|
203
227
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html
|
204
228
|
#
|
229
|
+
# @note returns *nil* on a *NullRelation*
|
230
|
+
#
|
205
231
|
# @param [Symbol, String] column_name
|
232
|
+
# @return [Float,nil]
|
206
233
|
def minimum(column_name)
|
207
|
-
|
234
|
+
calculate_aggregation(:min, column_name, node: :value)
|
208
235
|
end
|
209
236
|
|
210
237
|
# Calculates the maximum value on a given column. The value is returned
|
@@ -215,9 +242,12 @@ module ElasticsearchRecord
|
|
215
242
|
#
|
216
243
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html
|
217
244
|
#
|
245
|
+
# @note returns *nil* on a *NullRelation*
|
246
|
+
#
|
218
247
|
# @param [Symbol, String] column_name
|
248
|
+
# @return [Float,nil]
|
219
249
|
def maximum(column_name)
|
220
|
-
|
250
|
+
calculate_aggregation(:max, column_name, node: :value)
|
221
251
|
end
|
222
252
|
|
223
253
|
# This single-value aggregation approximates the median absolute deviation of its search results.
|
@@ -232,9 +262,12 @@ module ElasticsearchRecord
|
|
232
262
|
#
|
233
263
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-median-absolute-deviation-aggregation.html
|
234
264
|
#
|
265
|
+
# @note returns *nil* on a *NullRelation*
|
266
|
+
#
|
235
267
|
# @param [Symbol, String] column_name
|
268
|
+
# @return [Float,nil]
|
236
269
|
def median_absolute_deviation(column_name)
|
237
|
-
|
270
|
+
calculate_aggregation(:median_absolute_deviation, column_name)
|
238
271
|
end
|
239
272
|
|
240
273
|
# Calculates the sum of values on a given column. The value is returned
|
@@ -245,18 +278,27 @@ module ElasticsearchRecord
|
|
245
278
|
#
|
246
279
|
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html
|
247
280
|
#
|
281
|
+
# @note returns *nil* on a *NullRelation*
|
282
|
+
#
|
248
283
|
# @param [Symbol, String] column_name (optional)
|
284
|
+
# @return [Float,nil]
|
249
285
|
def sum(column_name)
|
250
|
-
|
286
|
+
calculate_aggregation(:sum, column_name, node: :value)
|
251
287
|
end
|
252
288
|
|
253
289
|
# creates a aggregation with the provided metric (e.g. :sum) and columns.
|
254
290
|
# returns the metric node (default: :value) from the aggregations result.
|
291
|
+
#
|
292
|
+
# @note returns *nil* on a *NullRelation*
|
293
|
+
#
|
255
294
|
# @param [Symbol, String] metric
|
256
295
|
# @param [Array<Symbol|String>] columns
|
257
296
|
# @param [Hash] opts - additional arguments that get merged with the metric definition
|
258
297
|
# @param [Symbol] node (default: nil)
|
259
|
-
def
|
298
|
+
def calculate_aggregation(metric, *columns, opts: {}, node: nil)
|
299
|
+
# prevent execution on a *NullRelation*
|
300
|
+
return if null_relation?
|
301
|
+
|
260
302
|
metric_key = "calculate_#{metric}"
|
261
303
|
|
262
304
|
# spawn a new aggregation and return the aggs
|
@@ -272,6 +314,8 @@ module ElasticsearchRecord
|
|
272
314
|
response[metric_key]
|
273
315
|
end
|
274
316
|
end
|
317
|
+
|
318
|
+
alias_method :calculate, :calculate_aggregation
|
275
319
|
end
|
276
320
|
end
|
277
321
|
end
|
@@ -132,11 +132,10 @@ module ElasticsearchRecord
|
|
132
132
|
# resolve only data from hits->hits[{_source}]
|
133
133
|
current_results = if ids_only
|
134
134
|
current_response['hits']['hits'].map { |result| result['_id'] }
|
135
|
-
# future with helper
|
136
|
-
# current_response['hits']['hits'].map.from_hash('_id')
|
137
135
|
else
|
138
136
|
current_response['hits']['hits'].map { |result| result['_source'].merge('_id' => result['_id']) }
|
139
137
|
end
|
138
|
+
|
140
139
|
current_results_length = current_results.length
|
141
140
|
|
142
141
|
# check if we reached the required offset
|
@@ -45,7 +45,7 @@ module ElasticsearchRecord
|
|
45
45
|
|
46
46
|
# overwrite the limit_value setter, to provide a special behaviour of auto-setting the +max_result_window+.
|
47
47
|
def limit_value=(limit)
|
48
|
-
if limit == '__max__' || (limit.nil? && delegate_query_nil_limit?)
|
48
|
+
if limit == '__max__' || limit == Float::INFINITY || (limit.nil? && delegate_query_nil_limit?)
|
49
49
|
super(max_result_window)
|
50
50
|
else
|
51
51
|
super(limit)
|
@@ -8,5 +8,15 @@ module ElasticsearchRecord
|
|
8
8
|
def table_name
|
9
9
|
"#{ElasticsearchRecord::Base.table_name_prefix}#{ElasticsearchRecord::Base.schema_migrations_table_name}#{ElasticsearchRecord::Base.table_name_suffix}"
|
10
10
|
end
|
11
|
+
|
12
|
+
# overwrite method to fix the default limit (= 10) to support returning more than 10 migrations
|
13
|
+
def versions
|
14
|
+
sm = Arel::SelectManager.new(arel_table)
|
15
|
+
sm.project(arel_table[primary_key])
|
16
|
+
sm.order(arel_table[primary_key].asc)
|
17
|
+
sm.take(connection.max_result_window(table_name))
|
18
|
+
|
19
|
+
connection.select_values(sm, "#{self.class} Load")
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Gonsior
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|