elasticgraph-indexer 0.19.3.0 → 1.0.0.rc2

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: d28113608a5471d4e6d3606aad9406d966ddf4501f253a8db5829547714ec5d9
4
- data.tar.gz: 96e18366cb625441ad605967c988eea5d8107d9445f73eb340f0af7a39f9291d
3
+ metadata.gz: 4aefec973d5a440bfb174de26f833ce048fc571b73eb7deec5b67d9349bab38e
4
+ data.tar.gz: c2733b78badf5d4e1481a91199b4fcef8b0e2daaaa0b42179969e29af9c191c7
5
5
  SHA512:
6
- metadata.gz: fc4b60c326fb22e839df9e7f9ead2a74efe629471dfede41843c5f0d0208db28b52489c7765af3cb992d00657a7d60ccd14ca5321ea7e9bd799629724180803d
7
- data.tar.gz: 8eca062ae143a3c3fe65296fc0af10a16479e649ace14523e1e50bcca0448e2592e4ca87ed27db45d9a0803ad094bf3a5ee2d2c17be5c6ce7bc06406ccd5d2b9
6
+ metadata.gz: 9fd5e2e2b8203221ed1262f72df2b4b9b66fd693919a5a85cabe1eba53961d3fb9e035106b6b5fff3b5db891bfb22a0f7718d758442cbd11adefee9ddbf10075
7
+ data.tar.gz: ff21fbe6096d21a230245d8077e20f9c526db20a90ead2a8d3b6ffb9f67fc33cbd1309acb5d14aeeee566caa556faba78f6831a0a422929068d0011ec22596a6
data/README.md CHANGED
@@ -1 +1,40 @@
1
1
  # ElasticGraph::Indexer
2
+
3
+ ## Dependency Diagram
4
+
5
+ ```mermaid
6
+ graph LR;
7
+ classDef targetGemStyle fill:#FADBD8,stroke:#EC7063,color:#000,stroke-width:2px;
8
+ classDef otherEgGemStyle fill:#A9DFBF,stroke:#2ECC71,color:#000;
9
+ classDef externalGemStyle fill:#E0EFFF,stroke:#70A1D7,color:#2980B9;
10
+ elasticgraph-indexer["elasticgraph-indexer"];
11
+ class elasticgraph-indexer targetGemStyle;
12
+ elasticgraph-datastore_core["elasticgraph-datastore_core"];
13
+ elasticgraph-indexer --> elasticgraph-datastore_core;
14
+ class elasticgraph-datastore_core otherEgGemStyle;
15
+ elasticgraph-json_schema["elasticgraph-json_schema"];
16
+ elasticgraph-indexer --> elasticgraph-json_schema;
17
+ class elasticgraph-json_schema otherEgGemStyle;
18
+ elasticgraph-schema_artifacts["elasticgraph-schema_artifacts"];
19
+ elasticgraph-indexer --> elasticgraph-schema_artifacts;
20
+ class elasticgraph-schema_artifacts otherEgGemStyle;
21
+ elasticgraph-support["elasticgraph-support"];
22
+ elasticgraph-indexer --> elasticgraph-support;
23
+ class elasticgraph-support otherEgGemStyle;
24
+ hashdiff["hashdiff"];
25
+ elasticgraph-indexer --> hashdiff;
26
+ class hashdiff externalGemStyle;
27
+ elasticgraph-admin["elasticgraph-admin"];
28
+ elasticgraph-admin --> elasticgraph-indexer;
29
+ class elasticgraph-admin otherEgGemStyle;
30
+ elasticgraph-indexer_lambda["elasticgraph-indexer_lambda"];
31
+ elasticgraph-indexer_lambda --> elasticgraph-indexer;
32
+ class elasticgraph-indexer_lambda otherEgGemStyle;
33
+ elasticgraph-local["elasticgraph-local"];
34
+ elasticgraph-local --> elasticgraph-indexer;
35
+ class elasticgraph-local otherEgGemStyle;
36
+ elasticgraph-schema_definition["elasticgraph-schema_definition"];
37
+ elasticgraph-schema_definition --> elasticgraph-indexer;
38
+ class elasticgraph-schema_definition otherEgGemStyle;
39
+ click hashdiff href "https://rubygems.org/gems/hashdiff" "Open on RubyGems.org" _blank;
40
+ ```
@@ -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
- # Filter to the documents matching the id.
233
- {query: {ids: {values: [op.doc_id]}}}.merge(include_version)
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[[_Operation, ::Hash[::String, ::Hash[::String, untyped]]]]
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
- if op.destination_index_def.use_updates_for_indexing?
264
- # @type var op: Operation::Update
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, []] # : [_Operation, ::Array[::Integer]]
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.19.3.0
4
+ version: 1.0.0.rc2
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: 2025-06-20 00:00:00.000000000 Z
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,132 +17,126 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.19.3.0
20
+ version: 1.0.0.rc2
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.19.3.0
27
+ version: 1.0.0.rc2
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.19.3.0
34
+ version: 1.0.0.rc2
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.19.3.0
41
+ version: 1.0.0.rc2
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.19.3.0
48
+ version: 1.0.0.rc2
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.19.3.0
55
+ version: 1.0.0.rc2
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.19.3.0
62
+ version: 1.0.0.rc2
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.19.3.0
69
+ version: 1.0.0.rc2
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: hashdiff
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '1.1'
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: 1.1.2
76
+ version: '1.2'
80
77
  type: :runtime
81
78
  prerelease: false
82
79
  version_requirements: !ruby/object:Gem::Requirement
83
80
  requirements:
84
81
  - - "~>"
85
82
  - !ruby/object:Gem::Version
86
- version: '1.1'
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 1.1.2
83
+ version: '1.2'
90
84
  - !ruby/object:Gem::Dependency
91
85
  name: elasticgraph-admin
92
86
  requirement: !ruby/object:Gem::Requirement
93
87
  requirements:
94
88
  - - '='
95
89
  - !ruby/object:Gem::Version
96
- version: 0.19.3.0
90
+ version: 1.0.0.rc2
97
91
  type: :development
98
92
  prerelease: false
99
93
  version_requirements: !ruby/object:Gem::Requirement
100
94
  requirements:
101
95
  - - '='
102
96
  - !ruby/object:Gem::Version
103
- version: 0.19.3.0
97
+ version: 1.0.0.rc2
104
98
  - !ruby/object:Gem::Dependency
105
99
  name: elasticgraph-elasticsearch
106
100
  requirement: !ruby/object:Gem::Requirement
107
101
  requirements:
108
102
  - - '='
109
103
  - !ruby/object:Gem::Version
110
- version: 0.19.3.0
104
+ version: 1.0.0.rc2
111
105
  type: :development
112
106
  prerelease: false
113
107
  version_requirements: !ruby/object:Gem::Requirement
114
108
  requirements:
115
109
  - - '='
116
110
  - !ruby/object:Gem::Version
117
- version: 0.19.3.0
111
+ version: 1.0.0.rc2
118
112
  - !ruby/object:Gem::Dependency
119
113
  name: elasticgraph-opensearch
120
114
  requirement: !ruby/object:Gem::Requirement
121
115
  requirements:
122
116
  - - '='
123
117
  - !ruby/object:Gem::Version
124
- version: 0.19.3.0
118
+ version: 1.0.0.rc2
125
119
  type: :development
126
120
  prerelease: false
127
121
  version_requirements: !ruby/object:Gem::Requirement
128
122
  requirements:
129
123
  - - '='
130
124
  - !ruby/object:Gem::Version
131
- version: 0.19.3.0
125
+ version: 1.0.0.rc2
132
126
  - !ruby/object:Gem::Dependency
133
127
  name: elasticgraph-schema_definition
134
128
  requirement: !ruby/object:Gem::Requirement
135
129
  requirements:
136
130
  - - '='
137
131
  - !ruby/object:Gem::Version
138
- version: 0.19.3.0
132
+ version: 1.0.0.rc2
139
133
  type: :development
140
134
  prerelease: false
141
135
  version_requirements: !ruby/object:Gem::Requirement
142
136
  requirements:
143
137
  - - '='
144
138
  - !ruby/object:Gem::Version
145
- version: 0.19.3.0
139
+ version: 1.0.0.rc2
146
140
  email:
147
141
  - myron@squareup.com
148
142
  executables: []
@@ -165,7 +159,6 @@ files:
165
159
  - lib/elastic_graph/indexer/operation/factory.rb
166
160
  - lib/elastic_graph/indexer/operation/result.rb
167
161
  - lib/elastic_graph/indexer/operation/update.rb
168
- - lib/elastic_graph/indexer/operation/upsert.rb
169
162
  - lib/elastic_graph/indexer/processor.rb
170
163
  - lib/elastic_graph/indexer/record_preparer.rb
171
164
  - lib/elastic_graph/indexer/spec_support/event_matcher.rb
@@ -175,10 +168,10 @@ licenses:
175
168
  - MIT
176
169
  metadata:
177
170
  bug_tracker_uri: https://github.com/block/elasticgraph/issues
178
- changelog_uri: https://github.com/block/elasticgraph/releases/tag/v0.19.3.0
179
- documentation_uri: https://block.github.io/elasticgraph/api-docs/v0.19.3.0/
171
+ changelog_uri: https://github.com/block/elasticgraph/releases/tag/v1.0.0.rc2
172
+ documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.0.0.rc2/
180
173
  homepage_uri: https://block.github.io/elasticgraph/
181
- source_code_uri: https://github.com/block/elasticgraph/tree/v0.19.3.0/elasticgraph-indexer
174
+ source_code_uri: https://github.com/block/elasticgraph/tree/v1.0.0.rc2/elasticgraph-indexer
182
175
  gem_category: core
183
176
  rdoc_options: []
184
177
  require_paths:
@@ -187,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
180
  requirements:
188
181
  - - ">="
189
182
  - !ruby/object:Gem::Version
190
- version: '3.2'
183
+ version: '3.4'
191
184
  - - "<"
192
185
  - !ruby/object:Gem::Version
193
186
  version: '3.5'
@@ -197,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
190
  - !ruby/object:Gem::Version
198
191
  version: '0'
199
192
  requirements: []
200
- rubygems_version: 3.6.2
193
+ rubygems_version: 3.6.7
201
194
  specification_version: 4
202
195
  summary: ElasticGraph gem that provides APIs to robustly index data into a datastore.
203
196
  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