Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions docs/changelog/138724.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 138724
summary: '`AggregateMetricDouble` fields should not build BKD indexes'
area: Mapping
type: feature
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ private static Version parseUnchecked(String version) {
public static final IndexVersion UPGRADE_TO_LUCENE_10_3_2 = def(9_047_0_00, Version.LUCENE_10_3_2);
public static final IndexVersion SECURITY_MIGRATIONS_METADATA_FLATTENED_UPDATE = def(9_048_0_00, Version.LUCENE_10_3_2);
public static final IndexVersion STANDARD_INDEXES_USE_SKIPPERS = def(9_049_0_00, Version.LUCENE_10_3_2);
public static final IndexVersion AGG_METRIC_DOUBLE_SKIPPERS = def(9_050_0_00, Version.LUCENE_10_3_2);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ public Builder coerce(boolean coerce) {
return this;
}

public Builder index(boolean index) {
this.indexed.setValue(index);
return this;
}

public Builder docValues(boolean hasDocValues) {
this.hasDocValues.setValue(hasDocValues);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.common.time.DateMathParser;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.fielddata.FieldDataContext;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.ScriptDocValues;
Expand Down Expand Up @@ -232,13 +233,19 @@ public AggregateMetricDoubleFieldMapper build(MapperBuilderContext context) {
ScriptCompiler.NONE,
indexSettings
).allowMultipleValues(false).ignoreMalformed(false).coerce(false);
if (indexSettings.getIndexVersionCreated().onOrAfter(IndexVersions.AGG_METRIC_DOUBLE_SKIPPERS)) {
builder.index(false);
}
} else {
builder = new NumberFieldMapper.Builder(
fieldName,
NumberFieldMapper.NumberType.DOUBLE,
ScriptCompiler.NONE,
indexSettings
).allowMultipleValues(false).ignoreMalformed(false).coerce(true);
if (indexSettings.getIndexVersionCreated().onOrAfter(IndexVersions.AGG_METRIC_DOUBLE_SKIPPERS)) {
builder.index(false);
}
}
NumberFieldMapper fieldMapper = builder.build(context);
metricMappers.put(m, fieldMapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
*/
package org.elasticsearch.xpack.aggregatemetric.mapper;

import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.DocValuesSkipIndexType;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.NumericUtils;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentParsingException;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.LuceneDocument;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
Expand All @@ -20,6 +29,7 @@
import org.elasticsearch.index.mapper.MapperTestCase;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.index.IndexVersionUtils;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.json.JsonXContent;
Expand Down Expand Up @@ -105,7 +115,12 @@ public void testParseValue() throws Exception {
ParsedDocument doc = mapper.parse(
source(b -> b.startObject("field").field("min", -10.1).field("max", 50.0).field("value_count", 14).endObject())
);
assertEquals("DoubleField <field.min:-10.1>", doc.rootDoc().getField("field.min").toString());

IndexableField f = doc.rootDoc().getField("field.min");
assertThat(f, instanceOf(SortedNumericDocValuesField.class));
SortedNumericDocValuesField sdv = (SortedNumericDocValuesField) f;
assertEquals(NumericUtils.doubleToSortableLong(-10.1), sdv.numericValue());
assertThat(sdv.fieldType().docValuesSkipIndexType(), equalTo(DocValuesSkipIndexType.RANGE));

Mapper fieldMapper = mapper.mappers().getMapper("field");
assertThat(fieldMapper, instanceOf(AggregateMetricDoubleFieldMapper.class));
Expand Down Expand Up @@ -626,6 +641,39 @@ protected List<SortShortcutSupport> getSortShortcutSupport() {

@Override
protected boolean supportsDocValuesSkippers() {
return false;
return false; // can't configure `index` so normal test doesn't work
}

public void testIndexTypes() throws Exception {
{
var indexSettings = getIndexSettingsBuilder().put(IndexSettings.MODE.getKey(), IndexMode.TIME_SERIES.getName())
.put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "dimension_field")
.build();
MapperService mapperService = createMapperService(indexSettings, fieldMapping(this::minimalMapping));
MappedFieldType ft = mapperService.fieldType("field");
assertIndexType(ft, IndexType.skippers());
}
{
var oldVersion = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.AGG_METRIC_DOUBLE_SKIPPERS);
MapperService mapperService = createMapperService(oldVersion, fieldMapping(this::minimalMapping));
MappedFieldType ft = mapperService.fieldType("field");
assertIndexType(ft, IndexType.points(true, true));
}
{
MapperService mapperService = createMapperService(IndexVersions.AGG_METRIC_DOUBLE_SKIPPERS, fieldMapping(this::minimalMapping));
MappedFieldType ft = mapperService.fieldType("field");
assertIndexType(ft, IndexType.skippers());
}
}

private void assertIndexType(MappedFieldType ft, IndexType indexType) {
assertThat(ft, instanceOf(AggregateMetricDoubleFieldMapper.AggregateMetricDoubleFieldType.class));
AggregateMetricDoubleFieldMapper.AggregateMetricDoubleFieldType aft =
(AggregateMetricDoubleFieldMapper.AggregateMetricDoubleFieldType) ft;
assertThat(aft.indexType(), equalTo(indexType));
for (MappedFieldType subField : aft.getMetricFields().values()) {
assertThat(subField.indexType(), equalTo(indexType));
}
}

}