Skip to content

Commit 96def28

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

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
@@ -596,3 +596,28 @@ setup:
596596
- match: { hits.hits.0._score: $knn_score0 }
597597
- match: { hits.hits.1._score: $knn_score1 }
598598
- match: { hits.hits.2._score: $knn_score2 }
599+
---
600+
"Updating dim to null is not allowed":
601+
- requires:
602+
cluster_features: "mapper.npe_on_dims_update_fix"
603+
reason: "dims update fix"
604+
- do:
605+
indices.create:
606+
index: test_index
607+
608+
- do:
609+
indices.put_mapping:
610+
index: test_index
611+
body:
612+
properties:
613+
embedding:
614+
type: dense_vector
615+
dims: 4
616+
- do:
617+
catch: bad_request
618+
indices.put_mapping:
619+
index: test_index
620+
body:
621+
properties:
622+
embedding:
623+
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
@@ -62,6 +62,7 @@ public Set<NodeFeature> getFeatures() {
6262
public static final NodeFeature META_FETCH_FIELDS_ERROR_CODE_CHANGED = new NodeFeature("meta_fetch_fields_error_code_changed");
6363
public static final NodeFeature SPARSE_VECTOR_STORE_SUPPORT = new NodeFeature("mapper.sparse_vector.store_support");
6464
public static final NodeFeature SORT_FIELDS_CHECK_FOR_NESTED_OBJECT_FIX = new NodeFeature("mapper.nested.sorting_fields_check_fix");
65+
static final NodeFeature NPE_ON_DIMS_UPDATE_FIX = new NodeFeature("mapper.npe_on_dims_update_fix");
6566

6667
@Override
6768
public Set<NodeFeature> getTestFeatures() {
@@ -80,7 +81,8 @@ public Set<NodeFeature> getTestFeatures() {
8081
COUNTED_KEYWORD_SYNTHETIC_SOURCE_NATIVE_SUPPORT,
8182
SourceFieldMapper.SYNTHETIC_RECOVERY_SOURCE,
8283
ObjectMapper.SUBOBJECTS_FALSE_MAPPING_UPDATE_FIX,
83-
DateFieldMapper.INVALID_DATE_FIX
84+
DateFieldMapper.INVALID_DATE_FIX,
85+
NPE_ON_DIMS_UPDATE_FIX
8486
);
8587
}
8688
}

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
@@ -147,7 +147,7 @@ public static class Builder extends FieldMapper.Builder {
147147
}
148148

149149
return XContentMapValues.nodeIntegerValue(o);
150-
}, m -> toType(m).fieldType().dims, XContentBuilder::field, Object::toString).setSerializerCheck((id, ic, v) -> v != null)
150+
}, m -> toType(m).fieldType().dims, XContentBuilder::field, Objects::toString).setSerializerCheck((id, ic, v) -> v != null)
151151
.setMergeValidator((previous, current, c) -> previous == null || Objects.equals(previous, current))
152152
.addValidator(dims -> {
153153
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)