Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.index.MapperTestUtils;
import org.elasticsearch.index.codec.bloomfilter.ES87BloomFilterPostingsFormat;
import org.elasticsearch.index.codec.postings.ES812PostingsFormat;
import org.elasticsearch.index.codec.tsdb.TSDBSyntheticIdPostingsFormat;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.SeqNoFieldMapper;
import org.elasticsearch.index.mapper.SourceFieldMapper;
Expand Down Expand Up @@ -93,34 +94,46 @@ public class PerFieldMapperCodecTests extends ESTestCase {
""";

public void testUseBloomFilter() throws IOException {
boolean timeSeries = randomBoolean();
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(false, timeSeries, false);
final boolean timeSeries = randomBoolean();
final boolean randomSyntheticId = syntheticId(timeSeries);
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(false, timeSeries, false, randomSyntheticId);
assertThat(perFieldMapperCodec.useBloomFilter("_id"), is(true));
assertThat(perFieldMapperCodec.getPostingsFormatForField("_id"), instanceOf(ES87BloomFilterPostingsFormat.class));
assertThat(
perFieldMapperCodec.getPostingsFormatForField("_id"),
instanceOf(randomSyntheticId ? TSDBSyntheticIdPostingsFormat.class : ES87BloomFilterPostingsFormat.class)
);
assertThat(perFieldMapperCodec.useBloomFilter("another_field"), is(false));

Class<? extends PostingsFormat> expectedPostingsFormat = timeSeries ? ES812PostingsFormat.class : Lucene103PostingsFormat.class;
assertThat(perFieldMapperCodec.getPostingsFormatForField("another_field"), instanceOf(expectedPostingsFormat));
}

public void testUseBloomFilterWithTimestampFieldEnabled() throws IOException {
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, true, false);
final boolean randomSyntheticId = syntheticId(true);
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, true, false, randomSyntheticId);
assertThat(perFieldMapperCodec.useBloomFilter("_id"), is(true));
assertThat(perFieldMapperCodec.getPostingsFormatForField("_id"), instanceOf(ES87BloomFilterPostingsFormat.class));
assertThat(
perFieldMapperCodec.getPostingsFormatForField("_id"),
instanceOf(randomSyntheticId ? TSDBSyntheticIdPostingsFormat.class : ES87BloomFilterPostingsFormat.class)
);
assertThat(perFieldMapperCodec.useBloomFilter("another_field"), is(false));
assertThat(perFieldMapperCodec.getPostingsFormatForField("another_field"), instanceOf(ES812PostingsFormat.class));
}

public void testUseBloomFilterWithTimestampFieldEnabled_noTimeSeriesMode() throws IOException {
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, false, false);
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, false, false, false);
assertThat(perFieldMapperCodec.useBloomFilter("_id"), is(false));
assertThat(perFieldMapperCodec.getPostingsFormatForField("_id"), instanceOf(ES812PostingsFormat.class));
}

public void testUseBloomFilterWithTimestampFieldEnabled_disableBloomFilter() throws IOException {
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, true, true);
final boolean randomSyntheticId = syntheticId(true);
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, true, true, randomSyntheticId);
assertThat(perFieldMapperCodec.useBloomFilter("_id"), is(false));
assertThat(perFieldMapperCodec.getPostingsFormatForField("_id"), instanceOf(ES812PostingsFormat.class));
assertThat(
perFieldMapperCodec.getPostingsFormatForField("_id"),
instanceOf(randomSyntheticId ? TSDBSyntheticIdPostingsFormat.class : ES812PostingsFormat.class)
);
assertWarnings(
"[index.bloom_filter_for_id_field.enabled] setting was deprecated in Elasticsearch and will be removed in a future release. "
+ "See the deprecation documentation for the next major version."
Expand Down Expand Up @@ -159,23 +172,30 @@ public void testUseEs812PostingsFormatForIdField() throws IOException {
for (int i = 0; i < numIterations; i++) {
var indexMode = randomFrom(IndexMode.STANDARD, IndexMode.LOGSDB, IndexMode.TIME_SERIES);
String mapping = randomFrom(MAPPING_1, MAPPING_2, MAPPING_3);
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(randomBoolean(), randomBoolean(), indexMode, mapping);
final boolean randomSyntheticId = syntheticId(indexMode.equals(IndexMode.TIME_SERIES));
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(
randomBoolean(),
randomBoolean(),
indexMode,
mapping,
randomSyntheticId
);
var result = perFieldMapperCodec.getPostingsFormatForField("_id");
if (result instanceof ES87BloomFilterPostingsFormat es87BloomFilterPostingsFormat) {
Function<String, PostingsFormat> postingsFormats = es87BloomFilterPostingsFormat.getPostingsFormats();
result = postingsFormats.apply("_id");
}
assertThat(result, instanceOf(ES812PostingsFormat.class));
assertThat(result, (instanceOf(randomSyntheticId ? TSDBSyntheticIdPostingsFormat.class : ES812PostingsFormat.class)));
}
}

public void testUseES87TSDBEncodingForTimestampField() throws IOException {
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, true, true);
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, true, true, syntheticId(true));
assertThat((perFieldMapperCodec.useTSDBDocValuesFormat("@timestamp")), is(true));
}

public void testDoNotUseES87TSDBEncodingForTimestampFieldNonTimeSeriesIndex() throws IOException {
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, false, true);
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, false, true, false);
assertThat((perFieldMapperCodec.useTSDBDocValuesFormat("@timestamp")), is(false));
}

Expand All @@ -191,13 +211,20 @@ public void testDisableES87TSDBCodec() throws IOException {
assertThat((perFieldMapperCodec.useTSDBDocValuesFormat("@timestamp")), is(false));
}

private PerFieldFormatSupplier createFormatSupplier(boolean timestampField, boolean timeSeries, boolean disableBloomFilter)
throws IOException {
private PerFieldFormatSupplier createFormatSupplier(
boolean timestampField,
boolean timeSeries,
boolean disableBloomFilter,
boolean syntheticId
) throws IOException {
Settings.Builder settings = Settings.builder();
if (timeSeries) {
settings.put(IndexSettings.MODE.getKey(), "time_series");
settings.put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "field");
}
if (IndexSettings.TSDB_SYNTHETIC_ID_FEATURE_FLAG) {
settings.put(IndexSettings.SYNTHETIC_ID.getKey(), syntheticId);
}
if (disableBloomFilter) {
settings.put(IndexSettings.BLOOM_FILTER_ID_FIELD_ENABLED_SETTING.getKey(), false);
}
Expand Down Expand Up @@ -235,7 +262,7 @@ public void testUseTimeSeriesModeDisabledCodecDisabled() throws IOException {
}

public void testUseTimeSeriesDocValuesCodecSetting() throws IOException {
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, null, false, IndexMode.STANDARD, MAPPING_2);
PerFieldFormatSupplier perFieldMapperCodec = createFormatSupplier(true, null, false, IndexMode.STANDARD, MAPPING_2, false);
assertThat((perFieldMapperCodec.useTSDBDocValuesFormat("@timestamp")), is(true));
assertThat((perFieldMapperCodec.useTSDBDocValuesFormat("counter")), is(true));
assertThat((perFieldMapperCodec.useTSDBDocValuesFormat("gauge")), is(true));
Expand Down Expand Up @@ -279,21 +306,35 @@ private PerFieldFormatSupplier createFormatSupplier(
IndexMode mode,
String mapping
) throws IOException {
return createFormatSupplier(null, enableES87TSDBCodec, useEs812PostingsFormat, mode, mapping);
return createFormatSupplier(null, enableES87TSDBCodec, useEs812PostingsFormat, mode, mapping, null);
}

private PerFieldFormatSupplier createFormatSupplier(
Boolean enableES87TSDBCodec,
Boolean useEs812PostingsFormat,
IndexMode mode,
String mapping,
boolean syntheticId
) throws IOException {
return createFormatSupplier(null, enableES87TSDBCodec, useEs812PostingsFormat, mode, mapping, syntheticId);
}

private PerFieldFormatSupplier createFormatSupplier(
Boolean useTimeSeriesDocValuesFormatSetting,
Boolean enableES87TSDBCodec,
Boolean useEs812PostingsFormat,
IndexMode mode,
String mapping
String mapping,
Boolean syntheticId
) throws IOException {
Settings.Builder settings = Settings.builder();
settings.put(IndexSettings.MODE.getKey(), mode);
if (mode == IndexMode.TIME_SERIES) {
settings.put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "field");
}
if (IndexSettings.TSDB_SYNTHETIC_ID_FEATURE_FLAG && syntheticId != null) {
settings.put(IndexSettings.SYNTHETIC_ID.getKey(), syntheticId);
}
if (enableES87TSDBCodec != null) {
settings.put(IndexSettings.TIME_SERIES_ES87TSDB_CODEC_ENABLED_SETTING.getKey(), enableES87TSDBCodec);
}
Expand All @@ -308,4 +349,7 @@ private PerFieldFormatSupplier createFormatSupplier(
return new PerFieldFormatSupplier(mapperService, BigArrays.NON_RECYCLING_INSTANCE, null);
}

private static boolean syntheticId(boolean timeSeries) {
return IndexSettings.TSDB_SYNTHETIC_ID_FEATURE_FLAG && timeSeries && randomBoolean();
}
}