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 e8551c88..9131535f 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapper.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/knn/index/KNNVectorFieldMapper.java @@ -98,10 +98,21 @@ public static class Builder extends ParametrizedFieldMapper.Builder { }, m -> toType(m).dimension); private final Parameter> meta = Parameter.metaParam(); + private String spaceType; + private String m; + private String efConstruction; + public Builder(String name) { super(name); } + public Builder(String name, String spaceType, String m, String efConstruction) { + super(name); + this.spaceType = spaceType; + this.m = m; + this.efConstruction = efConstruction; + } + @Override protected List> getParameters() { return Arrays.asList(stored, hasDocValues, dimension, meta); @@ -119,10 +130,21 @@ protected Explicit ignoreMalformed(BuilderContext context) { @Override public KNNVectorFieldMapper build(BuilderContext context) { + if (this.spaceType == null) { + this.spaceType = getSpaceType(context.indexSettings()); + } + + if (this.m == null) { + this.m = getM(context.indexSettings()); + } + + if (this.efConstruction == null) { + this.efConstruction = getEfConstruction(context.indexSettings()); + } + return new KNNVectorFieldMapper(name, new KNNVectorFieldType(buildFullName(context), meta.getValue(), dimension.getValue()), multiFieldsBuilder.build(this, context), - ignoreMalformed(context), getSpaceType(context.indexSettings()), getM(context.indexSettings()), - getEfConstruction(context.indexSettings()), copyTo.build(), this); + ignoreMalformed(context), this.spaceType, this.m, this.efConstruction, copyTo.build(), this); } private String getSpaceType(Settings indexSettings) { @@ -337,7 +359,7 @@ protected boolean docValuesByDefault() { @Override public ParametrizedFieldMapper.Builder getMergeBuilder() { - return new KNNVectorFieldMapper.Builder(simpleName()).init(this); + return new KNNVectorFieldMapper.Builder(simpleName(), this.spaceType, this.m, this.efConstruction).init(this); } @Override