Skip to content

Commit 6ba6caf

Browse files
authored
Return appropriate error on null dims update instead of npe (elastic#125716) (elastic#125766)
Calling `Object::toString` was trying to call `null.toString()`, really it should have been `Objects::toString`, which accepts `null`. closes: elastic#125713 (cherry picked from commit dd58b0b)
1 parent 8eea762 commit 6ba6caf

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

docs/changelog/125716.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 125716
2+
summary: Return appropriate error on null dims update instead of npe
3+
area: Vector Search
4+
type: bug
5+
issues: []

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/40_knn_search.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,28 @@ setup:
605605
- match: { hits.hits.0._score: $knn_score0 }
606606
- match: { hits.hits.1._score: $knn_score1 }
607607
- match: { hits.hits.2._score: $knn_score2 }
608+
---
609+
"Updating dim to null is not allowed":
610+
- requires:
611+
cluster_features: "mapper.npe_on_dims_update_fix"
612+
reason: "dims update fix"
613+
- do:
614+
indices.create:
615+
index: test_index
616+
617+
- do:
618+
indices.put_mapping:
619+
index: test_index
620+
body:
621+
properties:
622+
embedding:
623+
type: dense_vector
624+
dims: 4
625+
- do:
626+
catch: bad_request
627+
indices.put_mapping:
628+
index: test_index
629+
body:
630+
properties:
631+
embedding:
632+
type: dense_vector

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class MapperFeatures implements FeatureSpecification {
3131
public static final NodeFeature SPARSE_VECTOR_STORE_SUPPORT = new NodeFeature("mapper.sparse_vector.store_support");
3232
public static final NodeFeature SORT_FIELDS_CHECK_FOR_NESTED_OBJECT_FIX = new NodeFeature("mapper.nested.sorting_fields_check_fix");
3333
public static final NodeFeature DYNAMIC_HANDLING_IN_COPY_TO = new NodeFeature("mapper.copy_to.dynamic_handling");
34+
static final NodeFeature NPE_ON_DIMS_UPDATE_FIX = new NodeFeature("mapper.npe_on_dims_update_fix");
3435

3536
@Override
3637
public Set<NodeFeature> getTestFeatures() {
@@ -51,7 +52,8 @@ public Set<NodeFeature> getTestFeatures() {
5152
DYNAMIC_HANDLING_IN_COPY_TO,
5253
SourceFieldMapper.SYNTHETIC_RECOVERY_SOURCE,
5354
ObjectMapper.SUBOBJECTS_FALSE_MAPPING_UPDATE_FIX,
54-
DateFieldMapper.INVALID_DATE_FIX
55+
DateFieldMapper.INVALID_DATE_FIX,
56+
NPE_ON_DIMS_UPDATE_FIX
5557
);
5658
}
5759
}

server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static class Builder extends FieldMapper.Builder {
144144
}
145145

146146
return XContentMapValues.nodeIntegerValue(o);
147-
}, m -> toType(m).fieldType().dims, XContentBuilder::field, Object::toString).setSerializerCheck((id, ic, v) -> v != null)
147+
}, m -> toType(m).fieldType().dims, XContentBuilder::field, Objects::toString).setSerializerCheck((id, ic, v) -> v != null)
148148
.setMergeValidator((previous, current, c) -> previous == null || Objects.equals(previous, current))
149149
.addValidator(dims -> {
150150
if (dims == null) {

x-pack/plugin/rank-vectors/src/main/java/org/elasticsearch/xpack/rank/vectors/mapper/RankVectorsFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static class Builder extends FieldMapper.Builder {
8989
}
9090

9191
return XContentMapValues.nodeIntegerValue(o);
92-
}, m -> toType(m).fieldType().dims, XContentBuilder::field, Object::toString).setSerializerCheck((id, ic, v) -> v != null)
92+
}, m -> toType(m).fieldType().dims, XContentBuilder::field, Objects::toString).setSerializerCheck((id, ic, v) -> v != null)
9393
.setMergeValidator((previous, current, c) -> previous == null || Objects.equals(previous, current))
9494
.addValidator(dims -> {
9595
if (dims == null) {

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/rank_vectors/rank_vectors.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,28 @@ setup:
135135
id: "1"
136136
body:
137137
vector1: [[2, -1, 1], [[2, -1, 1]]]
138+
---
139+
"Updating dim to null is not allowed":
140+
- requires:
141+
cluster_features: "mapper.npe_on_dims_update_fix"
142+
reason: "dims update fix"
143+
- do:
144+
indices.create:
145+
index: test_index
146+
147+
- do:
148+
indices.put_mapping:
149+
index: test_index
150+
body:
151+
properties:
152+
embedding:
153+
type: rank_vectors
154+
dims: 4
155+
- do:
156+
catch: bad_request
157+
indices.put_mapping:
158+
index: test_index
159+
body:
160+
properties:
161+
embedding:
162+
type: rank_vectors

0 commit comments

Comments
 (0)