Skip to content

Commit 37fff92

Browse files
authored
Return appropriate error on null dims update instead of npe (elastic#125716) (elastic#125765)
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 7018005 commit 37fff92

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
@@ -67,6 +67,7 @@ public Set<NodeFeature> getFeatures() {
6767
static final NodeFeature UKNOWN_FIELD_MAPPING_UPDATE_ERROR_MESSAGE = new NodeFeature(
6868
"mapper.unknown_field_mapping_update_error_message"
6969
);
70+
static final NodeFeature NPE_ON_DIMS_UPDATE_FIX = new NodeFeature("mapper.npe_on_dims_update_fix");
7071

7172
@Override
7273
public Set<NodeFeature> getTestFeatures() {
@@ -88,7 +89,8 @@ public Set<NodeFeature> getTestFeatures() {
8889
SourceFieldMapper.SYNTHETIC_RECOVERY_SOURCE,
8990
ObjectMapper.SUBOBJECTS_FALSE_MAPPING_UPDATE_FIX,
9091
UKNOWN_FIELD_MAPPING_UPDATE_ERROR_MESSAGE,
91-
DateFieldMapper.INVALID_DATE_FIX
92+
DateFieldMapper.INVALID_DATE_FIX,
93+
NPE_ON_DIMS_UPDATE_FIX
9294
);
9395
}
9496
}

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)