Skip to content

Commit e3509c8

Browse files
committed
Introduce index.mapping.use_binary_doc_values to experiment with binary doc values for keyword field.
1 parent 3979d74 commit e3509c8

File tree

12 files changed

+307
-47
lines changed

12 files changed

+307
-47
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/_nightly/esql/ValuesSourceReaderBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ private static BlockLoader blockLoader(String name) {
222222
Lucene.KEYWORD_ANALYZER,
223223
Lucene.KEYWORD_ANALYZER,
224224
new KeywordFieldMapper.Builder(name, IndexVersion.current()).docValues(ft.docValuesType() != DocValuesType.NONE),
225-
syntheticSource
226-
).blockLoader(new MappedFieldType.BlockLoaderContext() {
225+
syntheticSource,
226+
useBinaryDocValues).blockLoader(new MappedFieldType.BlockLoaderContext() {
227227
@Override
228228
public String indexName() {
229229
return "benchmark";

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldTypeTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ public void testBlockLoaderDoesNotUseSyntheticSourceDelegateWhenIgnoreAboveIsSet
298298
mock(NamedAnalyzer.class),
299299
mock(NamedAnalyzer.class),
300300
builder,
301-
true
302-
);
301+
true,
302+
useBinaryDocValues);
303303

304304
MatchOnlyTextFieldMapper.MatchOnlyTextFieldType ft = new MatchOnlyTextFieldMapper.MatchOnlyTextFieldType(
305305
"parent",
@@ -346,8 +346,8 @@ public void testBlockLoaderDoesNotUseSyntheticSourceDelegateWhenIgnoreAboveIsSet
346346
mock(NamedAnalyzer.class),
347347
mock(NamedAnalyzer.class),
348348
builder,
349-
true
350-
);
349+
true,
350+
useBinaryDocValues);
351351

352352
MatchOnlyTextFieldMapper.MatchOnlyTextFieldType ft = new MatchOnlyTextFieldMapper.MatchOnlyTextFieldType(
353353
"parent",

server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
243243
if (IndexSettings.DOC_VALUES_SKIPPER) {
244244
settings.add(IndexSettings.USE_DOC_VALUES_SKIPPER);
245245
}
246+
settings.add(IndexSettings.USE_BINARY_DOC_VALUES);
246247
settings.add(IndexSettings.INDEX_MAPPING_EXCLUDE_SOURCE_VECTORS_SETTING);
247248
BUILT_IN_INDEX_SETTINGS = Collections.unmodifiableSet(settings);
248249
};

server/src/main/java/org/elasticsearch/index/IndexSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,13 @@ public boolean isES87TSDBCodecEnabled() {
675675
Property.Final
676676
);
677677

678+
public static final Setting<Boolean> USE_BINARY_DOC_VALUES = Setting.boolSetting(
679+
"index.mapping.use_binary_doc_values",
680+
false,
681+
Property.IndexScope,
682+
Property.Final
683+
);
684+
678685
/**
679686
* The {@link IndexMode "mode"} of the index.
680687
*/

server/src/main/java/org/elasticsearch/index/mapper/BlockDocValuesReader.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,28 @@ public AllReader reader(LeafReaderContext context) throws IOException {
925925
}
926926
}
927927

928+
public static class BytesRefsFromBinaryBlockLoader extends DocValuesBlockLoader {
929+
private final String fieldName;
930+
931+
public BytesRefsFromBinaryBlockLoader(String fieldName) {
932+
this.fieldName = fieldName;
933+
}
934+
935+
@Override
936+
public Builder builder(BlockFactory factory, int expectedCount) {
937+
return factory.bytesRefs(expectedCount);
938+
}
939+
940+
@Override
941+
public AllReader reader(LeafReaderContext context) throws IOException {
942+
BinaryDocValues docValues = context.reader().getBinaryDocValues(fieldName);
943+
if (docValues == null) {
944+
return new ConstantNullsReader();
945+
}
946+
return new BytesRefsFromBinary(docValues);
947+
}
948+
}
949+
928950
abstract static class AbstractBytesRefsFromBinary extends BlockDocValuesReader {
929951
protected final BinaryDocValues docValues;
930952

0 commit comments

Comments
 (0)