diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNN84Codec/KNN84Codec.java b/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNN84Codec/KNN84Codec.java index 30c3d1c5..9c3ae88c 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNN84Codec/KNN84Codec.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNN84Codec/KNN84Codec.java @@ -44,6 +44,7 @@ public final class KNN84Codec extends Codec { private final DocValuesFormat perFieldDocValuesFormat; private final CompoundFormat compoundFormat; private Codec lucene84Codec; + private PostingsFormat postingsFormat = null; public static final String KNN_84 = "KNN84Codec"; public static final String LUCENE_84 = "Lucene84"; // Lucene Codec to be used @@ -82,9 +83,16 @@ public DocValuesFormat docValuesFormat() { * approach of manually overriding. */ + public void setPostingsFormat(PostingsFormat postingsFormat) { + this.postingsFormat = postingsFormat; + } + @Override public PostingsFormat postingsFormat() { - return getDelegatee().postingsFormat(); + if (this.postingsFormat == null) { + return getDelegatee().postingsFormat(); + } + return this.postingsFormat; } @Override diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/KNNCodecService.java b/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/KNNCodecService.java index f3119247..df157ab8 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/KNNCodecService.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/KNNCodecService.java @@ -16,7 +16,9 @@ package com.amazon.opendistroforelasticsearch.knn.plugin; +import com.amazon.opendistroforelasticsearch.knn.index.codec.KNN84Codec.KNN84Codec; import org.apache.lucene.codecs.Codec; +import org.apache.lucene.codecs.PostingsFormat; import org.elasticsearch.index.codec.CodecService; import static com.amazon.opendistroforelasticsearch.knn.index.codec.KNN84Codec.KNN84Codec.KNN_84; @@ -35,7 +37,7 @@ class KNNCodecService extends CodecService { * return the KNN Codec * * @param name dummy name - * @return KNN80Codec + * @return KNN84Codec */ @Override public Codec codec(String name) { @@ -45,4 +47,9 @@ public Codec codec(String name) { } return codec; } + + public void setPostingsFormat(PostingsFormat postingsFormat) { + ((KNN84Codec)codec("")).setPostingsFormat(postingsFormat); + } + } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/KNNEngineFactory.java b/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/KNNEngineFactory.java index c70be1b9..879a1dcc 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/KNNEngineFactory.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/KNNEngineFactory.java @@ -16,7 +16,6 @@ package com.amazon.opendistroforelasticsearch.knn.plugin; -import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.EngineConfig; import org.elasticsearch.index.engine.EngineFactory; @@ -27,10 +26,11 @@ */ class KNNEngineFactory implements EngineFactory { - private static CodecService codecService = new KNNCodecService(); + private static KNNCodecService codecService = new KNNCodecService(); @Override public Engine newReadWriteEngine(EngineConfig config) { + codecService.setPostingsFormat(config.getCodec().postingsFormat()); EngineConfig engineConfig = new EngineConfig(config.getShardId(), config.getAllocationId(), config.getThreadPool(), config.getIndexSettings(), config.getWarmer(), config.getStore(), config.getMergePolicy(), config.getAnalyzer(), config.getSimilarity(), codecService,