Skip to content

Commit fb29671

Browse files
jwilsclaude
andcommitted
Support retrieved_from: :doc_values for direct leaf fields (#1110)
Add a narrow secondary retrieval path for fields that should stay returnable in GraphQL while being excluded from stored `_source`. When a field is marked `retrieved_from: :doc_values`, ElasticGraph: - keeps the field in GraphQL output types - excludes the field from datastore `_source` via `_source.excludes` - requests the field through datastore `docvalue_fields` - resolves the field from `fields` in datastore hits when `_source` omits it The change is intentionally narrow: only direct, non-list, non-text GraphQL leaf fields on indexed root document types are supported. Query planning only uses `docvalue_fields` when every participating index definition agrees on the retrieval method. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f3818af commit fb29671

39 files changed

Lines changed: 673 additions & 154 deletions

File tree

config/schema/artifacts/datastore_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ index_templates:
14901490
enabled: true
14911491
_source:
14921492
excludes:
1493+
- workspace_id2
14931494
- internal_name
14941495
- internal_details.*
14951496
settings:
@@ -1537,6 +1538,9 @@ indices:
15371538
value: Address
15381539
_size:
15391540
enabled: true
1541+
_source:
1542+
excludes:
1543+
- full_address
15401544
settings:
15411545
index.mapping.ignore_malformed: false
15421546
index.mapping.coerce: false

config/schema/artifacts/runtime_metadata.yaml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,7 @@ index_definitions_by_name:
18171817
__counts.shapes|type:
18181818
source: __self
18191819
full_address:
1820+
retrieved_from: doc_values
18201821
source: __self
18211822
geo_location.lat:
18221823
source: __self
@@ -3039,6 +3040,7 @@ index_definitions_by_name:
30393040
weight_in_ng_str:
30403041
source: __self
30413042
workspace_id2:
3043+
retrieved_from: doc_values
30423044
source: __self
30433045
workspace_name:
30443046
source: workspace
@@ -3170,9 +3172,6 @@ object_types_by_name:
31703172
cursor:
31713173
resolver:
31723174
name: object_without_lookahead
3173-
highlights:
3174-
resolver:
3175-
name: object_without_lookahead
31763175
node:
31773176
resolver:
31783177
name: object_without_lookahead
@@ -3184,11 +3183,6 @@ object_types_by_name:
31843183
timestamps:
31853184
resolver:
31863185
name: object_with_lookahead
3187-
AddressHighlights:
3188-
graphql_fields_by_name:
3189-
full_address:
3190-
resolver:
3191-
name: get_record_field_value
31923186
AddressTimestamps:
31933187
graphql_fields_by_name:
31943188
created_at:
@@ -5330,10 +5324,6 @@ object_types_by_name:
53305324
name_in_index: widget_workspace_id3
53315325
resolver:
53325326
name: get_record_field_value
5333-
workspace_id:
5334-
name_in_index: workspace_id2
5335-
resolver:
5336-
name: get_record_field_value
53375327
workspace_name:
53385328
resolver:
53395329
name: get_record_field_value
@@ -8454,10 +8444,6 @@ object_types_by_name:
84548444
name_in_index: the_opts
84558445
resolver:
84568446
name: get_record_field_value
8457-
workspace_id:
8458-
name_in_index: workspace_id2
8459-
resolver:
8460-
name: get_record_field_value
84618447
workspace_name:
84628448
resolver:
84638449
name: get_record_field_value
@@ -9031,9 +9017,6 @@ object_types_by_name:
90319017
fees:
90329018
resolver:
90339019
name: get_record_field_value
9034-
full_address:
9035-
resolver:
9036-
name: get_record_field_value
90379020
id:
90389021
resolver:
90399022
name: get_record_field_value
@@ -9072,10 +9055,6 @@ object_types_by_name:
90729055
name_in_index: the_opts
90739056
resolver:
90749057
name: get_record_field_value
9075-
workspace_id:
9076-
name_in_index: workspace_id2
9077-
resolver:
9078-
name: get_record_field_value
90799058
workspace_name:
90809059
resolver:
90819060
name: get_record_field_value

config/schema/artifacts/schema.graphql

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ type AddressEdge {
155155
"""
156156
cursor: Cursor
157157

158-
"""
159-
Specific search highlights for this `Address`, providing matching snippets for the requested fields.
160-
"""
161-
highlights: AddressHighlights
162-
163158
"""
164159
The `Address` of this edge.
165160
"""
@@ -238,16 +233,6 @@ type AddressGroupedBy {
238233
timestamps: AddressTimestampsGroupedBy
239234
}
240235

241-
"""
242-
Type used to request desired `Address` search highlight fields.
243-
"""
244-
type AddressHighlights {
245-
"""
246-
Search highlights for the `full_address`, providing snippets of the matching text.
247-
"""
248-
full_address: [String!]!
249-
}
250-
251236
"""
252237
Enumerates the ways `Address`s can be sorted.
253238
"""
@@ -6977,11 +6962,6 @@ type NamedEntityHighlights {
69776962
"""
69786963
widget_workspace_id: [String!]!
69796964

6980-
"""
6981-
Search highlights for the `workspace_id`, providing snippets of the matching text.
6982-
"""
6983-
workspace_id: [String!]!
6984-
69856965
"""
69866966
Search highlights for the `workspace_name`, providing snippets of the matching text.
69876967
"""
@@ -17142,11 +17122,6 @@ type WidgetHighlights {
1714217122
"""
1714317123
the_options: WidgetOptionsHighlights
1714417124

17145-
"""
17146-
Search highlights for the `workspace_id`, providing snippets of the matching text.
17147-
"""
17148-
workspace_id: [String!]!
17149-
1715017125
"""
1715117126
Search highlights for the `workspace_name`, providing snippets of the matching text.
1715217127
"""
@@ -18310,11 +18285,6 @@ type WidgetOrAddressHighlights {
1831018285
"""
1831118286
fees: MoneyHighlights
1831218287

18313-
"""
18314-
Search highlights for the `full_address`, providing snippets of the matching text.
18315-
"""
18316-
full_address: [String!]!
18317-
1831818288
"""
1831918289
Search highlights for the `id`, providing snippets of the matching text.
1832018290
"""
@@ -18375,11 +18345,6 @@ type WidgetOrAddressHighlights {
1837518345
"""
1837618346
the_options: WidgetOptionsHighlights
1837718347

18378-
"""
18379-
Search highlights for the `workspace_id`, providing snippets of the matching text.
18380-
"""
18381-
workspace_id: [String!]!
18382-
1838318348
"""
1838418349
Search highlights for the `workspace_name`, providing snippets of the matching text.
1838518350
"""

config/schema/artifacts_with_apollo/datastore_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ index_templates:
14901490
enabled: true
14911491
_source:
14921492
excludes:
1493+
- workspace_id2
14931494
- internal_name
14941495
- internal_details.*
14951496
settings:
@@ -1537,6 +1538,9 @@ indices:
15371538
value: Address
15381539
_size:
15391540
enabled: true
1541+
_source:
1542+
excludes:
1543+
- full_address
15401544
settings:
15411545
index.mapping.ignore_malformed: false
15421546
index.mapping.coerce: false

config/schema/artifacts_with_apollo/runtime_metadata.yaml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ index_definitions_by_name:
18461846
__counts.shapes|type:
18471847
source: __self
18481848
full_address:
1849+
retrieved_from: doc_values
18491850
source: __self
18501851
geo_location.lat:
18511852
source: __self
@@ -3068,6 +3069,7 @@ index_definitions_by_name:
30683069
weight_in_ng_str:
30693070
source: __self
30703071
workspace_id2:
3072+
retrieved_from: doc_values
30713073
source: __self
30723074
workspace_name:
30733075
source: workspace
@@ -3199,9 +3201,6 @@ object_types_by_name:
31993201
cursor:
32003202
resolver:
32013203
name: object_without_lookahead
3202-
highlights:
3203-
resolver:
3204-
name: object_without_lookahead
32053204
node:
32063205
resolver:
32073206
name: object_without_lookahead
@@ -3213,11 +3212,6 @@ object_types_by_name:
32133212
timestamps:
32143213
resolver:
32153214
name: object_with_lookahead
3216-
AddressHighlights:
3217-
graphql_fields_by_name:
3218-
full_address:
3219-
resolver:
3220-
name: get_record_field_value
32213215
AddressTimestamps:
32223216
graphql_fields_by_name:
32233217
created_at:
@@ -5453,10 +5447,6 @@ object_types_by_name:
54535447
name_in_index: widget_workspace_id3
54545448
resolver:
54555449
name: get_record_field_value
5456-
workspace_id:
5457-
name_in_index: workspace_id2
5458-
resolver:
5459-
name: get_record_field_value
54605450
workspace_name:
54615451
resolver:
54625452
name: get_record_field_value
@@ -8583,10 +8573,6 @@ object_types_by_name:
85838573
name_in_index: the_opts
85848574
resolver:
85858575
name: get_record_field_value
8586-
workspace_id:
8587-
name_in_index: workspace_id2
8588-
resolver:
8589-
name: get_record_field_value
85908576
workspace_name:
85918577
resolver:
85928578
name: get_record_field_value
@@ -9160,9 +9146,6 @@ object_types_by_name:
91609146
fees:
91619147
resolver:
91629148
name: get_record_field_value
9163-
full_address:
9164-
resolver:
9165-
name: get_record_field_value
91669149
id:
91679150
resolver:
91689151
name: get_record_field_value
@@ -9201,10 +9184,6 @@ object_types_by_name:
92019184
name_in_index: the_opts
92029185
resolver:
92039186
name: get_record_field_value
9204-
workspace_id:
9205-
name_in_index: workspace_id2
9206-
resolver:
9207-
name: get_record_field_value
92089187
workspace_name:
92099188
resolver:
92109189
name: get_record_field_value

config/schema/artifacts_with_apollo/schema.graphql

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ type AddressEdge {
188188
"""
189189
cursor: Cursor
190190

191-
"""
192-
Specific search highlights for this `Address`, providing matching snippets for the requested fields.
193-
"""
194-
highlights: AddressHighlights
195-
196191
"""
197192
The `Address` of this edge.
198193
"""
@@ -271,16 +266,6 @@ type AddressGroupedBy {
271266
timestamps: AddressTimestampsGroupedBy
272267
}
273268

274-
"""
275-
Type used to request desired `Address` search highlight fields.
276-
"""
277-
type AddressHighlights {
278-
"""
279-
Search highlights for the `full_address`, providing snippets of the matching text.
280-
"""
281-
full_address: [String!]!
282-
}
283-
284269
"""
285270
Enumerates the ways `Address`s can be sorted.
286271
"""
@@ -7259,11 +7244,6 @@ type NamedEntityHighlights {
72597244
"""
72607245
widget_workspace_id: [String!]!
72617246

7262-
"""
7263-
Search highlights for the `workspace_id`, providing snippets of the matching text.
7264-
"""
7265-
workspace_id: [String!]!
7266-
72677247
"""
72687248
Search highlights for the `workspace_name`, providing snippets of the matching text.
72697249
"""
@@ -17465,11 +17445,6 @@ type WidgetHighlights {
1746517445
"""
1746617446
the_options: WidgetOptionsHighlights
1746717447

17468-
"""
17469-
Search highlights for the `workspace_id`, providing snippets of the matching text.
17470-
"""
17471-
workspace_id: [String!]!
17472-
1747317448
"""
1747417449
Search highlights for the `workspace_name`, providing snippets of the matching text.
1747517450
"""
@@ -18633,11 +18608,6 @@ type WidgetOrAddressHighlights {
1863318608
"""
1863418609
fees: MoneyHighlights
1863518610

18636-
"""
18637-
Search highlights for the `full_address`, providing snippets of the matching text.
18638-
"""
18639-
full_address: [String!]!
18640-
1864118611
"""
1864218612
Search highlights for the `id`, providing snippets of the matching text.
1864318613
"""
@@ -18698,11 +18668,6 @@ type WidgetOrAddressHighlights {
1869818668
"""
1869918669
the_options: WidgetOptionsHighlights
1870018670

18701-
"""
18702-
Search highlights for the `workspace_id`, providing snippets of the matching text.
18703-
"""
18704-
workspace_id: [String!]!
18705-
1870618671
"""
1870718672
Search highlights for the `workspace_name`, providing snippets of the matching text.
1870818673
"""

config/schema/widgets.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
t.field "id", "ID!"
8989

9090
# Here we use an alternate name for this field since it's the routing field and want to verify
91-
# that `name_in_index` works correctly on routing fields.
92-
t.field "workspace_id", "ID", name_in_index: "workspace_id2"
91+
# that `name_in_index` works correctly on routing fields, including when fetched from doc values.
92+
t.field "workspace_id", "ID", name_in_index: "workspace_id2", retrieved_from: :doc_values
9393

9494
# It's a bit funny we have both `amount_cents` and `cost` but it's nice to be able to test
9595
# aggregations on both a root numeric field and on a nested one, so we are keeping both here.
@@ -448,7 +448,7 @@
448448
# We use `indexing_only: true` here to verify that `id` can be an indexing-only field.
449449
t.field "id", "ID!", indexing_only: true
450450

451-
t.field "full_address", "String!"
451+
t.field "full_address", "String!", retrieved_from: :doc_values
452452
t.field "timestamps", "AddressTimestamps"
453453
t.field "geo_location", "GeoLocation"
454454

0 commit comments

Comments
 (0)