Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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 @@ -51,6 +51,7 @@
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.mapper.BlockLoader;
import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.NumberFieldMapper;
Expand Down Expand Up @@ -290,9 +291,8 @@ private static BlockLoader numericBlockLoader(WhereAndBaseName w, NumberFieldMap
return new NumberFieldMapper.NumberFieldType(
w.name,
numberType,
true,
docValues ? IndexType.POINTS : IndexType.POINTS_WITHOUT_DOC_VALUES,
stored,
docValues,
true,
null,
Map.of(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.index.fielddata.FieldDataContext;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MappingLookup;
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType;
Expand Down Expand Up @@ -85,7 +86,23 @@ public class ScriptScoreBenchmark {
private final ScriptModule scriptModule = new ScriptModule(Settings.EMPTY, pluginsService.filterPlugins(ScriptPlugin.class).toList());

private final Map<String, MappedFieldType> fieldTypes = Map.ofEntries(
Map.entry("n", new NumberFieldType("n", NumberType.LONG, false, false, true, true, null, Map.of(), null, false, null, null, false))
Map.entry(
"n",
new NumberFieldType(
"n",
NumberType.LONG,
IndexType.DOC_VALUES_ONLY,
false,
true,
null,
Map.of(),
null,
false,
null,
null,
false
)
)
);
private final IndexFieldDataCache fieldDataCache = new IndexFieldDataCache.None();
private final CircuitBreakerService breakerService = new NoneCircuitBreakerService();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.elasticsearch.index.mapper.DocumentParsingException;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.GeoShapeQueryable;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperBuilderContext;
Expand Down Expand Up @@ -426,7 +427,7 @@ private GeoShapeFieldType(
LegacyGeoShapeParser parser,
Map<String, String> meta
) {
super(name, indexed, false, false, parser, orientation, meta);
super(name, indexed ? IndexType.TERMS_WITHOUT_DOC_VALUES : IndexType.NONE, false, parser, orientation, meta);
this.queryProcessor = new LegacyGeoShapeQueryProcessor(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.SourceValueFetcher;
Expand Down Expand Up @@ -113,7 +114,7 @@ public static final class RankFeatureFieldType extends MappedFieldType {
private final Float nullValue;

public RankFeatureFieldType(String name, Map<String, String> meta, boolean positiveScoreImpact, Float nullValue) {
super(name, true, false, false, meta);
super(name, IndexType.TERMS_WITHOUT_DOC_VALUES, false, meta);
this.positiveScoreImpact = positiveScoreImpact;
this.nullValue = nullValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.search.Query;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.ValueFetcher;
Expand All @@ -37,7 +38,7 @@ public static final class RankFeatureMetaFieldType extends MappedFieldType {

// made visible for tests
RankFeatureMetaFieldType() {
super(NAME, false, false, false, Collections.emptyMap());
super(NAME, IndexType.NONE, false, Collections.emptyMap());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.SourceValueFetcher;
Expand Down Expand Up @@ -80,7 +81,7 @@ public static final class RankFeaturesFieldType extends MappedFieldType {
private final boolean positiveScoreImpact;

public RankFeaturesFieldType(String name, Map<String, String> meta, boolean positiveScoreImpact) {
super(name, true, false, false, meta);
super(name, IndexType.TERMS_WITHOUT_DOC_VALUES, false, meta);
this.positiveScoreImpact = positiveScoreImpact;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.IgnoreMalformedStoredValues;
import org.elasticsearch.index.mapper.IgnoredSourceFieldMapper;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.mapper.SimpleMappedFieldType;
Expand Down Expand Up @@ -219,11 +220,11 @@ protected Parameter<?>[] getParameters() {

@Override
public ScaledFloatFieldMapper build(MapperBuilderContext context) {
IndexType indexType = IndexType.points(indexed.get(), hasDocValues.get(), false);
ScaledFloatFieldType type = new ScaledFloatFieldType(
context.buildFullName(leafName()),
indexed.getValue(),
indexType,
stored.getValue(),
hasDocValues.getValue(),
meta.getValue(),
scalingFactor.getValue(),
nullValue.getValue(),
Expand Down Expand Up @@ -273,9 +274,8 @@ public static final class ScaledFloatFieldType extends SimpleMappedFieldType {

public ScaledFloatFieldType(
String name,
boolean indexed,
IndexType indexType,
boolean stored,
boolean hasDocValues,
Map<String, String> meta,
double scalingFactor,
Double nullValue,
Expand All @@ -284,7 +284,7 @@ public ScaledFloatFieldType(
boolean coerce,
boolean isSyntheticSource
) {
super(name, indexed, stored, hasDocValues, meta);
super(name, indexType, stored, meta);
this.scalingFactor = scalingFactor;
this.nullValue = nullValue;
this.metricType = metricType;
Expand All @@ -298,7 +298,18 @@ public ScaledFloatFieldType(String name, double scalingFactor) {
}

public ScaledFloatFieldType(String name, double scalingFactor, boolean indexed) {
this(name, indexed, false, true, Collections.emptyMap(), scalingFactor, null, null, null, false, false);
this(
name,
indexed ? IndexType.POINTS : IndexType.DOC_VALUES_ONLY,
false,
Collections.emptyMap(),
scalingFactor,
null,
null,
null,
false,
false
);
}

public double getScalingFactor() {
Expand All @@ -317,7 +328,7 @@ public boolean mayExistInIndex(SearchExecutionContext context) {

@Override
public boolean isSearchable() {
return isIndexed() || hasDocValues();
return IndexType.hasPoints(indexType) || hasDocValues();
}

@Override
Expand All @@ -329,13 +340,13 @@ public TextSearchInfo getTextSearchInfo() {
public Query termQuery(Object value, SearchExecutionContext context) {
failIfNotIndexedNorDocValuesFallback(context);
long scaledValue = Math.round(scale(value));
return NumberFieldMapper.NumberType.LONG.termQuery(name(), scaledValue, isIndexed());
return NumberFieldMapper.NumberType.LONG.termQuery(name(), scaledValue, indexType() == IndexType.POINTS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should we use IndexType.hasPoints(indexType) like in other places in this class, assuming it's the same?

My main reason is that when reading the code it makes me think that there is something different going on here and it requires the use of the explicit indexType() == IndexType.POINTS. If that's the case, maybe a quick comment would be helpful.

}

@Override
public Query termsQuery(Collection<?> values, SearchExecutionContext context) {
failIfNotIndexedNorDocValuesFallback(context);
if (isIndexed()) {
if (IndexType.hasPoints(indexType)) {
List<Long> scaledValues = new ArrayList<>(values.size());
for (Object value : values) {
long scaledValue = Math.round(scale(value));
Expand Down Expand Up @@ -372,7 +383,16 @@ public Query rangeQuery(
}
hi = Math.round(Math.floor(dValue));
}
return NumberFieldMapper.NumberType.LONG.rangeQuery(name(), lo, hi, true, true, hasDocValues(), context, isIndexed());
return NumberFieldMapper.NumberType.LONG.rangeQuery(
name(),
lo,
hi,
true,
true,
hasDocValues(),
context,
IndexType.hasPoints(indexType)
);
}

@Override
Expand All @@ -399,8 +419,8 @@ public Builder builder(BlockFactory factory, int expectedCount) {
}

ValueFetcher valueFetcher = sourceValueFetcher(blContext.sourcePaths(name()));
BlockSourceReader.LeafIteratorLookup lookup = hasDocValues() == false && (isStored() || isIndexed())
// We only write the field names field if there aren't doc values or norms
BlockSourceReader.LeafIteratorLookup lookup = hasDocValues() == false && isStored()
// We only write the field names field if there aren't doc values
? BlockSourceReader.lookupFromFieldNames(blContext.fieldNames(), name())
: BlockSourceReader.lookupMatchingAll();
return new BlockSourceReader.DoublesBlockLoader(valueFetcher, lookup);
Expand Down Expand Up @@ -477,7 +497,7 @@ public IndexFieldData.Builder fielddataBuilder(FieldDataContext fieldDataContext
(dv, n) -> {
throw new UnsupportedOperationException();
},
isIndexed()
IndexType.hasPoints(indexType)
).build(cache, breakerService);
return new ScaledFloatIndexFieldData(scaledValues, scalingFactor, ScaledFloatDocValuesField::new);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.index.mapper.DocValueFetcher;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand Down Expand Up @@ -107,9 +108,8 @@ static class TokenCountFieldType extends NumberFieldMapper.NumberFieldType {
super(
name,
NumberFieldMapper.NumberType.INTEGER,
isSearchable,
IndexType.points(isSearchable, hasDocValues, false),
isStored,
hasDocValues,
false,
nullValue,
meta,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentParsingException;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand Down Expand Up @@ -341,7 +342,7 @@ public void testTimeSeriesIndexDefault() throws Exception {
}));
var ft = (ScaledFloatFieldMapper.ScaledFloatFieldType) mapperService.fieldType("field");
assertThat(ft.getMetricType(), equalTo(randomMetricType));
assertThat(ft.isIndexed(), is(false));
assertThat(ft.indexType(), is(IndexType.DOC_VALUES_ONLY));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.index.fielddata.LeafNumericFieldData;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.NumberFieldMapper;
Expand Down Expand Up @@ -88,9 +89,8 @@ public void testRangeQuery() throws IOException {
// searching doubles that are rounded to the closest half float
ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType(
"scaled_float",
randomBoolean(),
randomBoolean() ? IndexType.POINTS : IndexType.DOC_VALUES_ONLY,
false,
true,
Collections.emptyMap(),
0.1 + randomDouble() * 100,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.elasticsearch.index.mapper.BinaryFieldMapper;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.LuceneDocument;
import org.elasticsearch.index.mapper.MappedFieldType;
Expand Down Expand Up @@ -239,7 +240,7 @@ static class PercolatorFieldType extends MappedFieldType {
boolean mapUnmappedFieldsAsText;

private PercolatorFieldType(String name, Map<String, String> meta) {
super(name, false, false, false, meta);
super(name, IndexType.NONE, false, meta);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.SourceValueFetcher;
Expand Down Expand Up @@ -68,7 +69,12 @@ public Murmur3FieldMapper build(MapperBuilderContext context) {
public static class Murmur3FieldType extends MappedFieldType {

private Murmur3FieldType(String name, boolean isStored, Map<String, String> meta) {
super(name, false, isStored, true, meta);
super(name, IndexType.DOC_VALUES_ONLY, isStored, meta);
}

@Override
public boolean isSearchable() {
return false;
}

@Override
Expand All @@ -79,7 +85,7 @@ public String typeName() {
@Override
public IndexFieldData.Builder fielddataBuilder(FieldDataContext fieldDataContext) {
failIfNoDocValues();
return new SortedNumericIndexFieldData.Builder(name(), NumericType.LONG, Murmur3DocValueField::new, isIndexed());
return new SortedNumericIndexFieldData.Builder(name(), NumericType.LONG, Murmur3DocValueField::new, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.index.mapper.DocValueFetcher;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.IndexType;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType;
Expand Down Expand Up @@ -50,7 +51,7 @@ public SizeFieldMapper build() {

private static class SizeFieldType extends NumberFieldType {
SizeFieldType() {
super(NAME, NumberType.INTEGER, true, true, true, false, null, Collections.emptyMap(), null, false, null, null, false);
super(NAME, NumberType.INTEGER, IndexType.POINTS, true, false, null, Collections.emptyMap(), null, false, null, null, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,13 @@ public abstract static class AbstractGeometryFieldType<T> extends MappedFieldTyp

protected AbstractGeometryFieldType(
String name,
boolean indexed,
IndexType indexType,
boolean stored,
boolean hasDocValues,
Parser<T> geometryParser,
T nullValue,
Map<String, String> meta
) {
super(name, indexed, stored, hasDocValues, meta);
super(name, indexType, stored, meta);
this.nullValue = nullValue;
this.geometryParser = geometryParser;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ protected void parseAndConsumeFromObject(
public abstract static class AbstractPointFieldType<T extends SpatialPoint> extends AbstractGeometryFieldType<T> {
protected AbstractPointFieldType(
String name,
boolean indexed,
IndexType indexType,
boolean stored,
boolean hasDocValues,
Parser<T> geometryParser,
T nullValue,
Map<String, String> meta
) {
super(name, indexed, stored, hasDocValues, geometryParser, nullValue, meta);
super(name, indexType, stored, geometryParser, nullValue, meta);
}

@Override
Expand Down
Loading