From c06665bef232b1538aefbafeb517058ff8d2328c Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Tue, 10 Sep 2024 15:28:41 -0700 Subject: [PATCH] Fix NPE in dense_vector stats (#112720) 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 #111729 --- docs/changelog/112720.yaml | 5 +++++ .../rest-api-spec/test/cluster.stats/10_basic.yml | 14 +++++++++++--- .../org/elasticsearch/index/engine/Engine.java | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 docs/changelog/112720.yaml diff --git a/docs/changelog/112720.yaml b/docs/changelog/112720.yaml new file mode 100644 index 0000000000000..a44ea5a699520 --- /dev/null +++ b/docs/changelog/112720.yaml @@ -0,0 +1,5 @@ +pr: 112720 +summary: Fix NPE in `dense_vector` stats +area: Vector Search +type: bug +issues: [] diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.stats/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.stats/10_basic.yml index cf43797a451e7..06139542c5e55 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.stats/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.stats/10_basic.yml @@ -258,8 +258,8 @@ --- "Dense vector stats": - requires: - cluster_features: [ "gte_v8.15.0" ] - reason: "dense vector stats reports from primary indices in 8.15" + cluster_features: [ "gte_v8.16.0" ] + reason: "dense vector stats reports from primary indices in 8.15 and fixed in 8.16" - do: indices.create: index: test1 @@ -329,9 +329,17 @@ - do: indices.refresh: { } + - do: + index: + index: test2 + id: "3" + refresh: true + body: + not_vector_field: "not vector" + - do: { cluster.stats: { } } - - match: { indices.docs.count: 4 } + - match: { indices.docs.count: 5 } - match: { indices.docs.deleted: 0 } - match: { indices.dense_vector.value_count: 8 } diff --git a/server/src/main/java/org/elasticsearch/index/engine/Engine.java b/server/src/main/java/org/elasticsearch/index/engine/Engine.java index b07132eea75e8..ba2b9344efaa9 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -279,7 +279,7 @@ private long getDenseVectorValueCount(final LeafReader atomicReader, List 0) { + if (info != null && info.getVectorDimension() > 0) { switch (info.getVectorEncoding()) { case FLOAT32 -> { FloatVectorValues values = atomicReader.getFloatVectorValues(info.name);