esse 0.1.3 → 0.2.0
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a31d2a1c181dccd9c2acd7256d958010e7c636016b1d5a267597f7aec9ed3334
|
4
|
+
data.tar.gz: cdb390a10b0492833a9360d4fd39df0c18df114a44b37554cba1dd39d229f75b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59ae5dcafd8998c69e5705910b119f5f9d1333899a4320b8f7afa4c5782aa435d820dde222726de111cee00c6d3b4bbed9d6fdd18dac6a6f740cf64138b70d53
|
7
|
+
data.tar.gz: 84b876eaec5b090718e2d265dd5d9456c5dfaeedafdae6e9361ac790de91eab0ba46b9ceabee3c5e8a891c5027ff3ac8443217554219f8dce5f52c853912989c
|
@@ -19,10 +19,10 @@ module Esse
|
|
19
19
|
suffix ||= Esse.timestamp
|
20
20
|
suffix = Esse.timestamp while exist?(suffix: suffix).tap { |exist| existing << suffix if exist }
|
21
21
|
|
22
|
-
create_index!(suffix: suffix,
|
23
|
-
import!(suffix: suffix
|
22
|
+
create_index!(**options, suffix: suffix, alias: false)
|
23
|
+
import!(**options, suffix: suffix)
|
24
24
|
update_aliases!(suffix: suffix)
|
25
|
-
existing.each { |_s| delete_index!(suffix: suffix
|
25
|
+
existing.each { |_s| delete_index!(**options, suffix: suffix) }
|
26
26
|
true
|
27
27
|
end
|
28
28
|
end
|
@@ -11,7 +11,7 @@ module Esse
|
|
11
11
|
# @option [Hash] :context The collection context. This value will be passed as argument to the collection
|
12
12
|
# May be SQL condition or any other filter you have defined on the collection.
|
13
13
|
def import(context: {}, suffix: nil, **options)
|
14
|
-
each_serialized_batch(context || {}) do |batch|
|
14
|
+
each_serialized_batch(**(context || {})) do |batch|
|
15
15
|
bulk(index: batch, suffix: suffix, **options)
|
16
16
|
end
|
17
17
|
end
|
@@ -22,8 +22,8 @@ class <%= @index_name %> < <%= @base_class %>
|
|
22
22
|
# collection Collections::DocumentCollection
|
23
23
|
#
|
24
24
|
# but you can also use block definition style:
|
25
|
-
# collection do
|
26
|
-
# block.call [{ title: 'foo' }, { title: 'bar' }],
|
25
|
+
# collection do |**context, &block|
|
26
|
+
# block.call [{ title: 'foo' }, { title: 'bar' }], extra: 'info'
|
27
27
|
# end
|
28
28
|
#
|
29
29
|
# Serializer block or class yielder should be called with an array of objects.
|
@@ -78,7 +78,7 @@ class <%= @index_name %> < <%= @base_class %>
|
|
78
78
|
# Useful for eager loading data from database or any other repository. Below is an example of a rails like
|
79
79
|
# application could load using activerecord.
|
80
80
|
#
|
81
|
-
# collection do
|
81
|
+
# collection do |**context, &block|
|
82
82
|
# <%= type.camelize %>.where(context[:conditions]).find_in_batches(batch_size: 5000) do |batch|
|
83
83
|
# block.call batch, context
|
84
84
|
# end
|
@@ -86,10 +86,10 @@ module Esse
|
|
86
86
|
# @param args [*Object] Any argument is allowed here. The collection will be called with same arguments.
|
87
87
|
# And the serializer will be initialized with those arguments too.
|
88
88
|
# @yield [Array, *Object] serialized collection and method arguments
|
89
|
-
def each_serialized_batch(
|
90
|
-
each_batch(
|
91
|
-
entries = batch.map { |entry| serialize(entry,
|
92
|
-
block.call(entries,
|
89
|
+
def each_serialized_batch(**kwargs, &block)
|
90
|
+
each_batch(**kwargs) do |*batch, **collection_kwargs|
|
91
|
+
entries = batch.flatten.map { |entry| serialize(entry, **collection_kwargs) }.compact
|
92
|
+
block.call(entries, **kwargs)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -99,9 +99,9 @@ module Esse
|
|
99
99
|
# GeosIndex.documents(id: 1).first
|
100
100
|
#
|
101
101
|
# @return [Enumerator] All serialized entries
|
102
|
-
def documents(
|
102
|
+
def documents(**kwargs)
|
103
103
|
Enumerator.new do |yielder|
|
104
|
-
each_serialized_batch(
|
104
|
+
each_serialized_batch(**kwargs) do |documents, **_collection_kargs|
|
105
105
|
documents.each { |document| yielder.yield(document) }
|
106
106
|
end
|
107
107
|
end
|
data/lib/esse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos G. Zimmermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exec
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -260,7 +260,6 @@ files:
|
|
260
260
|
- lib/esse/cluster.rb
|
261
261
|
- lib/esse/config.rb
|
262
262
|
- lib/esse/core.rb
|
263
|
-
- lib/esse/document.rb
|
264
263
|
- lib/esse/errors.rb
|
265
264
|
- lib/esse/events.rb
|
266
265
|
- lib/esse/events/bus.rb
|
data/lib/esse/document.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Esse
|
4
|
-
# @abstract
|
5
|
-
#
|
6
|
-
# A document is a class that represents a single JSON document to be indexed
|
7
|
-
class Document
|
8
|
-
def initialize(entry, **context)
|
9
|
-
@source = item
|
10
|
-
@context = context
|
11
|
-
end
|
12
|
-
|
13
|
-
# Returns the Elasticsearch `_id` for the document.
|
14
|
-
#
|
15
|
-
# @return [String, Number] The Elasticsearch `_id` for the document
|
16
|
-
# @abstract
|
17
|
-
def id
|
18
|
-
raise NotImplementedError
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns the Elasticsearch `_routing` for the item. Elasticsearch
|
22
|
-
# default if this value is not provided is to use the `_id`.
|
23
|
-
# Setting this value to `false` or `nil` will omit sending the
|
24
|
-
# meta-field with your requests and use default routing behaviour.
|
25
|
-
#
|
26
|
-
# @return [String, NilClass, Boolean] The Elasticsearch `_routing` for the document
|
27
|
-
# @abstract
|
28
|
-
def routing
|
29
|
-
end
|
30
|
-
|
31
|
-
def attributes
|
32
|
-
{}
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_h
|
36
|
-
{
|
37
|
-
_id: id,
|
38
|
-
}.tap do |hash|
|
39
|
-
hash[:_routing] = routing if routing
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|