From d015c352e15aa31e877a716f3e66a76121747166 Mon Sep 17 00:00:00 2001 From: Martin Gaievski Date: Mon, 24 Oct 2022 14:43:18 -0700 Subject: [PATCH] Adding code comments Signed-off-by: Martin Gaievski --- .../org/opensearch/knn/index/query/KNNQueryBuilder.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java b/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java index 08ed23d05..ebf721304 100644 --- a/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java +++ b/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java @@ -112,6 +112,8 @@ public KNNQueryBuilder(StreamInput in) throws IOException { fieldName = in.readString(); vector = in.readFloatArray(); k = in.readInt(); + // We're checking if all cluster nodes has at least that version or higher. This check is required + // to avoid issues with cluster upgrade if (isClusterOnOrAfterMinRequiredVersion()) { filter = in.readOptionalNamedWriteable(QueryBuilder.class); } @@ -159,6 +161,10 @@ public static KNNQueryBuilder fromXContent(XContentParser parser) throws IOExcep if (FILTER_FIELD.getPreferredName().equals(tokenName)) { log.debug(String.format("Start parsing filter for field [%s]", fieldName)); KNNCounter.KNN_QUERY_WITH_FILTER_REQUESTS.increment(); + // Query filters are supported starting from a certain k-NN version only, exact version is defined by + // MINIMAL_SUPPORTED_VERSION_FOR_LUCENE_HNSW_FILTER variable. + // Here we're checking if all cluster nodes has at least that version or higher. This check is required + // to avoid issues with rolling cluster upgrade if (isClusterOnOrAfterMinRequiredVersion()) { filter = parseInnerQueryBuilder(parser); } else { @@ -204,6 +210,8 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeString(fieldName); out.writeFloatArray(vector); out.writeInt(k); + // We're checking if all cluster nodes has at least that version or higher. This check is required + // to avoid issues with cluster upgrade if (isClusterOnOrAfterMinRequiredVersion()) { out.writeOptionalNamedWriteable(filter); }