|
@@ -28,7 +28,6 @@ import org.elasticsearch.index.fielddata.AtomicFieldData;
|
|
|
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
|
|
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
|
|
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
|
|
|
-import org.elasticsearch.index.fielddata.ScriptDocValues;
|
|
|
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
|
|
|
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
|
|
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
|
@@ -46,7 +45,6 @@ import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Query sub phase which pulls data from doc values
|
|
@@ -55,7 +53,8 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
public final class DocValueFieldsFetchSubPhase implements FetchSubPhase {
|
|
|
|
|
|
- private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
|
|
|
+ private static final String USE_DEFAULT_FORMAT = "use_field_mapping";
|
|
|
+ private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(
|
|
|
LogManager.getLogger(DocValueFieldsFetchSubPhase.class));
|
|
|
|
|
|
@Override
|
|
@@ -66,9 +65,9 @@ public final class DocValueFieldsFetchSubPhase implements FetchSubPhase {
|
|
|
String name = context.collapse().getFieldName();
|
|
|
if (context.docValueFieldsContext() == null) {
|
|
|
context.docValueFieldsContext(new DocValueFieldsContext(
|
|
|
- Collections.singletonList(new FieldAndFormat(name, DocValueFieldsContext.USE_DEFAULT_FORMAT))));
|
|
|
+ Collections.singletonList(new FieldAndFormat(name, null))));
|
|
|
} else if (context.docValueFieldsContext().fields().stream().map(ff -> ff.field).anyMatch(name::equals) == false) {
|
|
|
- context.docValueFieldsContext().fields().add(new FieldAndFormat(name, DocValueFieldsContext.USE_DEFAULT_FORMAT));
|
|
|
+ context.docValueFieldsContext().fields().add(new FieldAndFormat(name, null));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -79,13 +78,13 @@ public final class DocValueFieldsFetchSubPhase implements FetchSubPhase {
|
|
|
hits = hits.clone(); // don't modify the incoming hits
|
|
|
Arrays.sort(hits, Comparator.comparingInt(SearchHit::docId));
|
|
|
|
|
|
- List<String> noFormatFields = context.docValueFieldsContext().fields().stream().filter(f -> f.format == null).map(f -> f.field)
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (noFormatFields.isEmpty() == false) {
|
|
|
- deprecationLogger.deprecated("There are doc-value fields which are not using a format. The output will "
|
|
|
- + "change in 7.0 when doc value fields get formatted based on mappings by default. It is recommended to pass "
|
|
|
- + "[format={}] with a doc value field in order to opt in for the future behaviour and ease the migration to "
|
|
|
- + "7.0: {}", DocValueFieldsContext.USE_DEFAULT_FORMAT, noFormatFields);
|
|
|
+ if (context.docValueFieldsContext().fields().stream()
|
|
|
+ .map(f -> f.format)
|
|
|
+ .filter(USE_DEFAULT_FORMAT::equals)
|
|
|
+ .findAny()
|
|
|
+ .isPresent()) {
|
|
|
+ DEPRECATION_LOGGER.deprecated("[" + USE_DEFAULT_FORMAT + "] is a special format that was only used to " +
|
|
|
+ "ease the transition to 7.x. It has become the default and shouldn't be set explicitly anymore.");
|
|
|
}
|
|
|
|
|
|
for (FieldAndFormat fieldAndFormat : context.docValueFieldsContext().fields()) {
|
|
@@ -93,19 +92,14 @@ public final class DocValueFieldsFetchSubPhase implements FetchSubPhase {
|
|
|
MappedFieldType fieldType = context.mapperService().fullName(field);
|
|
|
if (fieldType != null) {
|
|
|
final IndexFieldData<?> indexFieldData = context.getForField(fieldType);
|
|
|
- final DocValueFormat format;
|
|
|
- if (fieldAndFormat.format == null) {
|
|
|
- format = null;
|
|
|
- } else {
|
|
|
- String formatDesc = fieldAndFormat.format;
|
|
|
- if (Objects.equals(formatDesc, DocValueFieldsContext.USE_DEFAULT_FORMAT)) {
|
|
|
- formatDesc = null;
|
|
|
- }
|
|
|
- format = fieldType.docValueFormat(formatDesc, null);
|
|
|
+ String formatDesc = fieldAndFormat.format;
|
|
|
+ if (Objects.equals(formatDesc, USE_DEFAULT_FORMAT)) {
|
|
|
+ // TODO: Remove in 8.x
|
|
|
+ formatDesc = null;
|
|
|
}
|
|
|
+ final DocValueFormat format = fieldType.docValueFormat(formatDesc, null);
|
|
|
LeafReaderContext subReaderContext = null;
|
|
|
AtomicFieldData data = null;
|
|
|
- ScriptDocValues<?> scriptValues = null; // legacy
|
|
|
SortedBinaryDocValues binaryValues = null; // binary / string / ip fields
|
|
|
SortedNumericDocValues longValues = null; // int / date fields
|
|
|
SortedNumericDoubleValues doubleValues = null; // floating-point fields
|
|
@@ -115,9 +109,7 @@ public final class DocValueFieldsFetchSubPhase implements FetchSubPhase {
|
|
|
int readerIndex = ReaderUtil.subIndex(hit.docId(), context.searcher().getIndexReader().leaves());
|
|
|
subReaderContext = context.searcher().getIndexReader().leaves().get(readerIndex);
|
|
|
data = indexFieldData.load(subReaderContext);
|
|
|
- if (format == null) {
|
|
|
- scriptValues = data.getLegacyFieldValues();
|
|
|
- } else if (indexFieldData instanceof IndexNumericFieldData) {
|
|
|
+ if (indexFieldData instanceof IndexNumericFieldData) {
|
|
|
if (((IndexNumericFieldData) indexFieldData).getNumericType().isFloatingPoint()) {
|
|
|
doubleValues = ((AtomicNumericFieldData) data).getDoubleValues();
|
|
|
} else {
|
|
@@ -138,10 +130,7 @@ public final class DocValueFieldsFetchSubPhase implements FetchSubPhase {
|
|
|
final List<Object> values = hitField.getValues();
|
|
|
|
|
|
int subDocId = hit.docId() - subReaderContext.docBase;
|
|
|
- if (scriptValues != null) {
|
|
|
- scriptValues.setNextDocId(subDocId);
|
|
|
- values.addAll(scriptValues);
|
|
|
- } else if (binaryValues != null) {
|
|
|
+ if (binaryValues != null) {
|
|
|
if (binaryValues.advanceExact(subDocId)) {
|
|
|
for (int i = 0, count = binaryValues.docValueCount(); i < count; ++i) {
|
|
|
values.add(format.format(binaryValues.nextValue()));
|