Make FieldMapper.copyTo() always non-null. (#25994)
Otherwise it is confusing that both a null copyTo and an empty copyTo should be treated the same.
This commit is contained in:
parent
58feb5efa0
commit
88d456989e
|
@ -473,9 +473,7 @@ final class DocumentParser {
|
|||
if (update != null) {
|
||||
context.addDynamicMapper(update);
|
||||
}
|
||||
if (fieldMapper.copyTo() != null) {
|
||||
parseCopyFields(context, fieldMapper.copyTo().copyToFields());
|
||||
}
|
||||
parseCopyFields(context, fieldMapper.copyTo().copyToFields());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ import java.util.Comparator;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public abstract class FieldMapper extends Mapper implements Cloneable {
|
||||
|
@ -60,7 +61,7 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
|
|||
protected boolean indexOptionsSet = false;
|
||||
protected boolean docValuesSet = false;
|
||||
protected final MultiFields.Builder multiFieldsBuilder;
|
||||
protected CopyTo copyTo;
|
||||
protected CopyTo copyTo = CopyTo.empty();
|
||||
|
||||
protected Builder(String name, MappedFieldType fieldType, MappedFieldType defaultFieldType) {
|
||||
super(name);
|
||||
|
@ -256,7 +257,7 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
|
|||
defaultFieldType.freeze();
|
||||
this.defaultFieldType = defaultFieldType;
|
||||
this.multiFields = multiFields;
|
||||
this.copyTo = copyTo;
|
||||
this.copyTo = Objects.requireNonNull(copyTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -407,10 +408,7 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
|
|||
}
|
||||
|
||||
multiFields.toXContent(builder, params);
|
||||
|
||||
if (copyTo != null) {
|
||||
copyTo.toXContent(builder, params);
|
||||
}
|
||||
copyTo.toXContent(builder, params);
|
||||
}
|
||||
|
||||
protected final void doXContentAnalyzers(XContentBuilder builder, boolean includeDefaults) throws IOException {
|
||||
|
@ -617,6 +615,12 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
|
|||
*/
|
||||
public static class CopyTo {
|
||||
|
||||
private static final CopyTo EMPTY = new CopyTo(Collections.emptyList());
|
||||
|
||||
public static CopyTo empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
private final List<String> copyToFields;
|
||||
|
||||
private CopyTo(List<String> copyToFields) {
|
||||
|
@ -643,6 +647,9 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
|
|||
}
|
||||
|
||||
public CopyTo build() {
|
||||
if (copyToBuilders.isEmpty()) {
|
||||
return EMPTY;
|
||||
}
|
||||
return new CopyTo(Collections.unmodifiableList(copyToBuilders));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public abstract class MetadataFieldMapper extends FieldMapper {
|
|||
}
|
||||
|
||||
protected MetadataFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Settings indexSettings) {
|
||||
super(simpleName, fieldType, defaultFieldType, indexSettings, MultiFields.empty(), null);
|
||||
super(simpleName, fieldType, defaultFieldType, indexSettings, MultiFields.empty(), CopyTo.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -95,7 +95,7 @@ public class DocumentFieldMapperTests extends LuceneTestCase {
|
|||
private static final Settings SETTINGS = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
|
||||
|
||||
FakeFieldMapper(String simpleName, MappedFieldType fieldType) {
|
||||
super(simpleName, fieldType.clone(), fieldType.clone(), SETTINGS, null, null);
|
||||
super(simpleName, fieldType.clone(), fieldType.clone(), SETTINGS, MultiFields.empty(), CopyTo.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -108,7 +108,7 @@ public class MetaJoinFieldMapper extends FieldMapper {
|
|||
}
|
||||
|
||||
MetaJoinFieldMapper(String name, MappedFieldType fieldType, Settings indexSettings) {
|
||||
super(name, fieldType, ParentIdFieldMapper.Defaults.FIELD_TYPE, indexSettings, MultiFields.empty(), null);
|
||||
super(name, fieldType, ParentIdFieldMapper.Defaults.FIELD_TYPE, indexSettings, MultiFields.empty(), CopyTo.empty());
|
||||
}
|
||||
|
||||
void setFieldMapper(ParentJoinFieldMapper mapper) {
|
||||
|
|
|
@ -134,7 +134,7 @@ public final class ParentIdFieldMapper extends FieldMapper {
|
|||
Set<String> children,
|
||||
MappedFieldType fieldType,
|
||||
Settings indexSettings) {
|
||||
super(simpleName, fieldType, Defaults.FIELD_TYPE, indexSettings, MultiFields.empty(), null);
|
||||
super(simpleName, fieldType, Defaults.FIELD_TYPE, indexSettings, MultiFields.empty(), CopyTo.empty());
|
||||
this.parentName = parentName;
|
||||
this.children = children;
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ public final class ParentJoinFieldMapper extends FieldMapper {
|
|||
MetaJoinFieldMapper uniqueFieldMapper,
|
||||
List<ParentIdFieldMapper> parentIdFields,
|
||||
boolean eagerGlobalOrdinals) {
|
||||
super(simpleName, fieldType, Defaults.FIELD_TYPE, indexSettings, MultiFields.empty(), null);
|
||||
super(simpleName, fieldType, Defaults.FIELD_TYPE, indexSettings, MultiFields.empty(), CopyTo.empty());
|
||||
this.parentIdFields = parentIdFields;
|
||||
this.uniqueFieldMapper = uniqueFieldMapper;
|
||||
this.uniqueFieldMapper.setFieldMapper(this);
|
||||
|
|
Loading…
Reference in New Issue