Skip to content

Commit

Permalink
tweak keyword field to use binary DV
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhmaurya committed Dec 12, 2024
1 parent 05513df commit 61d7250
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.document.BinaryDocValuesField;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.SortedSetDocValuesField;
Expand Down Expand Up @@ -61,6 +62,7 @@
import org.opensearch.index.analysis.NamedAnalyzer;
import org.opensearch.index.compositeindex.datacube.DimensionType;
import org.opensearch.index.fielddata.IndexFieldData;
import org.opensearch.index.fielddata.plain.BinaryIndexFieldData;
import org.opensearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.index.similarity.SimilarityProvider;
Expand Down Expand Up @@ -167,6 +169,13 @@ public static class Builder extends ParametrizedFieldMapper.Builder {
false
);

private final Parameter<Boolean> useBinaryDV = Parameter.boolParam(
"use_binary_doc_value",
true,
m -> toType(m).useBinaryDocValue,
false
);

private final Parameter<Map<String, String>> meta = Parameter.metaParam();
private final Parameter<Float> boost = Parameter.boostParam();

Expand Down Expand Up @@ -333,7 +342,8 @@ NamedAnalyzer normalizer() {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
failIfNoDocValues();
return new SortedSetOrdinalsIndexFieldData.Builder(name(), CoreValuesSourceType.BYTES);
return new BinaryIndexFieldData.Builder(name() + ".binary", CoreValuesSourceType.BYTES);
// return new SortedSetOrdinalsIndexFieldData.Builder(name(), CoreValuesSourceType.BYTES);
}

@Override
Expand Down Expand Up @@ -661,6 +671,7 @@ public Query wildcardQuery(
private final SimilarityProvider similarity;
private final String normalizerName;
private final boolean splitQueriesOnWhitespace;
private final boolean useBinaryDocValue;

private final IndexAnalyzers indexAnalyzers;

Expand All @@ -684,7 +695,7 @@ protected KeywordFieldMapper(
this.similarity = builder.similarity.getValue();
this.normalizerName = builder.normalizer.getValue();
this.splitQueriesOnWhitespace = builder.splitQueriesOnWhitespace.getValue();

this.useBinaryDocValue = builder.useBinaryDV.getValue();
this.indexAnalyzers = builder.indexAnalyzers;
}

Expand Down Expand Up @@ -741,7 +752,11 @@ protected void parseCreateField(ParseContext context) throws IOException {
}

if (fieldType().hasDocValues()) {
context.doc().add(new SortedSetDocValuesField(fieldType().name(), binaryValue));
if (useBinaryDocValue) {
context.doc().add(new BinaryDocValuesField(fieldType().name() + ".binary", binaryValue));
} else {
context.doc().add(new SortedSetDocValuesField(fieldType().name(), binaryValue));
}
}
}

Expand Down

0 comments on commit 61d7250

Please sign in to comment.