Clean up DocValuesIndexFieldData (#56372) (#56684)

This commit is contained in:
Mark Tozzi 2020-05-14 12:42:37 -04:00 committed by GitHub
parent 044ee380e8
commit b718193a01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 363 additions and 249 deletions

View File

@ -54,7 +54,7 @@ import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.NumberFieldMapper.Defaults;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
@ -289,8 +289,9 @@ public class ScaledFloatFieldMapper extends FieldMapper {
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
final IndexNumericFieldData scaledValues = (IndexNumericFieldData) new DocValuesIndexFieldData.Builder()
.numericType(IndexNumericFieldData.NumericType.LONG)
final IndexNumericFieldData scaledValues = new SortedNumericIndexFieldData.Builder(
IndexNumericFieldData.NumericType.LONG
)
.build(indexSettings, fieldType, cache, breakerService, mapperService);
return new ScaledFloatIndexFieldData(scaledValues, scalingFactor);
}

View File

@ -24,7 +24,7 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.ParseContext;
@ -92,7 +92,7 @@ public class MetaJoinFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override

View File

@ -33,7 +33,7 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
@ -115,7 +115,7 @@ public final class ParentIdFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override

View File

@ -32,7 +32,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
@ -225,7 +225,7 @@ public final class ParentJoinFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override

View File

@ -38,7 +38,7 @@ import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.InnerHitBuilder;
@ -325,7 +325,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
Query childFilter = parentIdFieldMapper.getChildFilter(type);
Query innerQuery = Queries.filtered(query.toQuery(context), childFilter);
MappedFieldType fieldType = parentIdFieldMapper.fieldType();
final SortedSetDVOrdinalsIndexFieldData fieldData = context.getForField(fieldType);
final SortedSetOrdinalsIndexFieldData fieldData = context.getForField(fieldType);
return new LateParsingQuery(parentFilter, innerQuery, minChildren(), maxChildren(),
fieldType.name(), scoreMode, fieldData, context.getSearchSimilarity());
} else {
@ -356,12 +356,12 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
private final int maxChildren;
private final String joinField;
private final ScoreMode scoreMode;
private final SortedSetDVOrdinalsIndexFieldData fieldDataJoin;
private final SortedSetOrdinalsIndexFieldData fieldDataJoin;
private final Similarity similarity;
LateParsingQuery(Query toQuery, Query innerQuery, int minChildren, int maxChildren,
String joinField, ScoreMode scoreMode,
SortedSetDVOrdinalsIndexFieldData fieldData, Similarity similarity) {
SortedSetOrdinalsIndexFieldData fieldData, Similarity similarity) {
this.toQuery = toQuery;
this.innerQuery = innerQuery;
this.minChildren = minChildren;

View File

@ -29,7 +29,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.InnerHitBuilder;
@ -181,7 +181,7 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
Query innerQuery = Queries.filtered(query.toQuery(context), parentFilter);
Query childFilter = parentIdFieldMapper.getChildrenFilter();
MappedFieldType fieldType = parentIdFieldMapper.fieldType();
final SortedSetDVOrdinalsIndexFieldData fieldData = context.getForField(fieldType);
final SortedSetOrdinalsIndexFieldData fieldData = context.getForField(fieldType);
return new HasChildQueryBuilder.LateParsingQuery(childFilter, innerQuery,
HasChildQueryBuilder.DEFAULT_MIN_CHILDREN, HasChildQueryBuilder.DEFAULT_MAX_CHILDREN,
fieldType.name(), score ? ScoreMode.Max : ScoreMode.None, fieldData, context.getSearchSimilarity());

View File

@ -35,7 +35,7 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.plain.BytesBinaryDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.BytesBinaryIndexFieldData;
import org.elasticsearch.index.mapper.BinaryFieldMapper;
import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
@ -94,7 +94,7 @@ public class QueryBuilderStoreTests extends ESTestCase {
when(queryShardContext.getWriteableRegistry()).thenReturn(writableRegistry());
when(queryShardContext.getXContentRegistry()).thenReturn(xContentRegistry());
when(queryShardContext.getForField(fieldMapper.fieldType()))
.thenReturn(new BytesBinaryDVIndexFieldData(new Index("index", "uuid"), fieldMapper.name()));
.thenReturn(new BytesBinaryIndexFieldData(new Index("index", "uuid"), fieldMapper.name()));
when(queryShardContext.fieldMapper(Mockito.anyString())).thenAnswer(invocation -> {
final String fieldName = (String) invocation.getArguments()[0];
KeywordFieldMapper.KeywordFieldType ft = new KeywordFieldMapper.KeywordFieldType();

View File

@ -23,6 +23,7 @@ import com.ibm.icu.text.Collator;
import com.ibm.icu.text.RawCollationKey;
import com.ibm.icu.text.RuleBasedCollator;
import com.ibm.icu.util.ULocale;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexOptions;
@ -42,7 +43,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.analysis.IndexableBinaryStringTools;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
@ -137,7 +138,7 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override

View File

@ -29,7 +29,7 @@ import org.elasticsearch.common.hash.MurmurHash3;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
@ -121,7 +121,7 @@ public class Murmur3FieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder().numericType(NumericType.LONG);
return new SortedNumericIndexFieldData.Builder(NumericType.LONG);
}
@Override

View File

@ -21,14 +21,31 @@ package org.elasticsearch.index.fielddata;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
/**
* Specialization of {@link IndexFieldData} for histograms.
*/
public abstract class IndexHistogramFieldData extends DocValuesIndexFieldData implements IndexFieldData<LeafHistogramFieldData> {
public abstract class IndexHistogramFieldData implements IndexFieldData<LeafHistogramFieldData> {
protected final Index index;
protected final String fieldName;
public IndexHistogramFieldData(Index index, String fieldName) {
super(index, fieldName);
this.index = index;
this.fieldName = fieldName;
}
@Override
public final String getFieldName() {
return fieldName;
}
@Override
public final void clear() {
// can't do
}
@Override
public final Index index() {
return index;
}
}

View File

@ -31,7 +31,7 @@ import org.elasticsearch.index.fielddata.LeafNumericFieldData;
import org.elasticsearch.index.fielddata.FieldData;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.sort.BucketedSort;
@ -69,8 +69,8 @@ public class LongValuesComparatorSource extends IndexFieldData.XFieldComparatorS
private SortedNumericDocValues loadDocValues(LeafReaderContext context) {
final LeafNumericFieldData data = indexFieldData.load(context);
SortedNumericDocValues values;
if (data instanceof SortedNumericDVIndexFieldData.NanoSecondFieldData) {
values = ((SortedNumericDVIndexFieldData.NanoSecondFieldData) data).getLongValuesAsNanos();
if (data instanceof SortedNumericIndexFieldData.NanoSecondFieldData) {
values = ((SortedNumericIndexFieldData.NanoSecondFieldData) data).getLongValuesAsNanos();
} else {
values = data.getLongValues();
}

View File

@ -28,11 +28,11 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.LeafGeoPointFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.LeafGeoPointFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
@ -41,10 +41,29 @@ import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.sort.BucketedSort;
import org.elasticsearch.search.sort.SortOrder;
public abstract class AbstractLatLonPointDVIndexFieldData extends DocValuesIndexFieldData
implements IndexGeoPointFieldData {
AbstractLatLonPointDVIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
public abstract class AbstractLatLonPointIndexFieldData implements IndexGeoPointFieldData {
protected final Index index;
protected final String fieldName;
AbstractLatLonPointIndexFieldData(Index index, String fieldName) {
this.index = index;
this.fieldName = fieldName;
}
@Override
public final String getFieldName() {
return fieldName;
}
@Override
public final void clear() {
// can't do
}
@Override
public final Index index() {
return index;
}
@Override
@ -59,8 +78,8 @@ public abstract class AbstractLatLonPointDVIndexFieldData extends DocValuesIndex
throw new IllegalArgumentException("can't sort on geo_point field without using specific sorting feature, like geo_distance");
}
public static class LatLonPointDVIndexFieldData extends AbstractLatLonPointDVIndexFieldData {
public LatLonPointDVIndexFieldData(Index index, String fieldName) {
public static class LatLonPointIndexFieldData extends AbstractLatLonPointIndexFieldData {
public LatLonPointIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
}
@ -96,7 +115,7 @@ public abstract class AbstractLatLonPointDVIndexFieldData extends DocValuesIndex
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
// ignore breaker
return new LatLonPointDVIndexFieldData(indexSettings.getIndex(), fieldType.name());
return new LatLonPointIndexFieldData(indexSettings.getIndex(), fieldType.name());
}
}
}

View File

@ -24,18 +24,55 @@ import org.apache.lucene.search.SortField;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.sort.BucketedSort;
import org.elasticsearch.search.sort.SortOrder;
public class BinaryDVIndexFieldData extends DocValuesIndexFieldData implements IndexFieldData<BinaryDVLeafFieldData> {
public class BinaryIndexFieldData implements IndexFieldData<BinaryDVLeafFieldData> {
public BinaryDVIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
public static class Builder implements IndexFieldData.Builder {
@Override
public BinaryIndexFieldData build(
IndexSettings indexSettings,
MappedFieldType fieldType,
IndexFieldDataCache cache,
CircuitBreakerService breakerService,
MapperService mapperService
) {
final String fieldName = fieldType.name();
return new BinaryIndexFieldData(indexSettings.getIndex(), fieldName);
}
}
protected final Index index;
protected final String fieldName;
public BinaryIndexFieldData(Index index, String fieldName) {
this.index = index;
this.fieldName = fieldName;
}
@Override
public final String getFieldName() {
return fieldName;
}
@Override
public final void clear() {
// can't do
}
@Override
public final Index index() {
return index;
}
@Override

View File

@ -39,10 +39,29 @@ import org.elasticsearch.search.sort.SortOrder;
import java.io.IOException;
public class BytesBinaryDVIndexFieldData extends DocValuesIndexFieldData implements IndexFieldData<BytesBinaryDVLeafFieldData> {
public class BytesBinaryIndexFieldData implements IndexFieldData<BytesBinaryDVLeafFieldData> {
public BytesBinaryDVIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
protected final Index index;
protected final String fieldName;
public BytesBinaryIndexFieldData(Index index, String fieldName) {
this.index = index;
this.fieldName = fieldName;
}
@Override
public final String getFieldName() {
return fieldName;
}
@Override
public final void clear() {
// can't do
}
@Override
public final Index index() {
return index;
}
@Override
@ -77,7 +96,7 @@ public class BytesBinaryDVIndexFieldData extends DocValuesIndexFieldData impleme
CircuitBreakerService breakerService, MapperService mapperService) {
// Ignore breaker
final String fieldName = fieldType.name();
return new BytesBinaryDVIndexFieldData(indexSettings.getIndex(), fieldName);
return new BytesBinaryIndexFieldData(indexSettings.getIndex(), fieldName);
}
}

View File

@ -1,109 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.fielddata.plain;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.SortedSetDocValues;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.mapper.IdFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.RangeType;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import java.util.Set;
import java.util.function.Function;
import static java.util.Collections.unmodifiableSet;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
/** {@link IndexFieldData} impl based on Lucene's doc values. Caching is done on the Lucene side. */
public abstract class DocValuesIndexFieldData {
protected final Index index;
protected final String fieldName;
public DocValuesIndexFieldData(Index index, String fieldName) {
super();
this.index = index;
this.fieldName = fieldName;
}
public final String getFieldName() {
return fieldName;
}
public final void clear() {
// can't do
}
public final void clear(IndexReader reader) {
// can't do
}
public final Index index() {
return index;
}
public static class Builder implements IndexFieldData.Builder {
private static final Set<String> BINARY_INDEX_FIELD_NAMES = unmodifiableSet(newHashSet(IdFieldMapper.NAME));
private NumericType numericType;
private Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction = AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION;
private RangeType rangeType;
public Builder numericType(NumericType type) {
this.numericType = type;
return this;
}
public Builder scriptFunction(Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction) {
this.scriptFunction = scriptFunction;
return this;
}
public Builder setRangeType(RangeType rangeType) {
this.rangeType = rangeType;
return this;
}
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
// Ignore Circuit Breaker
final String fieldName = fieldType.name();
if (BINARY_INDEX_FIELD_NAMES.contains(fieldName) || rangeType != null) {
assert numericType == null;
return new BinaryDVIndexFieldData(indexSettings.getIndex(), fieldName);
} else if (numericType != null) {
return new SortedNumericDVIndexFieldData(indexSettings.getIndex(), fieldName, numericType);
} else {
return new SortedSetDVOrdinalsIndexFieldData(indexSettings, cache, fieldName, breakerService, scriptFunction);
}
}
}
}

View File

@ -54,8 +54,8 @@ abstract class LeafLongFieldData implements LeafNumericFieldData {
case DATE:
return new ScriptDocValues.Dates(getLongValues(), false);
case DATE_NANOSECONDS:
assert this instanceof SortedNumericDVIndexFieldData.NanoSecondFieldData;
return new ScriptDocValues.Dates(((SortedNumericDVIndexFieldData.NanoSecondFieldData) this).getLongValuesAsNanos(), true);
assert this instanceof SortedNumericIndexFieldData.NanoSecondFieldData;
return new ScriptDocValues.Dates(((SortedNumericIndexFieldData.NanoSecondFieldData) this).getLongValuesAsNanos(), true);
case BOOLEAN:
return new ScriptDocValues.Booleans(getLongValues());
default:

View File

@ -35,16 +35,22 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.time.DateUtils;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.AbstractSortedNumericDocValues;
import org.elasticsearch.index.fielddata.LeafNumericFieldData;
import org.elasticsearch.index.fielddata.FieldData;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.LeafNumericFieldData;
import org.elasticsearch.index.fielddata.NumericDoubleValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
import org.elasticsearch.index.fielddata.fieldcomparator.FloatValuesComparatorSource;
import org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.sort.BucketedSort;
@ -53,21 +59,58 @@ import org.elasticsearch.search.sort.SortOrder;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.function.LongUnaryOperator;
/**
* FieldData backed by {@link LeafReader#getSortedNumericDocValues(String)}
* @see DocValuesType#SORTED_NUMERIC
*/
public class SortedNumericDVIndexFieldData extends DocValuesIndexFieldData implements IndexNumericFieldData {
private final NumericType numericType;
public class SortedNumericIndexFieldData implements IndexNumericFieldData {
public static class Builder implements IndexFieldData.Builder {
public SortedNumericDVIndexFieldData(Index index, String fieldNames, NumericType numericType) {
super(index, fieldNames);
if (numericType == null) {
throw new IllegalArgumentException("numericType must be non-null");
private final NumericType numericType;
public Builder(NumericType numericType) {
this.numericType = numericType;
}
this.numericType = numericType;
@Override
public SortedNumericIndexFieldData build(
IndexSettings indexSettings,
MappedFieldType fieldType,
IndexFieldDataCache cache,
CircuitBreakerService breakerService,
MapperService mapperService
) {
final String fieldName = fieldType.name();
return new SortedNumericIndexFieldData(indexSettings.getIndex(), fieldName, numericType);
}
}
private final NumericType numericType;
protected final Index index;
protected final String fieldName;
public SortedNumericIndexFieldData(Index index, String fieldName, NumericType numericType) {
this.index = index;
this.fieldName = fieldName;
this.numericType = Objects.requireNonNull(numericType);
}
@Override
public final String getFieldName() {
return fieldName;
}
@Override
public final void clear() {
// can't do
}
@Override
public final Index index() {
return index;
}
/**

View File

@ -34,12 +34,12 @@ import java.util.function.Function;
/**
* An {@link LeafFieldData} implementation that uses Lucene {@link SortedSetDocValues}.
*/
public final class SortedSetDVBytesLeafFieldData extends AbstractLeafOrdinalsFieldData {
public final class SortedSetBytesLeafFieldData extends AbstractLeafOrdinalsFieldData {
private final LeafReader reader;
private final String field;
SortedSetDVBytesLeafFieldData(LeafReader reader, String field, Function<SortedSetDocValues,
SortedSetBytesLeafFieldData(LeafReader reader, String field, Function<SortedSetDocValues,
ScriptDocValues<?>> scriptFunction) {
super(scriptFunction);
this.reader = reader;

View File

@ -31,15 +31,19 @@ import org.apache.lucene.search.SortedSetSortField;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData;
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.GlobalOrdinalsIndexFieldData;
import org.elasticsearch.index.fielddata.ordinals.GlobalOrdinalsBuilder;
import org.elasticsearch.index.fielddata.ordinals.GlobalOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
@ -49,23 +53,70 @@ import org.elasticsearch.search.sort.SortOrder;
import java.io.IOException;
import java.util.function.Function;
public class SortedSetDVOrdinalsIndexFieldData extends DocValuesIndexFieldData implements IndexOrdinalsFieldData {
public class SortedSetOrdinalsIndexFieldData implements IndexOrdinalsFieldData {
public static class Builder implements IndexFieldData.Builder {
private final Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction;
public Builder() {
this(AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
}
public Builder(Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction) {
this.scriptFunction = scriptFunction;
}
@Override
public SortedSetOrdinalsIndexFieldData build(
IndexSettings indexSettings,
MappedFieldType fieldType,
IndexFieldDataCache cache,
CircuitBreakerService breakerService,
MapperService mapperService
) {
final String fieldName = fieldType.name();
return new SortedSetOrdinalsIndexFieldData(indexSettings, cache, fieldName, breakerService, scriptFunction);
}
}
protected final Index index;
protected final String fieldName;
private final IndexSettings indexSettings;
private final IndexFieldDataCache cache;
private final CircuitBreakerService breakerService;
private final Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction;
private static final Logger logger = LogManager.getLogger(SortedSetDVOrdinalsIndexFieldData.class);
private static final Logger logger = LogManager.getLogger(SortedSetOrdinalsIndexFieldData.class);
public SortedSetDVOrdinalsIndexFieldData(IndexSettings indexSettings, IndexFieldDataCache cache, String fieldName,
CircuitBreakerService breakerService, Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction) {
super(indexSettings.getIndex(), fieldName);
public SortedSetOrdinalsIndexFieldData(
IndexSettings indexSettings,
IndexFieldDataCache cache,
String fieldName,
CircuitBreakerService breakerService,
Function<SortedSetDocValues, ScriptDocValues<?>> scriptFunction
) {
this.index = indexSettings.getIndex();
this.fieldName = fieldName;
this.indexSettings = indexSettings;
this.cache = cache;
this.breakerService = breakerService;
this.scriptFunction = scriptFunction;
}
@Override
public final String getFieldName() {
return fieldName;
}
@Override
public final void clear() {
// can't do
}
@Override
public final Index index() {
return index;
}
@Override
public SortField sortField(@Nullable Object missingValue, MultiValueMode sortMode, Nested nested, boolean reverse) {
XFieldComparatorSource source = new BytesRefFieldComparatorSource(this, missingValue, sortMode, nested);
@ -93,7 +144,7 @@ public class SortedSetDVOrdinalsIndexFieldData extends DocValuesIndexFieldData i
@Override
public LeafOrdinalsFieldData load(LeafReaderContext context) {
return new SortedSetDVBytesLeafFieldData(context.reader(), fieldName, scriptFunction);
return new SortedSetBytesLeafFieldData(context.reader(), fieldName, scriptFunction);
}
@Override

View File

@ -35,7 +35,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.BytesBinaryDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.BytesBinaryIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.search.DocValueFormat;
@ -133,7 +133,7 @@ public class BinaryFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new BytesBinaryDVIndexFieldData.Builder();
return new BytesBinaryIndexFieldData.Builder();
}
@Override

View File

@ -36,7 +36,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
@ -186,7 +186,7 @@ public class BooleanFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder().numericType(NumericType.BOOLEAN);
return new SortedNumericIndexFieldData.Builder(NumericType.BOOLEAN);
}
@Override

View File

@ -49,7 +49,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.query.DateRangeIncludingNowQuery;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.index.query.QueryShardContext;
@ -546,7 +546,7 @@ public final class DateFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder().numericType(resolution.numericType());
return new SortedNumericIndexFieldData.Builder(resolution.numericType());
}
@Override

View File

@ -29,7 +29,7 @@ import org.elasticsearch.common.geo.GeoUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.AbstractLatLonPointDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.AbstractLatLonPointIndexFieldData;
import org.elasticsearch.index.query.VectorGeoPointShapeQueryProcessor;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
@ -192,7 +192,7 @@ public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<?
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new AbstractLatLonPointDVIndexFieldData.Builder();
return new AbstractLatLonPointIndexFieldData.Builder();
}
@Override

View File

@ -40,7 +40,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
@ -292,7 +292,7 @@ public class IpFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder().scriptFunction(IpScriptDocValues::new);
return new SortedSetOrdinalsIndexFieldData.Builder(IpScriptDocValues::new);
}
@Override

View File

@ -40,7 +40,7 @@ import org.elasticsearch.index.analysis.AnalyzerScope;
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
@ -270,7 +270,7 @@ public final class KeywordFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override

View File

@ -52,7 +52,7 @@ import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
@ -963,7 +963,7 @@ public class NumberFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder().numericType(type.numericType());
return new SortedNumericIndexFieldData.Builder(type.numericType());
}
@Override

View File

@ -42,7 +42,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.BinaryIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
@ -238,7 +238,7 @@ public class RangeFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder().setRangeType(rangeType);
return new BinaryIndexFieldData.Builder();
}
@Override

View File

@ -33,7 +33,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.seqno.SequenceNumbers;
@ -217,7 +217,7 @@ public class SeqNoFieldMapper extends MetadataFieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder().numericType(NumericType.LONG);
return new SortedNumericIndexFieldData.Builder(NumericType.LONG);
}
@Override

View File

@ -30,7 +30,7 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.SearchHit;
@ -133,7 +133,7 @@ public final class FetchDocValuesPhase implements FetchSubPhase {
// by default nanoseconds are cut to milliseconds within aggregations
// however for doc value fields we need the original nanosecond longs
if (isNanosecond) {
longValues = ((SortedNumericDVIndexFieldData.NanoSecondFieldData) data).getLongValuesAsNanos();
longValues = ((SortedNumericIndexFieldData.NanoSecondFieldData) data).getLongValuesAsNanos();
} else {
longValues = ((LeafNumericFieldData) data).getLongValues();
}

View File

@ -44,7 +44,7 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
@ -411,7 +411,7 @@ public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
throw new QueryShardException(context,
"[numeric_type] option cannot be set on a non-numeric field, got " + fieldType.typeName());
}
SortedNumericDVIndexFieldData numericFieldData = (SortedNumericDVIndexFieldData) fieldData;
SortedNumericIndexFieldData numericFieldData = (SortedNumericIndexFieldData) fieldData;
NumericType resolvedType = resolveNumericType(numericType);
field = numericFieldData.sortField(resolvedType, missing, localSortMode(), nested, reverse);
} else {
@ -487,7 +487,7 @@ public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
throw new QueryShardException(context, "we only support AVG, MEDIAN and SUM on number based fields");
}
if (numericType != null) {
SortedNumericDVIndexFieldData numericFieldData = (SortedNumericDVIndexFieldData) fieldData;
SortedNumericIndexFieldData numericFieldData = (SortedNumericIndexFieldData) fieldData;
NumericType resolvedType = resolveNumericType(numericType);
return numericFieldData.newBucketedSort(resolvedType, context.bigArrays(), missing, localSortMode(), nested, order,
fieldType.docValueFormat(null, null), bucketSize, extra);

View File

@ -49,7 +49,7 @@ import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
import org.elasticsearch.index.fielddata.MultiGeoPointValues;
import org.elasticsearch.index.fielddata.NumericDoubleValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.fielddata.plain.AbstractLatLonPointDVIndexFieldData.LatLonPointDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.AbstractLatLonPointIndexFieldData.LatLonPointIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.GeoValidationMethod;
import org.elasticsearch.index.query.QueryBuilder;
@ -584,7 +584,7 @@ public class GeoDistanceSortBuilder extends SortBuilder<GeoDistanceSortBuilder>
IndexGeoPointFieldData geoIndexFieldData = fieldData(context);
Nested nested = nested(context);
if (geoIndexFieldData.getClass() == LatLonPointDVIndexFieldData.class // only works with 5.x geo_point
if (geoIndexFieldData.getClass() == LatLonPointIndexFieldData.class // only works with 5.x geo_point
&& nested == null
&& localSortMode == MultiValueMode.MIN // LatLonDocValuesField internally picks the closest point
&& unit == DistanceUnit.METERS

View File

@ -37,7 +37,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.plain.AbstractLeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
@ -69,11 +69,11 @@ public class FieldDataCacheTests extends ESTestCase {
ElasticsearchDirectoryReader.wrap(DirectoryReader.open(dir), new ShardId("_index", "_na_", 0));
DummyAccountingFieldDataCache fieldDataCache = new DummyAccountingFieldDataCache();
// Testing SortedSetDVOrdinalsIndexFieldData:
SortedSetDVOrdinalsIndexFieldData sortedSetDVOrdinalsIndexFieldData = createSortedDV("field1", fieldDataCache);
sortedSetDVOrdinalsIndexFieldData.loadGlobal(ir);
// Testing SortedSetOrdinalsIndexFieldData:
SortedSetOrdinalsIndexFieldData sortedSetOrdinalsIndexFieldData = createSortedDV("field1", fieldDataCache);
sortedSetOrdinalsIndexFieldData.loadGlobal(ir);
assertThat(fieldDataCache.cachedGlobally, equalTo(1));
sortedSetDVOrdinalsIndexFieldData.loadGlobal(new FieldMaskingReader("field1", ir));
sortedSetOrdinalsIndexFieldData.loadGlobal(new FieldMaskingReader("field1", ir));
assertThat(fieldDataCache.cachedGlobally, equalTo(1));
// Testing PagedBytesIndexFieldData
@ -87,8 +87,8 @@ public class FieldDataCacheTests extends ESTestCase {
dir.close();
}
private SortedSetDVOrdinalsIndexFieldData createSortedDV(String fieldName, IndexFieldDataCache indexFieldDataCache) {
return new SortedSetDVOrdinalsIndexFieldData(createIndexSettings(), indexFieldDataCache, fieldName, new NoneCircuitBreakerService(),
private SortedSetOrdinalsIndexFieldData createSortedDV(String fieldName, IndexFieldDataCache indexFieldDataCache) {
return new SortedSetOrdinalsIndexFieldData(createIndexSettings(), indexFieldDataCache, fieldName, new NoneCircuitBreakerService(),
AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
}

View File

@ -33,8 +33,8 @@ import org.apache.lucene.util.Accountable;
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.BooleanFieldMapper;
import org.elasticsearch.index.mapper.ContentPath;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
@ -74,7 +74,7 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase {
final MappedFieldType stringMapper = new KeywordFieldMapper.Builder("string").build(ctx).fieldType();
ifdService.clear();
IndexFieldData<?> fd = ifdService.getForField(stringMapper);
assertTrue(fd instanceof SortedSetDVOrdinalsIndexFieldData);
assertTrue(fd instanceof SortedSetOrdinalsIndexFieldData);
for (MappedFieldType mapper : Arrays.asList(
new NumberFieldMapper.Builder("int", NumberFieldMapper.NumberType.BYTE).build(ctx).fieldType(),
@ -84,20 +84,20 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase {
)) {
ifdService.clear();
fd = ifdService.getForField(mapper);
assertTrue(fd instanceof SortedNumericDVIndexFieldData);
assertTrue(fd instanceof SortedNumericIndexFieldData);
}
final MappedFieldType floatMapper = new NumberFieldMapper.Builder("float", NumberFieldMapper.NumberType.FLOAT)
.build(ctx).fieldType();
ifdService.clear();
fd = ifdService.getForField(floatMapper);
assertTrue(fd instanceof SortedNumericDVIndexFieldData);
assertTrue(fd instanceof SortedNumericIndexFieldData);
final MappedFieldType doubleMapper = new NumberFieldMapper.Builder("double", NumberFieldMapper.NumberType.DOUBLE)
.build(ctx).fieldType();
ifdService.clear();
fd = ifdService.getForField(doubleMapper);
assertTrue(fd instanceof SortedNumericDVIndexFieldData);
assertTrue(fd instanceof SortedNumericIndexFieldData);
}
public void testClearField() throws Exception {

View File

@ -48,7 +48,7 @@ public class HalfFloatFielddataTests extends ESTestCase {
w.addDocument(doc);
final DirectoryReader dirReader = DirectoryReader.open(w);
LeafReader reader = getOnlyLeafReader(dirReader);
SortedNumericDoubleValues values = new SortedNumericDVIndexFieldData.SortedNumericHalfFloatFieldData(
SortedNumericDoubleValues values = new SortedNumericIndexFieldData.SortedNumericHalfFloatFieldData(
reader, "half_float").getDoubleValues();
assertNotNull(FieldData.unwrapSingleton(values));
assertTrue(values.advanceExact(0));
@ -70,7 +70,7 @@ public class HalfFloatFielddataTests extends ESTestCase {
w.addDocument(doc);
final DirectoryReader dirReader = DirectoryReader.open(w);
LeafReader reader = getOnlyLeafReader(dirReader);
SortedNumericDoubleValues values = new SortedNumericDVIndexFieldData.SortedNumericHalfFloatFieldData(
SortedNumericDoubleValues values = new SortedNumericIndexFieldData.SortedNumericHalfFloatFieldData(
reader, "half_float").getDoubleValues();
assertNull(FieldData.unwrapSingleton(values));
assertTrue(values.advanceExact(0));

View File

@ -43,7 +43,7 @@ import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.fielddata.LeafNumericFieldData;
import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType;
import org.elasticsearch.index.mapper.DateFieldMapper.Resolution;
@ -332,7 +332,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).build();
IndexSettings indexSettings = new IndexSettings(IndexMetadata.builder("foo").settings(settings).build(), settings);
SortedNumericDVIndexFieldData fieldData = new SortedNumericDVIndexFieldData(indexSettings.getIndex(), "my_date",
SortedNumericIndexFieldData fieldData = new SortedNumericIndexFieldData(indexSettings.getIndex(), "my_date",
IndexNumericFieldData.NumericType.DATE_NANOSECONDS);
// Read index and check the doc values
DirectoryReader reader = DirectoryReader.open(w);

View File

@ -36,7 +36,7 @@ import org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.NumberFieldMapper;
@ -191,7 +191,7 @@ public class DiversifiedSamplerTests extends AggregatorTestCase {
idFieldType.setName("id");
idFieldType.setHasDocValues(true);
SortedNumericDVIndexFieldData fieldData = new SortedNumericDVIndexFieldData(new Index("index", "index"), "price",
SortedNumericIndexFieldData fieldData = new SortedNumericIndexFieldData(new Index("index", "index"), "price",
IndexNumericFieldData.NumericType.DOUBLE);
FunctionScoreQuery query = new FunctionScoreQuery(new MatchAllDocsQuery(),
new FieldValueFactorFunction("price", 1, FieldValueFactorFunction.Modifier.RECIPROCAL, null, fieldData));

View File

@ -37,8 +37,7 @@ import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData;
import org.elasticsearch.index.fielddata.LeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.plain.AbstractLeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.DynamicKeyFieldMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
@ -460,7 +459,7 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
CircuitBreakerService breakerService,
MapperService mapperService) {
String fieldName = fieldType.name();
IndexOrdinalsFieldData delegate = new SortedSetDVOrdinalsIndexFieldData(indexSettings,
IndexOrdinalsFieldData delegate = new SortedSetOrdinalsIndexFieldData(indexSettings,
cache, fieldName, breakerService, AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
return new KeyedFlatObjectFieldData(key, delegate);
}
@ -537,7 +536,7 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new DocValuesIndexFieldData.Builder();
return new SortedSetOrdinalsIndexFieldData.Builder();
}
@Override

View File

@ -30,7 +30,7 @@ import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.IndexOrdinalsFieldData;
import org.elasticsearch.index.fielddata.plain.AbstractLeafOrdinalsFieldData;
import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
@ -45,7 +45,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo;
public class FieldDataCacheWithFieldSubsetReaderTests extends ESTestCase {
private SortedSetDVOrdinalsIndexFieldData sortedSetDVOrdinalsIndexFieldData;
private SortedSetOrdinalsIndexFieldData sortedSetOrdinalsIndexFieldData;
private PagedBytesIndexFieldData pagedBytesIndexFieldData;
private DirectoryReader ir;
@ -60,7 +60,7 @@ public class FieldDataCacheWithFieldSubsetReaderTests extends ESTestCase {
CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
String name = "_field";
indexFieldDataCache = new DummyAccountingFieldDataCache();
sortedSetDVOrdinalsIndexFieldData = new SortedSetDVOrdinalsIndexFieldData(indexSettings,indexFieldDataCache, name,
sortedSetOrdinalsIndexFieldData = new SortedSetOrdinalsIndexFieldData(indexSettings,indexFieldDataCache, name,
circuitBreakerService, AbstractLeafOrdinalsFieldData.DEFAULT_SCRIPT_FUNCTION);
pagedBytesIndexFieldData = new PagedBytesIndexFieldData(indexSettings, name, indexFieldDataCache,
circuitBreakerService, TextFieldMapper.Defaults.FIELDDATA_MIN_FREQUENCY,
@ -94,13 +94,13 @@ public class FieldDataCacheWithFieldSubsetReaderTests extends ESTestCase {
public void testSortedSetDVOrdinalsIndexFieldData_global() throws Exception {
assertThat(indexFieldDataCache.topLevelBuilds, equalTo(0));
IndexOrdinalsFieldData global = sortedSetDVOrdinalsIndexFieldData.loadGlobal(ir);
IndexOrdinalsFieldData global = sortedSetOrdinalsIndexFieldData.loadGlobal(ir);
LeafOrdinalsFieldData atomic = global.load(ir.leaves().get(0));
assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(numDocs));
assertThat(indexFieldDataCache.topLevelBuilds, equalTo(1));
DirectoryReader ir = FieldSubsetReader.wrap(this.ir, new CharacterRunAutomaton(Automata.makeEmpty()));
global = sortedSetDVOrdinalsIndexFieldData.loadGlobal(ir);
global = sortedSetOrdinalsIndexFieldData.loadGlobal(ir);
atomic = global.load(ir.leaves().get(0));
assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(0L));
assertThat(indexFieldDataCache.topLevelBuilds, equalTo(1));
@ -108,13 +108,13 @@ public class FieldDataCacheWithFieldSubsetReaderTests extends ESTestCase {
public void testSortedSetDVOrdinalsIndexFieldData_segment() throws Exception {
for (LeafReaderContext context : ir.leaves()) {
LeafOrdinalsFieldData atomic = sortedSetDVOrdinalsIndexFieldData.load(context);
LeafOrdinalsFieldData atomic = sortedSetOrdinalsIndexFieldData.load(context);
assertThat(atomic.getOrdinalsValues().getValueCount(), greaterThanOrEqualTo(1L));
}
DirectoryReader ir = FieldSubsetReader.wrap(this.ir, new CharacterRunAutomaton(Automata.makeEmpty()));
for (LeafReaderContext context : ir.leaves()) {
LeafOrdinalsFieldData atomic = sortedSetDVOrdinalsIndexFieldData.load(context);
LeafOrdinalsFieldData atomic = sortedSetOrdinalsIndexFieldData.load(context);
assertThat(atomic.getOrdinalsValues().getValueCount(), equalTo(0L));
}
// dv based field data doesn't use index field data cache, so in the end noting should have been added

View File

@ -17,7 +17,6 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
@ -26,9 +25,28 @@ import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.sort.BucketedSort;
import org.elasticsearch.search.sort.SortOrder;
public abstract class AbstractLatLonShapeDVIndexFieldData extends DocValuesIndexFieldData implements IndexGeoShapeFieldData {
AbstractLatLonShapeDVIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
public abstract class AbstractLatLonShapeIndexFieldData implements IndexGeoShapeFieldData {
protected final Index index;
protected final String fieldName;
AbstractLatLonShapeIndexFieldData(Index index, String fieldName) {
this.index = index;
this.fieldName = fieldName;
}
@Override
public final String getFieldName() {
return fieldName;
}
@Override
public final void clear() {
// can't do
}
@Override
public final Index index() {
return index;
}
@Override
@ -37,8 +55,8 @@ public abstract class AbstractLatLonShapeDVIndexFieldData extends DocValuesIndex
throw new IllegalArgumentException("can't sort on geo_shape field without using specific sorting feature, like geo_distance");
}
public static class LatLonShapeDVIndexFieldData extends AbstractLatLonShapeDVIndexFieldData {
public LatLonShapeDVIndexFieldData(Index index, String fieldName) {
public static class LatLonShapeIndexFieldData extends AbstractLatLonShapeIndexFieldData {
public LatLonShapeIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
}
@ -81,7 +99,7 @@ public abstract class AbstractLatLonShapeDVIndexFieldData extends DocValuesIndex
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
// ignore breaker
return new LatLonShapeDVIndexFieldData(indexSettings.getIndex(), fieldType.name());
return new LatLonShapeIndexFieldData(indexSettings.getIndex(), fieldType.name());
}
}
}

View File

@ -28,7 +28,7 @@ import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.TypeParsers;
import org.elasticsearch.index.query.VectorGeoShapeQueryProcessor;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.spatial.index.fielddata.AbstractLatLonShapeDVIndexFieldData;
import org.elasticsearch.xpack.spatial.index.fielddata.AbstractLatLonShapeIndexFieldData;
import org.elasticsearch.xpack.spatial.index.fielddata.CentroidCalculator;
import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType;
@ -146,7 +146,7 @@ public class GeoShapeWithDocValuesFieldMapper extends GeoShapeFieldMapper {
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
return new AbstractLatLonShapeDVIndexFieldData.Builder();
return new AbstractLatLonShapeIndexFieldData.Builder();
}
@Override

View File

@ -28,7 +28,7 @@ import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.vectors.query.VectorDVIndexFieldData;
import org.elasticsearch.xpack.vectors.query.VectorIndexFieldData;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -147,7 +147,7 @@ public class DenseVectorFieldMapper extends FieldMapper implements ArrayValueMap
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
return new VectorDVIndexFieldData.Builder(true);
return new VectorIndexFieldData.Builder(true);
}
@Override

View File

@ -25,7 +25,7 @@ import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.xpack.vectors.query.VectorDVIndexFieldData;
import org.elasticsearch.xpack.vectors.query.VectorIndexFieldData;
import java.io.IOException;
import java.time.ZoneId;
@ -117,7 +117,7 @@ public class SparseVectorFieldMapper extends FieldMapper {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
return new VectorDVIndexFieldData.Builder(false);
return new VectorIndexFieldData.Builder(false);
}
@Override

View File

@ -16,7 +16,6 @@ import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
@ -26,12 +25,31 @@ import org.elasticsearch.search.sort.BucketedSort;
import org.elasticsearch.search.sort.SortOrder;
public class VectorDVIndexFieldData extends DocValuesIndexFieldData implements IndexFieldData<VectorDVLeafFieldData> {
public class VectorIndexFieldData implements IndexFieldData<VectorDVLeafFieldData> {
protected final Index index;
protected final String fieldName;
private final boolean isDense;
public VectorDVIndexFieldData(Index index, String fieldName, boolean isDense) {
super(index, fieldName);
public VectorIndexFieldData(Index index, String fieldName, boolean isDense) {
this.isDense = isDense;
this.index = index;
this.fieldName = fieldName;
}
@Override
public final String getFieldName() {
return fieldName;
}
@Override
public final void clear() {
// can't do
}
@Override
public final Index index() {
return index;
}
@Override
@ -65,7 +83,7 @@ public class VectorDVIndexFieldData extends DocValuesIndexFieldData implements I
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
final String fieldName = fieldType.name();
return new VectorDVIndexFieldData(indexSettings.getIndex(), fieldName, isDense);
return new VectorIndexFieldData(indexSettings.getIndex(), fieldName, isDense);
}
}

View File

@ -44,7 +44,7 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
import org.elasticsearch.index.fielddata.plain.BytesBinaryDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.BytesBinaryIndexFieldData;
import org.elasticsearch.index.mapper.BinaryFieldMapper.CustomBinaryDocValuesField;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
@ -467,7 +467,7 @@ public class WildcardFieldMapper extends FieldMapper {
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
return new WildcardBytesBinaryDVIndexFieldData(indexSettings.getIndex(), fieldType.name());
return new WildcardBytesBinaryIndexFieldData(indexSettings.getIndex(), fieldType.name());
}};
}
@ -478,9 +478,9 @@ public class WildcardFieldMapper extends FieldMapper {
}
static class WildcardBytesBinaryDVIndexFieldData extends BytesBinaryDVIndexFieldData{
static class WildcardBytesBinaryIndexFieldData extends BytesBinaryIndexFieldData {
WildcardBytesBinaryDVIndexFieldData(Index index, String fieldName) {
WildcardBytesBinaryIndexFieldData(Index index, String fieldName) {
super(index, fieldName);
}