From 3a4e2fc06eee76d5fad5265134f63b53bd1fd555 Mon Sep 17 00:00:00 2001 From: Jack Mazanec Date: Wed, 14 Oct 2020 12:42:40 -0700 Subject: [PATCH] Fix bug in KNNVectorFieldMapper for ODFE 1.8 (#244) --- .../knn/index/KNNVectorFieldMapper.java | 5 +++-- .../knn/index/KNNVectorFieldMapperTests.java | 9 ++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapper.java b/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapper.java index 19fc8c6c..b7469811 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapper.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapper.java @@ -88,6 +88,7 @@ public static class Defaults { FIELD_TYPE.setHasDocValues(true); FIELD_TYPE.setDocValuesType(DocValuesType.BINARY); FIELD_TYPE.putAttribute(KNN_FIELD, "true"); //This attribute helps to determine knn field type + FIELD_TYPE.freeze(); } } @@ -105,12 +106,12 @@ public Builder ignoreMalformed(boolean ignoreMalformed) { } public Builder spaceTypeParam(String key, String paramValue) { - Defaults.FIELD_TYPE.putAttribute(key, paramValue.toLowerCase()); + builder.fieldType.putAttribute(key, paramValue.toLowerCase()); return builder; } public Builder algoParams(String key, int paramValue) { - Defaults.FIELD_TYPE.putAttribute(key, String.valueOf(paramValue)); + builder.fieldType.putAttribute(key, String.valueOf(paramValue)); return builder; } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapperTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapperTests.java index c279ac59..4851e605 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapperTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapperTests.java @@ -57,14 +57,13 @@ public void testBuildKNNIndexSettings_emptySettings_checkDefaultsSet() { KNNVectorFieldMapper.TypeParser typeParser = new KNNVectorFieldMapper.TypeParser(); typeParser.buildKNNIndexSettings(builder, parserContext); - assertEquals(KNNVectorFieldMapper.Defaults.FIELD_TYPE.getAttributes().get(KNNConstants.SPACE_TYPE), + assertEquals(builder.fieldType().getAttributes().get(KNNConstants.SPACE_TYPE), INDEX_KNN_DEFAULT_SPACE_TYPE); - assertEquals(KNNVectorFieldMapper.Defaults.FIELD_TYPE.getAttributes().get(KNNConstants.HNSW_ALGO_M), + assertEquals(builder.fieldType().getAttributes().get(KNNConstants.HNSW_ALGO_M), String.valueOf(INDEX_KNN_DEFAULT_ALGO_PARAM_M)); - assertEquals(KNNVectorFieldMapper.Defaults.FIELD_TYPE.getAttributes().get( - KNNConstants.HNSW_ALGO_EF_CONSTRUCTION), String.valueOf( - INDEX_KNN_DEFAULT_ALGO_PARAM_EF_CONSTRUCTION)); + assertEquals(builder.fieldType().getAttributes().get(KNNConstants.HNSW_ALGO_EF_CONSTRUCTION), + String.valueOf(INDEX_KNN_DEFAULT_ALGO_PARAM_EF_CONSTRUCTION)); } } \ No newline at end of file