Skip to content

Commit df75d28

Browse files
authored
Bugfix 136545 (#136556) (#136564)
* Address UOE on exclude vectors field fetching * removing unnecessary chagne * iter * Update docs/changelog/136556.yaml (cherry picked from commit 69774c2)
1 parent c60d392 commit df75d28

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

docs/changelog/136556.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 136556
2+
summary: Bugfix 136545
3+
area: Vector Search
4+
type: bug
5+
issues: []

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/240_source_synthetic_dense_vectors.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ setup:
213213
- length: { hits.hits.3._source.nested: 3 }
214214
- not_exists: hits.hits.3._source.nested.0.vector
215215

216-
217216
---
218217
"Bulk partial update with synthetic vectors":
219218
- do:
@@ -342,3 +341,52 @@ setup:
342341
- match: { hits.total.relation: eq }
343342
- match: { hits.hits.0._source.name: zoolander3.jpg }
344343
- match: { hits.hits.0._source.nested: $original_nested }
344+
345+
---
346+
"Ensure both fields and docvalue_fields are supported":
347+
- requires:
348+
cluster_features: ["mapper.exclude_vectors_docvalue_bugfix"]
349+
reason: "Bugfix for issue #136545"
350+
- do:
351+
headers:
352+
Content-Type: application/json
353+
indices.create:
354+
index: just_vectors
355+
body:
356+
mappings:
357+
properties:
358+
vector1:
359+
type: dense_vector
360+
dims: 5
361+
index: true
362+
element_type: float
363+
similarity: cosine
364+
vector2:
365+
type: dense_vector
366+
dims: 5
367+
element_type: float
368+
index: false
369+
settings:
370+
index:
371+
mapping:
372+
exclude_source_vectors: true
373+
- do:
374+
headers:
375+
Content-Type: application/json
376+
index:
377+
refresh: true
378+
index: just_vectors
379+
id: "1"
380+
body:
381+
vector1: [230.0, 300.33, -34.8988, 15.555, -200.0]
382+
vector2: [230.0, 300.33, -34.8988, 15.555, -200.0]
383+
# shouldn't throw
384+
- do:
385+
headers:
386+
Content-Type: application/json
387+
search:
388+
index: just_vectors
389+
body:
390+
_source: false
391+
fields: ["vector1"]
392+
docvalue_fields: ["vector2"]

server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class MapperFeatures implements FeatureSpecification {
5252
static final NodeFeature IGNORED_SOURCE_FIELDS_PER_ENTRY = new NodeFeature("mapper.ignored_source_fields_per_entry");
5353
public static final NodeFeature MULTI_FIELD_UNICODE_OPTIMISATION_FIX = new NodeFeature("mapper.multi_field.unicode_optimisation_fix");
5454
static final NodeFeature PATTERN_TEXT_RENAME = new NodeFeature("mapper.pattern_text_rename");
55+
static final NodeFeature EXCLUDE_VECTORS_DOCVALUE_BUGFIX = new NodeFeature("mapper.exclude_vectors_docvalue_bugfix");
5556

5657
@Override
5758
public Set<NodeFeature> getTestFeatures() {
@@ -89,7 +90,8 @@ public Set<NodeFeature> getTestFeatures() {
8990
IGNORED_SOURCE_FIELDS_PER_ENTRY,
9091
MULTI_FIELD_UNICODE_OPTIMISATION_FIX,
9192
MATCH_ONLY_TEXT_BLOCK_LOADER_FIX,
92-
PATTERN_TEXT_RENAME
93+
PATTERN_TEXT_RENAME,
94+
EXCLUDE_VECTORS_DOCVALUE_BUGFIX
9395
);
9496
}
9597
}

server/src/main/java/org/elasticsearch/index/mapper/SourceLoader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.ByteArrayOutputStream;
2525
import java.io.IOException;
2626
import java.util.ArrayList;
27+
import java.util.LinkedHashMap;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.Set;
@@ -467,6 +468,10 @@ public void write(LeafStoredFieldLoader storedFields, int docId, XContentBuilder
467468
*/
468469
static Source applySyntheticVectors(Source originalSource, List<SyntheticVectorPatch> patches) {
469470
Map<String, Object> newMap = originalSource.source();
471+
// Make sure we have a mutable map, empty implies `Map.of()`
472+
if (newMap.isEmpty()) {
473+
newMap = new LinkedHashMap<>();
474+
}
470475
applyPatches("", newMap, patches);
471476
return Source.fromMap(newMap, originalSource.sourceContentType());
472477
}

0 commit comments

Comments
 (0)