Skip to content

Commit 8080aac

Browse files
authored
Fix NPE in dense_vector stats (elastic#112720) (elastic#112722)
If a segment doesn't contain any documents with a dense_vector field, but the mapping defines it, an NPE can occur when retrieving the dense_vector stats. Relates elastic#111729
1 parent 00f2058 commit 8080aac

File tree

3 files changed

+17
-4
lines changed
  • docs/changelog
  • rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.stats
  • server/src/main/java/org/elasticsearch/index/engine

3 files changed

+17
-4
lines changed

docs/changelog/112720.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 112720
2+
summary: Fix NPE in `dense_vector` stats
3+
area: Vector Search
4+
type: bug
5+
issues: []

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.stats/10_basic.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@
258258
---
259259
"Dense vector stats":
260260
- requires:
261-
cluster_features: [ "gte_v8.15.0" ]
262-
reason: "dense vector stats reports from primary indices in 8.15"
261+
cluster_features: [ "gte_v8.16.0" ]
262+
reason: "dense vector stats reports from primary indices in 8.15 and fixed in 8.16"
263263
- do:
264264
indices.create:
265265
index: test1
@@ -329,9 +329,17 @@
329329
- do:
330330
indices.refresh: { }
331331

332+
- do:
333+
index:
334+
index: test2
335+
id: "3"
336+
refresh: true
337+
body:
338+
not_vector_field: "not vector"
339+
332340
- do: { cluster.stats: { } }
333341

334-
- match: { indices.docs.count: 4 }
342+
- match: { indices.docs.count: 5 }
335343
- match: { indices.docs.deleted: 0 }
336344
- match: { indices.dense_vector.value_count: 8 }
337345

server/src/main/java/org/elasticsearch/index/engine/Engine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private long getDenseVectorValueCount(final LeafReader atomicReader, List<String
279279
long count = 0;
280280
for (var field : fields) {
281281
var info = atomicReader.getFieldInfos().fieldInfo(field);
282-
if (info.getVectorDimension() > 0) {
282+
if (info != null && info.getVectorDimension() > 0) {
283283
switch (info.getVectorEncoding()) {
284284
case FLOAT32 -> {
285285
FloatVectorValues values = atomicReader.getFloatVectorValues(info.name);

0 commit comments

Comments
 (0)