Added better error message when field types are not the same
This commit is contained in:
parent
542c25e78d
commit
573c85251e
|
@ -107,9 +107,12 @@ class FieldTypeLookup implements Iterable<MappedFieldType> {
|
||||||
for (FieldMapper fieldMapper : newFieldMappers) {
|
for (FieldMapper fieldMapper : newFieldMappers) {
|
||||||
MappedFieldTypeReference ref = fullNameToFieldType.get(fieldMapper.fieldType().names().fullName());
|
MappedFieldTypeReference ref = fullNameToFieldType.get(fieldMapper.fieldType().names().fullName());
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
boolean strict = ref.getNumAssociatedMappers() > 1 && updateAllTypes == false;
|
|
||||||
List<String> conflicts = new ArrayList<>();
|
List<String> conflicts = new ArrayList<>();
|
||||||
|
ref.get().checkTypeName(fieldMapper.fieldType(), conflicts);
|
||||||
|
if (conflicts.isEmpty()) { // only check compat if they are the same type
|
||||||
|
boolean strict = ref.getNumAssociatedMappers() > 1 && updateAllTypes == false;
|
||||||
ref.get().checkCompatibility(fieldMapper.fieldType(), conflicts, strict);
|
ref.get().checkCompatibility(fieldMapper.fieldType(), conflicts, strict);
|
||||||
|
}
|
||||||
if (conflicts.isEmpty() == false) {
|
if (conflicts.isEmpty() == false) {
|
||||||
throw new IllegalArgumentException("Mapper for [" + fieldMapper.fieldType().names().fullName() + "] conflicts with existing mapping in other types" + conflicts.toString());
|
throw new IllegalArgumentException("Mapper for [" + fieldMapper.fieldType().names().fullName() + "] conflicts with existing mapping in other types" + conflicts.toString());
|
||||||
}
|
}
|
||||||
|
@ -118,9 +121,12 @@ class FieldTypeLookup implements Iterable<MappedFieldType> {
|
||||||
// field type for the index name must be compatible too
|
// field type for the index name must be compatible too
|
||||||
MappedFieldTypeReference indexNameRef = fullNameToFieldType.get(fieldMapper.fieldType().names().indexName());
|
MappedFieldTypeReference indexNameRef = fullNameToFieldType.get(fieldMapper.fieldType().names().indexName());
|
||||||
if (indexNameRef != null) {
|
if (indexNameRef != null) {
|
||||||
boolean strict = indexNameRef.getNumAssociatedMappers() > 1 && updateAllTypes == false;
|
|
||||||
List<String> conflicts = new ArrayList<>();
|
List<String> conflicts = new ArrayList<>();
|
||||||
|
ref.get().checkTypeName(fieldMapper.fieldType(), conflicts);
|
||||||
|
if (conflicts.isEmpty()) { // only check compat if they are the same type
|
||||||
|
boolean strict = indexNameRef.getNumAssociatedMappers() > 1 && updateAllTypes == false;
|
||||||
indexNameRef.get().checkCompatibility(fieldMapper.fieldType(), conflicts, strict);
|
indexNameRef.get().checkCompatibility(fieldMapper.fieldType(), conflicts, strict);
|
||||||
|
}
|
||||||
if (conflicts.isEmpty() == false) {
|
if (conflicts.isEmpty() == false) {
|
||||||
throw new IllegalArgumentException("Mapper for [" + fieldMapper.fieldType().names().fullName() + "] conflicts with mapping with the same index name in other types" + conflicts.toString());
|
throw new IllegalArgumentException("Mapper for [" + fieldMapper.fieldType().names().fullName() + "] conflicts with mapping with the same index name in other types" + conflicts.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ import java.util.Objects;
|
||||||
/**
|
/**
|
||||||
* This defines the core properties and functions to operate on a field.
|
* This defines the core properties and functions to operate on a field.
|
||||||
*/
|
*/
|
||||||
public class MappedFieldType extends FieldType {
|
public abstract class MappedFieldType extends FieldType {
|
||||||
|
|
||||||
public static class Names {
|
public static class Names {
|
||||||
|
|
||||||
|
@ -194,12 +194,17 @@ public class MappedFieldType extends FieldType {
|
||||||
this.nullValueAsString = ref.nullValueAsString();
|
this.nullValueAsString = ref.nullValueAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MappedFieldType() {}
|
public MappedFieldType() {
|
||||||
|
setTokenized(true);
|
||||||
public MappedFieldType clone() {
|
setStored(false);
|
||||||
return new MappedFieldType(this);
|
setStoreTermVectors(false);
|
||||||
|
setOmitNorms(false);
|
||||||
|
setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
|
||||||
|
setBoost(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract MappedFieldType clone();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!super.equals(o)) return false;
|
if (!super.equals(o)) return false;
|
||||||
|
@ -224,6 +229,18 @@ public class MappedFieldType extends FieldType {
|
||||||
|
|
||||||
// norelease: we need to override freeze() and add safety checks that all settings are actually set
|
// norelease: we need to override freeze() and add safety checks that all settings are actually set
|
||||||
|
|
||||||
|
/** Returns the name of this type, as would be specified in mapping properties */
|
||||||
|
public abstract String typeName();
|
||||||
|
|
||||||
|
/** Checks this type is the same type as other. Adds a conflict if they are different. */
|
||||||
|
public final void checkTypeName(MappedFieldType other, List<String> conflicts) {
|
||||||
|
if (typeName().equals(other.typeName()) == false) {
|
||||||
|
conflicts.add("mapper [" + names().fullName() + "] cannot be changed from type [" + typeName() + "] to [" + other.typeName() + "]");
|
||||||
|
} else if (getClass() != other.getClass()) {
|
||||||
|
throw new IllegalStateException("Type names equal for class " + getClass().getSimpleName() + " and " + other.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for any conflicts between this field type and other.
|
* Checks for any conflicts between this field type and other.
|
||||||
* If strict is true, all properties must be equal.
|
* If strict is true, all properties must be equal.
|
||||||
|
@ -240,7 +257,7 @@ public class MappedFieldType extends FieldType {
|
||||||
conflicts.add("mapper [" + names().fullName() + "] has different store values");
|
conflicts.add("mapper [" + names().fullName() + "] has different store values");
|
||||||
}
|
}
|
||||||
if (hasDocValues() == false && other.hasDocValues()) {
|
if (hasDocValues() == false && other.hasDocValues()) {
|
||||||
// don't add conflict if this mapper has doc values while the mapper to merge doesn't since doc values are implicitely set
|
// don't add conflict if this mapper has doc values while the mapper to merge doesn't since doc values are implicitly set
|
||||||
// when the doc_values field data format is configured
|
// when the doc_values field data format is configured
|
||||||
conflicts.add("mapper [" + names().fullName() + "] has different doc_values values");
|
conflicts.add("mapper [" + names().fullName() + "] has different doc_values values");
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,18 +63,6 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.DOC_VALUES;
|
||||||
public abstract class AbstractFieldMapper implements FieldMapper {
|
public abstract class AbstractFieldMapper implements FieldMapper {
|
||||||
|
|
||||||
public static class Defaults {
|
public static class Defaults {
|
||||||
public static final MappedFieldType FIELD_TYPE = new MappedFieldType();
|
|
||||||
|
|
||||||
static {
|
|
||||||
FIELD_TYPE.setTokenized(true);
|
|
||||||
FIELD_TYPE.setStored(false);
|
|
||||||
FIELD_TYPE.setStoreTermVectors(false);
|
|
||||||
FIELD_TYPE.setOmitNorms(false);
|
|
||||||
FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
|
|
||||||
FIELD_TYPE.setBoost(Defaults.BOOST);
|
|
||||||
FIELD_TYPE.freeze();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final float BOOST = 1.0f;
|
public static final float BOOST = 1.0f;
|
||||||
public static final ContentPath.Type PATH_TYPE = ContentPath.Type.FULL;
|
public static final ContentPath.Type PATH_TYPE = ContentPath.Type.FULL;
|
||||||
}
|
}
|
||||||
|
@ -409,6 +397,14 @@ public abstract class AbstractFieldMapper implements FieldMapper {
|
||||||
}
|
}
|
||||||
AbstractFieldMapper fieldMergeWith = (AbstractFieldMapper) mergeWith;
|
AbstractFieldMapper fieldMergeWith = (AbstractFieldMapper) mergeWith;
|
||||||
List<String> subConflicts = new ArrayList<>(); // TODO: just expose list from MergeResult?
|
List<String> subConflicts = new ArrayList<>(); // TODO: just expose list from MergeResult?
|
||||||
|
fieldType().checkTypeName(fieldMergeWith.fieldType(), subConflicts);
|
||||||
|
if (subConflicts.isEmpty() == false) {
|
||||||
|
// return early if field types don't match
|
||||||
|
assert subConflicts.size() == 1;
|
||||||
|
mergeResult.addConflict(subConflicts.get(0));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
boolean strict = this.fieldTypeRef.getNumAssociatedMappers() > 1 && mergeResult.updateAllTypes() == false;
|
boolean strict = this.fieldTypeRef.getNumAssociatedMappers() > 1 && mergeResult.updateAllTypes() == false;
|
||||||
fieldType().checkCompatibility(fieldMergeWith.fieldType(), subConflicts, strict);
|
fieldType().checkCompatibility(fieldMergeWith.fieldType(), subConflicts, strict);
|
||||||
for (String conflict : subConflicts) {
|
for (String conflict : subConflicts) {
|
||||||
|
|
|
@ -109,9 +109,7 @@ public class BinaryFieldMapper extends AbstractFieldMapper {
|
||||||
static final class BinaryFieldType extends MappedFieldType {
|
static final class BinaryFieldType extends MappedFieldType {
|
||||||
private boolean tryUncompressing = false;
|
private boolean tryUncompressing = false;
|
||||||
|
|
||||||
public BinaryFieldType() {
|
public BinaryFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected BinaryFieldType(BinaryFieldType ref) {
|
protected BinaryFieldType(BinaryFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -135,6 +133,11 @@ public class BinaryFieldMapper extends AbstractFieldMapper {
|
||||||
return Objects.hash(super.hashCode(), tryUncompressing);
|
return Objects.hash(super.hashCode(), tryUncompressing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean tryUncompressing() {
|
public boolean tryUncompressing() {
|
||||||
return tryUncompressing;
|
return tryUncompressing;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,9 +118,7 @@ public class BooleanFieldMapper extends AbstractFieldMapper {
|
||||||
|
|
||||||
public static final class BooleanFieldType extends MappedFieldType {
|
public static final class BooleanFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public BooleanFieldType() {
|
public BooleanFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected BooleanFieldType(BooleanFieldType ref) {
|
protected BooleanFieldType(BooleanFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -131,6 +129,11 @@ public class BooleanFieldMapper extends AbstractFieldMapper {
|
||||||
return new BooleanFieldType(this);
|
return new BooleanFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean nullValue() {
|
public Boolean nullValue() {
|
||||||
return (Boolean)super.nullValue();
|
return (Boolean)super.nullValue();
|
||||||
|
|
|
@ -134,6 +134,11 @@ public class ByteFieldMapper extends NumberFieldMapper {
|
||||||
return new ByteFieldType(this);
|
return new ByteFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Byte nullValue() {
|
public Byte nullValue() {
|
||||||
return (Byte)super.nullValue();
|
return (Byte)super.nullValue();
|
||||||
|
|
|
@ -226,9 +226,7 @@ public class CompletionFieldMapper extends AbstractFieldMapper {
|
||||||
private AnalyzingCompletionLookupProvider analyzingSuggestLookupProvider;
|
private AnalyzingCompletionLookupProvider analyzingSuggestLookupProvider;
|
||||||
private SortedMap<String, ContextMapping> contextMapping = ContextMapping.EMPTY_MAPPING;
|
private SortedMap<String, ContextMapping> contextMapping = ContextMapping.EMPTY_MAPPING;
|
||||||
|
|
||||||
public CompletionFieldType() {
|
public CompletionFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CompletionFieldType(CompletionFieldType ref) {
|
protected CompletionFieldType(CompletionFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -242,6 +240,11 @@ public class CompletionFieldMapper extends AbstractFieldMapper {
|
||||||
return new CompletionFieldType(this);
|
return new CompletionFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) {
|
public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) {
|
||||||
super.checkCompatibility(fieldType, conflicts, strict);
|
super.checkCompatibility(fieldType, conflicts, strict);
|
||||||
|
|
|
@ -251,6 +251,11 @@ public class DateFieldMapper extends NumberFieldMapper {
|
||||||
return Objects.hash(super.hashCode(), dateTimeFormatter.format(), timeUnit);
|
return Objects.hash(super.hashCode(), dateTimeFormatter.format(), timeUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) {
|
public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) {
|
||||||
super.checkCompatibility(fieldType, conflicts, strict);
|
super.checkCompatibility(fieldType, conflicts, strict);
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class DoubleFieldMapper extends NumberFieldMapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class DoubleFieldType extends NumberFieldType {
|
public static final class DoubleFieldType extends NumberFieldType {
|
||||||
|
|
||||||
public DoubleFieldType() {
|
public DoubleFieldType() {
|
||||||
super(NumericType.DOUBLE);
|
super(NumericType.DOUBLE);
|
||||||
|
@ -141,6 +141,11 @@ public class DoubleFieldMapper extends NumberFieldMapper {
|
||||||
return new DoubleFieldType(this);
|
return new DoubleFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double nullValue() {
|
public Double nullValue() {
|
||||||
return (Double)super.nullValue();
|
return (Double)super.nullValue();
|
||||||
|
|
|
@ -142,6 +142,11 @@ public class FloatFieldMapper extends NumberFieldMapper {
|
||||||
return new FloatFieldType(this);
|
return new FloatFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Float nullValue() {
|
public Float nullValue() {
|
||||||
return (Float)super.nullValue();
|
return (Float)super.nullValue();
|
||||||
|
|
|
@ -143,6 +143,11 @@ public class IntegerFieldMapper extends NumberFieldMapper {
|
||||||
return new IntegerFieldType(this);
|
return new IntegerFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer nullValue() {
|
public Integer nullValue() {
|
||||||
return (Integer)super.nullValue();
|
return (Integer)super.nullValue();
|
||||||
|
|
|
@ -142,6 +142,11 @@ public class LongFieldMapper extends NumberFieldMapper {
|
||||||
return new LongFieldType(this);
|
return new LongFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long nullValue() {
|
public Long nullValue() {
|
||||||
return (Long)super.nullValue();
|
return (Long)super.nullValue();
|
||||||
|
|
|
@ -136,7 +136,6 @@ public abstract class NumberFieldMapper extends AbstractFieldMapper implements A
|
||||||
public static abstract class NumberFieldType extends MappedFieldType {
|
public static abstract class NumberFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public NumberFieldType(NumericType numericType) {
|
public NumberFieldType(NumericType numericType) {
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
setTokenized(false);
|
setTokenized(false);
|
||||||
setOmitNorms(true);
|
setOmitNorms(true);
|
||||||
setIndexOptions(IndexOptions.DOCS);
|
setIndexOptions(IndexOptions.DOCS);
|
||||||
|
|
|
@ -140,6 +140,11 @@ public class ShortFieldMapper extends NumberFieldMapper {
|
||||||
return new ShortFieldType(this);
|
return new ShortFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Short nullValue() {
|
public Short nullValue() {
|
||||||
return (Short)super.nullValue();
|
return (Short)super.nullValue();
|
||||||
|
|
|
@ -186,9 +186,7 @@ public class StringFieldMapper extends AbstractFieldMapper implements AllFieldMa
|
||||||
|
|
||||||
public static final class StringFieldType extends MappedFieldType {
|
public static final class StringFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public StringFieldType() {
|
public StringFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected StringFieldType(StringFieldType ref) {
|
protected StringFieldType(StringFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -198,6 +196,11 @@ public class StringFieldMapper extends AbstractFieldMapper implements AllFieldMa
|
||||||
return new StringFieldType(this);
|
return new StringFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String value(Object value) {
|
public String value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -287,9 +287,7 @@ public class GeoPointFieldMapper extends AbstractFieldMapper implements ArrayVal
|
||||||
private boolean normalizeLon = true;
|
private boolean normalizeLon = true;
|
||||||
private boolean normalizeLat = true;
|
private boolean normalizeLat = true;
|
||||||
|
|
||||||
public GeoPointFieldType() {
|
public GeoPointFieldType() {}
|
||||||
super(StringFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected GeoPointFieldType(GeoPointFieldType ref) {
|
protected GeoPointFieldType(GeoPointFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -329,6 +327,11 @@ public class GeoPointFieldMapper extends AbstractFieldMapper implements ArrayVal
|
||||||
return java.util.Objects.hash(super.hashCode(), geohashFieldType, geohashPrecision, geohashPrefixEnabled, latFieldType, lonFieldType, validateLon, validateLat, normalizeLon, normalizeLat);
|
return java.util.Objects.hash(super.hashCode(), geohashFieldType, geohashPrecision, geohashPrefixEnabled, latFieldType, lonFieldType, validateLon, validateLat, normalizeLon, normalizeLat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) {
|
public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) {
|
||||||
super.checkCompatibility(fieldType, conflicts, strict);
|
super.checkCompatibility(fieldType, conflicts, strict);
|
||||||
|
|
|
@ -183,9 +183,7 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper {
|
||||||
private RecursivePrefixTreeStrategy recursiveStrategy;
|
private RecursivePrefixTreeStrategy recursiveStrategy;
|
||||||
private TermQueryPrefixTreeStrategy termStrategy;
|
private TermQueryPrefixTreeStrategy termStrategy;
|
||||||
|
|
||||||
public GeoShapeFieldType() {
|
public GeoShapeFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected GeoShapeFieldType(GeoShapeFieldType ref) {
|
protected GeoShapeFieldType(GeoShapeFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -221,6 +219,11 @@ public class GeoShapeFieldMapper extends AbstractFieldMapper {
|
||||||
return Objects.hash(super.hashCode(), tree, strategyName, treeLevels, precisionInMeters, distanceErrorPct, defaultDistanceErrorPct, orientation);
|
return Objects.hash(super.hashCode(), tree, strategyName, treeLevels, precisionInMeters, distanceErrorPct, defaultDistanceErrorPct, orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void freeze() {
|
public void freeze() {
|
||||||
super.freeze();
|
super.freeze();
|
||||||
|
|
|
@ -156,9 +156,7 @@ public class AllFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||||
|
|
||||||
static final class AllFieldType extends MappedFieldType {
|
static final class AllFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public AllFieldType() {
|
public AllFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AllFieldType(AllFieldType ref) {
|
protected AllFieldType(AllFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -169,6 +167,11 @@ public class AllFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||||
return new AllFieldType(this);
|
return new AllFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String value(Object value) {
|
public String value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -137,15 +137,18 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMa
|
||||||
|
|
||||||
private boolean enabled = Defaults.ENABLED;
|
private boolean enabled = Defaults.ENABLED;
|
||||||
|
|
||||||
public FieldNamesFieldType() {
|
public FieldNamesFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected FieldNamesFieldType(FieldNamesFieldType ref) {
|
protected FieldNamesFieldType(FieldNamesFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
this.enabled = ref.enabled;
|
this.enabled = ref.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldNamesFieldType clone() {
|
||||||
|
return new FieldNamesFieldType(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!super.equals(o)) return false;
|
if (!super.equals(o)) return false;
|
||||||
|
@ -158,6 +161,11 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMa
|
||||||
return Objects.hash(super.hashCode(), enabled);
|
return Objects.hash(super.hashCode(), enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) {
|
public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) {
|
||||||
if (strict) {
|
if (strict) {
|
||||||
|
@ -177,11 +185,6 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMa
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public FieldNamesFieldType clone() {
|
|
||||||
return new FieldNamesFieldType(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String value(Object value) {
|
public String value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -136,9 +136,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||||
|
|
||||||
static final class IdFieldType extends MappedFieldType {
|
static final class IdFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public IdFieldType() {
|
public IdFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IdFieldType(IdFieldType ref) {
|
protected IdFieldType(IdFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -149,6 +147,10 @@ public class IdFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||||
return new IdFieldType(this);
|
return new IdFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String value(Object value) {
|
public String value(Object value) {
|
||||||
|
|
|
@ -120,9 +120,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||||
|
|
||||||
static final class IndexFieldType extends MappedFieldType {
|
static final class IndexFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public IndexFieldType() {
|
public IndexFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IndexFieldType(IndexFieldType ref) {
|
protected IndexFieldType(IndexFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -133,6 +131,11 @@ public class IndexFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||||
return new IndexFieldType(this);
|
return new IndexFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String value(Object value) {
|
public String value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -147,9 +147,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||||
|
|
||||||
static final class ParentFieldType extends MappedFieldType {
|
static final class ParentFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public ParentFieldType() {
|
public ParentFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ParentFieldType(ParentFieldType ref) {
|
protected ParentFieldType(ParentFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -160,6 +158,11 @@ public class ParentFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||||
return new ParentFieldType(this);
|
return new ParentFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uid value(Object value) {
|
public Uid value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -125,9 +125,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements RootMappe
|
||||||
|
|
||||||
static final class RoutingFieldType extends MappedFieldType {
|
static final class RoutingFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public RoutingFieldType() {
|
public RoutingFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected RoutingFieldType(RoutingFieldType ref) {
|
protected RoutingFieldType(RoutingFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -138,6 +136,11 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements RootMappe
|
||||||
return new RoutingFieldType(this);
|
return new RoutingFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String value(Object value) {
|
public String value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -200,9 +200,7 @@ public class SourceFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||||
|
|
||||||
static final class SourceFieldType extends MappedFieldType {
|
static final class SourceFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public SourceFieldType() {
|
public SourceFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected SourceFieldType(SourceFieldType ref) {
|
protected SourceFieldType(SourceFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -213,6 +211,11 @@ public class SourceFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||||
return new SourceFieldType(this);
|
return new SourceFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] value(Object value) {
|
public byte[] value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -106,9 +106,7 @@ public class TypeFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||||
|
|
||||||
static final class TypeFieldType extends MappedFieldType {
|
static final class TypeFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public TypeFieldType() {
|
public TypeFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TypeFieldType(TypeFieldType ref) {
|
protected TypeFieldType(TypeFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -119,6 +117,11 @@ public class TypeFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||||
return new TypeFieldType(this);
|
return new TypeFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String value(Object value) {
|
public String value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -107,9 +107,7 @@ public class UidFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||||
|
|
||||||
static final class UidFieldType extends MappedFieldType {
|
static final class UidFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public UidFieldType() {
|
public UidFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected UidFieldType(UidFieldType ref) {
|
protected UidFieldType(UidFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -120,6 +118,11 @@ public class UidFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||||
return new UidFieldType(this);
|
return new UidFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uid value(Object value) {
|
public Uid value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -90,9 +90,7 @@ public class VersionFieldMapper extends AbstractFieldMapper implements RootMappe
|
||||||
|
|
||||||
static final class VersionFieldType extends MappedFieldType {
|
static final class VersionFieldType extends MappedFieldType {
|
||||||
|
|
||||||
public VersionFieldType() {
|
public VersionFieldType() {}
|
||||||
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected VersionFieldType(VersionFieldType ref) {
|
protected VersionFieldType(VersionFieldType ref) {
|
||||||
super(ref);
|
super(ref);
|
||||||
|
@ -103,6 +101,11 @@ public class VersionFieldMapper extends AbstractFieldMapper implements RootMappe
|
||||||
return new VersionFieldType(this);
|
return new VersionFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long value(Object value) {
|
public Long value(Object value) {
|
||||||
if (value == null || (value instanceof Long)) {
|
if (value == null || (value instanceof Long)) {
|
||||||
|
|
|
@ -173,6 +173,11 @@ public class IpFieldMapper extends NumberFieldMapper {
|
||||||
return new IpFieldType(this);
|
return new IpFieldType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return CONTENT_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long value(Object value) {
|
public Long value(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -175,17 +175,31 @@ public class FieldTypeLookupTests extends ElasticsearchTestCase {
|
||||||
return Lists.newArrayList(mapper);
|
return Lists.newArrayList(mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this sucks how much must be overriden just do get a dummy field mapper...
|
// this sucks how much must be overridden just do get a dummy field mapper...
|
||||||
static class FakeFieldMapper extends AbstractFieldMapper {
|
static class FakeFieldMapper extends AbstractFieldMapper {
|
||||||
static Settings dummySettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id).build();
|
static Settings dummySettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id).build();
|
||||||
public FakeFieldMapper(String fullName, String indexName) {
|
public FakeFieldMapper(String fullName, String indexName) {
|
||||||
super(makeFieldType(fullName, indexName), null, null, dummySettings, null, null);
|
super(makeFieldType(fullName, indexName), null, null, dummySettings, null, null);
|
||||||
}
|
}
|
||||||
static MappedFieldType makeFieldType(String fullName, String indexName) {
|
static MappedFieldType makeFieldType(String fullName, String indexName) {
|
||||||
MappedFieldType fieldType = Defaults.FIELD_TYPE.clone();
|
FakeFieldType fieldType = new FakeFieldType();
|
||||||
fieldType.setNames(new MappedFieldType.Names(fullName, indexName, indexName, fullName));
|
fieldType.setNames(new MappedFieldType.Names(fullName, indexName, indexName, fullName));
|
||||||
return fieldType;
|
return fieldType;
|
||||||
}
|
}
|
||||||
|
static class FakeFieldType extends MappedFieldType {
|
||||||
|
public FakeFieldType() {}
|
||||||
|
protected FakeFieldType(FakeFieldType ref) {
|
||||||
|
super(ref);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public MappedFieldType clone() {
|
||||||
|
return new FakeFieldType(this);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return "faketype";
|
||||||
|
}
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public MappedFieldType defaultFieldType() { return null; }
|
public MappedFieldType defaultFieldType() { return null; }
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,12 +24,21 @@ import org.elasticsearch.index.fielddata.FieldDataType;
|
||||||
import org.elasticsearch.index.similarity.BM25SimilarityProvider;
|
import org.elasticsearch.index.similarity.BM25SimilarityProvider;
|
||||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** Base test case for subclasses of MappedFieldType */
|
/** Base test case for subclasses of MappedFieldType */
|
||||||
public abstract class FieldTypeTestCase extends ElasticsearchTestCase {
|
public abstract class FieldTypeTestCase extends ElasticsearchTestCase {
|
||||||
|
|
||||||
/** Create a default constructed fieldtype */
|
/** Create a default constructed fieldtype */
|
||||||
protected abstract MappedFieldType createDefaultFieldType();
|
protected abstract MappedFieldType createDefaultFieldType();
|
||||||
|
|
||||||
|
MappedFieldType createNamedDefaultFieldType(String name) {
|
||||||
|
MappedFieldType fieldType = createDefaultFieldType();
|
||||||
|
fieldType.setNames(new MappedFieldType.Names(name));
|
||||||
|
return fieldType;
|
||||||
|
}
|
||||||
|
|
||||||
/** A dummy null value to use when modifying null value */
|
/** A dummy null value to use when modifying null value */
|
||||||
protected Object dummyNullValue() {
|
protected Object dummyNullValue() {
|
||||||
return "dummyvalue";
|
return "dummyvalue";
|
||||||
|
@ -79,7 +88,7 @@ public abstract class FieldTypeTestCase extends ElasticsearchTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClone() {
|
public void testClone() {
|
||||||
MappedFieldType fieldType = createDefaultFieldType();
|
MappedFieldType fieldType = createNamedDefaultFieldType("foo");
|
||||||
MappedFieldType clone = fieldType.clone();
|
MappedFieldType clone = fieldType.clone();
|
||||||
assertNotSame(clone, fieldType);
|
assertNotSame(clone, fieldType);
|
||||||
assertEquals(clone.getClass(), fieldType.getClass());
|
assertEquals(clone.getClass(), fieldType.getClass());
|
||||||
|
@ -87,7 +96,7 @@ public abstract class FieldTypeTestCase extends ElasticsearchTestCase {
|
||||||
assertEquals(clone, clone.clone()); // transitivity
|
assertEquals(clone, clone.clone()); // transitivity
|
||||||
|
|
||||||
for (int i = 0; i < numProperties(); ++i) {
|
for (int i = 0; i < numProperties(); ++i) {
|
||||||
fieldType = createDefaultFieldType();
|
fieldType = createNamedDefaultFieldType("foo");
|
||||||
modifyProperty(fieldType, i);
|
modifyProperty(fieldType, i);
|
||||||
clone = fieldType.clone();
|
clone = fieldType.clone();
|
||||||
assertNotSame(clone, fieldType);
|
assertNotSame(clone, fieldType);
|
||||||
|
@ -96,15 +105,15 @@ public abstract class FieldTypeTestCase extends ElasticsearchTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
MappedFieldType ft1 = createDefaultFieldType();
|
MappedFieldType ft1 = createNamedDefaultFieldType("foo");
|
||||||
MappedFieldType ft2 = createDefaultFieldType();
|
MappedFieldType ft2 = createNamedDefaultFieldType("foo");
|
||||||
assertEquals(ft1, ft1); // reflexive
|
assertEquals(ft1, ft1); // reflexive
|
||||||
assertEquals(ft1, ft2); // symmetric
|
assertEquals(ft1, ft2); // symmetric
|
||||||
assertEquals(ft2, ft1);
|
assertEquals(ft2, ft1);
|
||||||
assertEquals(ft1.hashCode(), ft2.hashCode());
|
assertEquals(ft1.hashCode(), ft2.hashCode());
|
||||||
|
|
||||||
for (int i = 0; i < numProperties(); ++i) {
|
for (int i = 0; i < numProperties(); ++i) {
|
||||||
ft2 = createDefaultFieldType();
|
ft2 = createNamedDefaultFieldType("foo");
|
||||||
modifyProperty(ft2, i);
|
modifyProperty(ft2, i);
|
||||||
assertNotEquals(ft1, ft2);
|
assertNotEquals(ft1, ft2);
|
||||||
assertNotEquals(ft1.hashCode(), ft2.hashCode());
|
assertNotEquals(ft1.hashCode(), ft2.hashCode());
|
||||||
|
@ -113,7 +122,7 @@ public abstract class FieldTypeTestCase extends ElasticsearchTestCase {
|
||||||
|
|
||||||
public void testFreeze() {
|
public void testFreeze() {
|
||||||
for (int i = 0; i < numProperties(); ++i) {
|
for (int i = 0; i < numProperties(); ++i) {
|
||||||
MappedFieldType fieldType = createDefaultFieldType();
|
MappedFieldType fieldType = createNamedDefaultFieldType("foo");
|
||||||
fieldType.freeze();
|
fieldType.freeze();
|
||||||
try {
|
try {
|
||||||
modifyProperty(fieldType, i);
|
modifyProperty(fieldType, i);
|
||||||
|
@ -123,4 +132,36 @@ public abstract class FieldTypeTestCase extends ElasticsearchTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCheckTypeName() {
|
||||||
|
final MappedFieldType fieldType = createNamedDefaultFieldType("foo");
|
||||||
|
List<String> conflicts = new ArrayList<>();
|
||||||
|
fieldType.checkTypeName(fieldType, conflicts);
|
||||||
|
assertTrue(conflicts.toString(), conflicts.isEmpty());
|
||||||
|
|
||||||
|
MappedFieldType bogus = new MappedFieldType() {
|
||||||
|
@Override
|
||||||
|
public MappedFieldType clone() {return null;}
|
||||||
|
@Override
|
||||||
|
public String typeName() { return fieldType.typeName();}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
fieldType.checkTypeName(bogus, conflicts);
|
||||||
|
fail("expected bad types exception");
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
assertTrue(e.getMessage().contains("Type names equal"));
|
||||||
|
}
|
||||||
|
assertTrue(conflicts.toString(), conflicts.isEmpty());
|
||||||
|
|
||||||
|
MappedFieldType other = new MappedFieldType() {
|
||||||
|
@Override
|
||||||
|
public MappedFieldType clone() {return null;}
|
||||||
|
@Override
|
||||||
|
public String typeName() { return "othertype";}
|
||||||
|
};
|
||||||
|
fieldType.checkTypeName(other, conflicts);
|
||||||
|
assertFalse(conflicts.isEmpty());
|
||||||
|
assertTrue(conflicts.get(0).contains("cannot be changed from type"));
|
||||||
|
assertEquals(1, conflicts.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +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.mapper;
|
|
||||||
|
|
||||||
public class MappedFieldTypeTests extends FieldTypeTestCase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MappedFieldType createDefaultFieldType() {
|
|
||||||
return new MappedFieldType();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -80,7 +80,7 @@ public class ExternalMapper extends AbstractFieldMapper {
|
||||||
private String mapperName;
|
private String mapperName;
|
||||||
|
|
||||||
public Builder(String name, String generatedValue, String mapperName) {
|
public Builder(String name, String generatedValue, String mapperName) {
|
||||||
super(name, Defaults.FIELD_TYPE);
|
super(name, new ExternalFieldType());
|
||||||
this.builder = this;
|
this.builder = this;
|
||||||
this.stringBuilder = stringField(name).store(false);
|
this.stringBuilder = stringField(name).store(false);
|
||||||
this.generatedValue = generatedValue;
|
this.generatedValue = generatedValue;
|
||||||
|
@ -142,6 +142,25 @@ public class ExternalMapper extends AbstractFieldMapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ExternalFieldType extends MappedFieldType {
|
||||||
|
|
||||||
|
public ExternalFieldType() {}
|
||||||
|
|
||||||
|
protected ExternalFieldType(ExternalFieldType ref) {
|
||||||
|
super(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MappedFieldType clone() {
|
||||||
|
return new ExternalFieldType(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String typeName() {
|
||||||
|
return "faketype";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final String generatedValue;
|
private final String generatedValue;
|
||||||
private final String mapperName;
|
private final String mapperName;
|
||||||
|
|
||||||
|
@ -168,7 +187,7 @@ public class ExternalMapper extends AbstractFieldMapper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MappedFieldType defaultFieldType() {
|
public MappedFieldType defaultFieldType() {
|
||||||
return Defaults.FIELD_TYPE;
|
return new ExternalFieldType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,6 +20,8 @@ package org.elasticsearch.index.mapper.geo;
|
||||||
|
|
||||||
import org.elasticsearch.index.mapper.FieldTypeTestCase;
|
import org.elasticsearch.index.mapper.FieldTypeTestCase;
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
|
import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
|
||||||
|
import org.elasticsearch.index.mapper.core.StringFieldMapper;
|
||||||
|
|
||||||
public class GeoPointFieldTypeTests extends FieldTypeTestCase {
|
public class GeoPointFieldTypeTests extends FieldTypeTestCase {
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,8 +38,8 @@ public class GeoPointFieldTypeTests extends FieldTypeTestCase {
|
||||||
protected void modifyProperty(MappedFieldType ft, int propNum) {
|
protected void modifyProperty(MappedFieldType ft, int propNum) {
|
||||||
GeoPointFieldMapper.GeoPointFieldType gft = (GeoPointFieldMapper.GeoPointFieldType)ft;
|
GeoPointFieldMapper.GeoPointFieldType gft = (GeoPointFieldMapper.GeoPointFieldType)ft;
|
||||||
switch (propNum) {
|
switch (propNum) {
|
||||||
case 0: gft.setGeohashEnabled(new MappedFieldType(), 1, true); break;
|
case 0: gft.setGeohashEnabled(new StringFieldMapper.StringFieldType(), 1, true); break;
|
||||||
case 1: gft.setLatLonEnabled(new MappedFieldType(), new MappedFieldType()); break;
|
case 1: gft.setLatLonEnabled(new DoubleFieldMapper.DoubleFieldType(), new DoubleFieldMapper.DoubleFieldType()); break;
|
||||||
case 2: gft.setValidateLon(!gft.validateLon()); break;
|
case 2: gft.setValidateLon(!gft.validateLon()); break;
|
||||||
case 3: gft.setValidateLat(!gft.validateLat()); break;
|
case 3: gft.setValidateLat(!gft.validateLat()); break;
|
||||||
case 4: gft.setNormalizeLon(!gft.normalizeLon()); break;
|
case 4: gft.setNormalizeLon(!gft.normalizeLon()); break;
|
||||||
|
|
Loading…
Reference in New Issue