elasticgraph-indexer 0.19.2.2 → 1.0.0.rc1
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5788fea72c47b1c983ffc469b17c39d606e655c6ceb465db62b31c2eb59a2a9
|
4
|
+
data.tar.gz: e4a0a9d49a9bb6ae35d0dd0a688289c103e70db9613029f0ed10224e0b474309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e214cebc685a4f948ee862a87e65b59b6ac9bbb87bcfa6ce778e4789f85eb6b2712e653386d0c1de7e0a7af6c42423f09c41ddf98fdcb6a69d5e17fe5f7f119
|
7
|
+
data.tar.gz: 4bee1404c3406dc042b5641d62727d651cdd4985937e36bae182e0ae3111a66b80a49a4afe4625c23f81514b4c39ea0ab711a5254a08329807022695a3f12f55
|
@@ -198,27 +198,11 @@ module ElasticGraph
|
|
198
198
|
client_names_and_results = Support::Threading.parallel_map(ops_by_client_name) do |(client_name, all_ops)|
|
199
199
|
# @type block: [::String, ::Symbol, ::Array[untyped] | ::Hash[_Operation, ::Array[::Integer]]]
|
200
200
|
|
201
|
-
ops, unversioned_ops = all_ops.partition(&:versioned?)
|
201
|
+
ops, unversioned_ops = all_ops.partition(&:versioned?) # : [::Array[Operation::Update], ::Array[Operation::Update]]
|
202
202
|
|
203
203
|
msearch_response =
|
204
204
|
if (client = @datastore_clients_by_name[client_name]) && ops.any?
|
205
205
|
body = ops.flat_map do |op|
|
206
|
-
# We only care about the source versions, but the way we get it varies.
|
207
|
-
include_version =
|
208
|
-
if op.destination_index_def.use_updates_for_indexing?
|
209
|
-
# @type var op: Operation::Update
|
210
|
-
{_source: {includes: [
|
211
|
-
"__versions.#{op.update_target.relationship}",
|
212
|
-
# The update_data script before ElasticGraph v0.8 used __sourceVersions[type] instead of __versions[relationship].
|
213
|
-
# To be backwards-compatible we need to fetch the data at both paths.
|
214
|
-
#
|
215
|
-
# TODO: Drop this when we no longer need to maintain backwards-compatibility.
|
216
|
-
"__sourceVersions.#{op.event.fetch("type")}"
|
217
|
-
]}}
|
218
|
-
else
|
219
|
-
{version: true, _source: false}
|
220
|
-
end
|
221
|
-
|
222
206
|
[
|
223
207
|
# Note: we intentionally search the entire index expression, not just an individual index based on a rollover timestamp.
|
224
208
|
# And we intentionally do NOT provide a routing value--we want to find the version, no matter what shard the document
|
@@ -229,8 +213,12 @@ module ElasticGraph
|
|
229
213
|
# a different shard and index than what the operation is targeted at. We want to search across all of them
|
230
214
|
# so that we will find it, regardless of where it lives.
|
231
215
|
{index: op.destination_index_def.index_expression_for_search},
|
232
|
-
|
233
|
-
|
216
|
+
{
|
217
|
+
# Filter to the documents matching the id.
|
218
|
+
query: {ids: {values: [op.doc_id]}},
|
219
|
+
# We only care about the version.
|
220
|
+
_source: {includes: ["__versions.#{op.update_target.relationship}"]}
|
221
|
+
}
|
234
222
|
]
|
235
223
|
end
|
236
224
|
|
@@ -244,7 +232,7 @@ module ElasticGraph
|
|
244
232
|
|
245
233
|
if errors.empty?
|
246
234
|
# We assume the size of the ops and the other array is the same and it cannot have `nil`.
|
247
|
-
zip = ops.zip(msearch_response.fetch("responses")) # : ::Array[[
|
235
|
+
zip = ops.zip(msearch_response.fetch("responses")) # : ::Array[[Operation::Update, ::Hash[::String, ::Hash[::String, untyped]]]]
|
248
236
|
|
249
237
|
versions_by_op = zip.to_h do |(op, response)|
|
250
238
|
hits = response.fetch("hits").fetch("hits")
|
@@ -260,25 +248,15 @@ module ElasticGraph
|
|
260
248
|
})
|
261
249
|
end
|
262
250
|
|
263
|
-
|
264
|
-
|
265
|
-
versions = hits.filter_map do |hit|
|
266
|
-
hit.dig("_source", "__versions", op.update_target.relationship, hit.fetch("_id")) ||
|
267
|
-
# The update_data script before ElasticGraph v0.8 used __sourceVersions[type] instead of __versions[relationship].
|
268
|
-
# To be backwards-compatible we need to fetch the data at both paths.
|
269
|
-
#
|
270
|
-
# TODO: Drop this when we no longer need to maintain backwards-compatibility.
|
271
|
-
hit.dig("_source", "__sourceVersions", op.event.fetch("type"), hit.fetch("_id"))
|
272
|
-
end
|
273
|
-
|
274
|
-
[op, versions.uniq]
|
275
|
-
else
|
276
|
-
[op, hits.map { |h| h.fetch("_version") }.uniq]
|
251
|
+
versions = hits.filter_map do |hit|
|
252
|
+
hit.dig("_source", "__versions", op.update_target.relationship, hit.fetch("_id"))
|
277
253
|
end
|
254
|
+
|
255
|
+
[op, versions.uniq]
|
278
256
|
end
|
279
257
|
|
280
258
|
unversioned_ops_hash = unversioned_ops.to_h do |op|
|
281
|
-
[op, []] # : [
|
259
|
+
[op, []] # : [Operation::Update, ::Array[::Integer]]
|
282
260
|
end
|
283
261
|
|
284
262
|
[client_name, :success, versions_by_op.merge(unversioned_ops_hash)]
|
@@ -10,7 +10,6 @@ require "elastic_graph/constants"
|
|
10
10
|
require "elastic_graph/indexer/event_id"
|
11
11
|
require "elastic_graph/indexer/failed_event_error"
|
12
12
|
require "elastic_graph/indexer/operation/update"
|
13
|
-
require "elastic_graph/indexer/operation/upsert"
|
14
13
|
require "elastic_graph/indexer/record_preparer"
|
15
14
|
require "elastic_graph/json_schema/validator_factory"
|
16
15
|
require "elastic_graph/support/memoizable_data"
|
@@ -140,23 +139,6 @@ module ElasticGraph
|
|
140
139
|
end
|
141
140
|
|
142
141
|
def build_all_operations_for(event, record_preparer)
|
143
|
-
upsert_operations(event, record_preparer) + update_operations(event, record_preparer)
|
144
|
-
end
|
145
|
-
|
146
|
-
def upsert_operations(event, record_preparer)
|
147
|
-
type = event.fetch("type") do
|
148
|
-
# This key should only be missing on invalid events. We still want to build operations
|
149
|
-
# for the event (to put it in the `FailedEventError`) but in this case we can't build
|
150
|
-
# any because we don't know what indices to target.
|
151
|
-
return []
|
152
|
-
end
|
153
|
-
|
154
|
-
index_definitions_for(type).reject(&:use_updates_for_indexing?).map do |index_definition|
|
155
|
-
Upsert.new(event, index_definition, record_preparer)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def update_operations(event, record_preparer)
|
160
142
|
# If `type` is missing or is not a known type (as indicated by `runtime_metadata` being nil)
|
161
143
|
# then we can't build a derived indexing type update operation. That case will only happen when we build
|
162
144
|
# operations for an `FailedEventError` rather than to execute.
|
@@ -27,8 +27,6 @@ module ElasticGraph
|
|
27
27
|
update_target:,
|
28
28
|
destination_index_mapping:
|
29
29
|
)
|
30
|
-
return [] if update_target.for_normal_indexing? && !destination_index_def.use_updates_for_indexing?
|
31
|
-
|
32
30
|
prepared_record = record_preparer.prepare_for_index(event["type"], event["record"] || {"id" => event["id"]})
|
33
31
|
|
34
32
|
Support::HashUtil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticgraph-indexer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Myron Marston
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Block Engineering
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: elasticgraph-datastore_core
|
@@ -17,56 +17,56 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 1.0.0.rc1
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 1.0.0.rc1
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: elasticgraph-json_schema
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - '='
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.
|
34
|
+
version: 1.0.0.rc1
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - '='
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.
|
41
|
+
version: 1.0.0.rc1
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: elasticgraph-schema_artifacts
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - '='
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
48
|
+
version: 1.0.0.rc1
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - '='
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 1.0.0.rc1
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: elasticgraph-support
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - '='
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
62
|
+
version: 1.0.0.rc1
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - '='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 1.0.0.rc1
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: hashdiff
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,56 +93,56 @@ dependencies:
|
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 1.0.0.rc1
|
97
97
|
type: :development
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 1.0.0.rc1
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: elasticgraph-elasticsearch
|
106
106
|
requirement: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 1.0.0.rc1
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
113
|
version_requirements: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - '='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: 1.0.0.rc1
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: elasticgraph-opensearch
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - '='
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
124
|
+
version: 1.0.0.rc1
|
125
125
|
type: :development
|
126
126
|
prerelease: false
|
127
127
|
version_requirements: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - '='
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
131
|
+
version: 1.0.0.rc1
|
132
132
|
- !ruby/object:Gem::Dependency
|
133
133
|
name: elasticgraph-schema_definition
|
134
134
|
requirement: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - '='
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.
|
138
|
+
version: 1.0.0.rc1
|
139
139
|
type: :development
|
140
140
|
prerelease: false
|
141
141
|
version_requirements: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 1.0.0.rc1
|
146
146
|
email:
|
147
147
|
- myron@squareup.com
|
148
148
|
executables: []
|
@@ -165,7 +165,6 @@ files:
|
|
165
165
|
- lib/elastic_graph/indexer/operation/factory.rb
|
166
166
|
- lib/elastic_graph/indexer/operation/result.rb
|
167
167
|
- lib/elastic_graph/indexer/operation/update.rb
|
168
|
-
- lib/elastic_graph/indexer/operation/upsert.rb
|
169
168
|
- lib/elastic_graph/indexer/processor.rb
|
170
169
|
- lib/elastic_graph/indexer/record_preparer.rb
|
171
170
|
- lib/elastic_graph/indexer/spec_support/event_matcher.rb
|
@@ -175,10 +174,10 @@ licenses:
|
|
175
174
|
- MIT
|
176
175
|
metadata:
|
177
176
|
bug_tracker_uri: https://github.com/block/elasticgraph/issues
|
178
|
-
changelog_uri: https://github.com/block/elasticgraph/releases/tag/
|
179
|
-
documentation_uri: https://block.github.io/elasticgraph/api-docs/
|
177
|
+
changelog_uri: https://github.com/block/elasticgraph/releases/tag/v1.0.0.rc1
|
178
|
+
documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.0.0.rc1/
|
180
179
|
homepage_uri: https://block.github.io/elasticgraph/
|
181
|
-
source_code_uri: https://github.com/block/elasticgraph/tree/
|
180
|
+
source_code_uri: https://github.com/block/elasticgraph/tree/v1.0.0.rc1/elasticgraph-indexer
|
182
181
|
gem_category: core
|
183
182
|
rdoc_options: []
|
184
183
|
require_paths:
|
@@ -187,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
186
|
requirements:
|
188
187
|
- - ">="
|
189
188
|
- !ruby/object:Gem::Version
|
190
|
-
version: '3.
|
189
|
+
version: '3.4'
|
191
190
|
- - "<"
|
192
191
|
- !ruby/object:Gem::Version
|
193
192
|
version: '3.5'
|
@@ -197,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
196
|
- !ruby/object:Gem::Version
|
198
197
|
version: '0'
|
199
198
|
requirements: []
|
200
|
-
rubygems_version: 3.6.
|
199
|
+
rubygems_version: 3.6.7
|
201
200
|
specification_version: 4
|
202
201
|
summary: ElasticGraph gem that provides APIs to robustly index data into a datastore.
|
203
202
|
test_files: []
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# Copyright 2024 - 2025 Block, Inc.
|
2
|
-
#
|
3
|
-
# Use of this source code is governed by an MIT-style
|
4
|
-
# license that can be found in the LICENSE file or at
|
5
|
-
# https://opensource.org/licenses/MIT.
|
6
|
-
#
|
7
|
-
# frozen_string_literal: true
|
8
|
-
|
9
|
-
require "elastic_graph/indexer/operation/result"
|
10
|
-
require "elastic_graph/support/hash_util"
|
11
|
-
require "elastic_graph/support/memoizable_data"
|
12
|
-
|
13
|
-
module ElasticGraph
|
14
|
-
class Indexer
|
15
|
-
module Operation
|
16
|
-
Upsert = Support::MemoizableData.define(:event, :destination_index_def, :record_preparer) do
|
17
|
-
# @implements Upsert
|
18
|
-
|
19
|
-
def to_datastore_bulk
|
20
|
-
@to_datastore_bulk ||= [{index: metadata}, prepared_record]
|
21
|
-
end
|
22
|
-
|
23
|
-
def categorize(response)
|
24
|
-
index = response.fetch("index")
|
25
|
-
status = index.fetch("status")
|
26
|
-
|
27
|
-
case status
|
28
|
-
when 200..299
|
29
|
-
Result.success_of(self)
|
30
|
-
when 409
|
31
|
-
Result.noop_of(self, index.fetch("error").fetch("reason"))
|
32
|
-
else
|
33
|
-
Result.failure_of(self, index.fetch("error").fetch("reason"))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def doc_id
|
38
|
-
@doc_id ||= event.fetch("id")
|
39
|
-
end
|
40
|
-
|
41
|
-
def type
|
42
|
-
:upsert
|
43
|
-
end
|
44
|
-
|
45
|
-
def description
|
46
|
-
"#{event.fetch("type")} upsert"
|
47
|
-
end
|
48
|
-
|
49
|
-
def versioned?
|
50
|
-
true
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def metadata
|
56
|
-
@metadata ||= {
|
57
|
-
_index: destination_index_def.index_name_for_writes(prepared_record),
|
58
|
-
_id: doc_id,
|
59
|
-
version: event.fetch("version"),
|
60
|
-
version_type: "external",
|
61
|
-
routing: destination_index_def.routing_value_for_prepared_record(prepared_record)
|
62
|
-
}.compact
|
63
|
-
end
|
64
|
-
|
65
|
-
def prepared_record
|
66
|
-
@prepared_record ||= record_preparer.prepare_for_index(event.fetch("type"), event.fetch("record"))
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|