@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); }
/** * Checks if the given field type is compatible with an existing field type. * An IllegalArgumentException is thrown in case of incompatibility. * If updateAllTypes is true, only basic compatibility is checked. */ private void validateField(String type, MappedFieldType existingFieldType, MappedFieldType newFieldType, CopyOnWriteHashMap<String, String> aliasToConcreteName, boolean updateAllTypes) { String fieldName = newFieldType.name(); if (aliasToConcreteName.containsKey(fieldName)) { throw new IllegalArgumentException("The name for field [" + fieldName + "] has already" + " been used to define a field alias."); } if (existingFieldType != null) { List<String> conflicts = new ArrayList<>(); final Set<String> types = fullNameToTypes.get(newFieldType.name()); boolean strict = beStrict(type, types, updateAllTypes); existingFieldType.checkCompatibility(newFieldType, conflicts, strict); if (conflicts.isEmpty() == false) { throw new IllegalArgumentException("Mapper for [" + fieldName + "] conflicts with existing mapping in other types:\n" + conflicts.toString()); } } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); DateFieldType other = (DateFieldType) fieldType; if (Objects.equals(dateTimeFormatter().pattern(), other.dateTimeFormatter().pattern()) == false) { conflicts.add("mapper [" + name() + "] has different [format] values"); } if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { conflicts.add("mapper [" + name() + "] has different [locale] values"); } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); if (strict) { RangeFieldType other = (RangeFieldType)fieldType; if (this.rangeType != other.rangeType) { conflicts.add("mapper [" + name() + "] is attempting to update from type [" + rangeType.name + "] to incompatible type [" + other.rangeType.name + "]."); } if (this.rangeType == RangeType.DATE) { if (Objects.equals(dateTimeFormatter().pattern(), other.dateTimeFormatter().pattern()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [format] across all types."); } if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [locale] across all types."); } } } }
protected void assertCompatible(String msg, MappedFieldType ft1, MappedFieldType ft2, boolean strict) { List<String> conflicts = new ArrayList<>(); ft1.checkCompatibility(ft2, conflicts, strict); assertTrue("Found conflicts for " + msg + ": " + conflicts, conflicts.isEmpty()); }
protected void assertNotCompatible(String msg, MappedFieldType ft1, MappedFieldType ft2, boolean strict, String... messages) { assert messages.length != 0; List<String> conflicts = new ArrayList<>(); ft1.checkCompatibility(ft2, conflicts, strict); for (String message : messages) { boolean found = false; for (String conflict : conflicts) { if (conflict.contains(message)) { found = true; } } assertTrue("Missing conflict for " + msg + ": [" + message + "] in conflicts " + conflicts, found); } }
@Override public void checkCompatibility(MappedFieldType other, List<String> conflicts, boolean strict) { super.checkCompatibility(other, conflicts, strict); if (scalingFactor != ((ScaledFloatFieldType) other).getScalingFactor()) { conflicts.add("mapper [" + name() + "] has different [scaling_factor] values"); } }
@Override protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { super.doMerge(mergeWith, updateAllTypes); ParentFieldMapper fieldMergeWith = (ParentFieldMapper) mergeWith; if (Objects.equals(parentType, fieldMergeWith.parentType) == false) { throw new IllegalArgumentException("The _parent field's type option can't be changed: [" + parentType + "]->[" + fieldMergeWith.parentType + "]"); } List<String> conflicts = new ArrayList<>(); fieldType().checkCompatibility(fieldMergeWith.fieldType, conflicts, true); if (conflicts.isEmpty() == false) { throw new IllegalArgumentException("Merge conflicts: " + conflicts); } if (active()) { fieldType = fieldMergeWith.fieldType.clone(); } }
@Override public void checkCompatibility(MappedFieldType other, List<String> conflicts, boolean strict) { super.checkCompatibility(other, conflicts, strict); if (numericPrecisionStep() != other.numericPrecisionStep()) { conflicts.add("mapper [" + names().fullName() + "] has different [precision_step] values"); } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); BinaryFieldType other = (BinaryFieldType)fieldType; if (tryUncompressing() != other.tryUncompressing()) { conflicts.add("mapper [" + names().fullName() + "] has different [try_uncompressing] (IMPOSSIBLE)"); } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); if (strict) { FieldNamesFieldType other = (FieldNamesFieldType)fieldType; if (isEnabled() != other.isEnabled()) { conflicts.add("mapper [" + names().fullName() + "] is used by multiple types. Set update_all_types to true to update [enabled] across all types."); } } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); DateFieldType other = (DateFieldType) fieldType; if (Objects.equals(dateTimeFormatter().format(), other.dateTimeFormatter().format()) == false) { conflicts.add("mapper [" + name() + "] has different [format] values"); } if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { conflicts.add("mapper [" + name() + "] has different [locale] values"); } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); DateFieldType other = (DateFieldType) fieldType; if (Objects.equals(dateTimeFormatter().format(), other.dateTimeFormatter().format()) == false) { conflicts.add("mapper [" + name() + "] has different [format] values"); } if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { conflicts.add("mapper [" + name() + "] has different [locale] values"); } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); if (strict) { DateFieldType other = (DateFieldType)fieldType; if (Objects.equals(dateTimeFormatter().format(), other.dateTimeFormatter().format()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [format] across all types."); } if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [locale] across all types."); } } }
/** * Checks if the given field type is compatible with an existing field type. * An IllegalArgumentException is thrown in case of incompatibility. * If updateAllTypes is true, only basic compatibility is checked. */ private void checkCompatibility(String type, FieldMapper fieldMapper, boolean updateAllTypes) { MappedFieldType fieldType = fullNameToFieldType.get(fieldMapper.fieldType().name()); if (fieldType != null) { List<String> conflicts = new ArrayList<>(); final Set<String> types = fullNameToTypes.get(fieldMapper.fieldType().name()); boolean strict = beStrict(type, types, updateAllTypes); fieldType.checkCompatibility(fieldMapper.fieldType(), conflicts, strict); if (conflicts.isEmpty() == false) { throw new IllegalArgumentException("Mapper for [" + fieldMapper.fieldType().name() + "] conflicts with existing mapping in other types:\n" + conflicts.toString()); } } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); if (strict) { RangeFieldType other = (RangeFieldType)fieldType; if (this.rangeType != other.rangeType) { conflicts.add("mapper [" + name() + "] is attempting to update from type [" + rangeType.name + "] to incompatible type [" + other.rangeType.name + "]."); } if (this.rangeType == RangeType.DATE) { if (Objects.equals(dateTimeFormatter().format(), other.dateTimeFormatter().format()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [format] across all types."); } if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [locale] across all types."); } } } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); if (strict) { RangeFieldType other = (RangeFieldType)fieldType; if (this.rangeType != other.rangeType) { conflicts.add("mapper [" + name() + "] is attempting to update from type [" + rangeType.name + "] to incompatible type [" + other.rangeType.name + "]."); } if (this.rangeType == RangeType.DATE) { if (Objects.equals(dateTimeFormatter().format(), other.dateTimeFormatter().format()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [format] across all types."); } if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [locale] across all types."); } } } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); if (strict) { RangeFieldType other = (RangeFieldType)fieldType; if (this.rangeType != other.rangeType) { conflicts.add("mapper [" + name() + "] is attempting to update from type [" + rangeType.name + "] to incompatible type [" + other.rangeType.name + "]."); } if (this.rangeType == RangeType.DATE) { if (Objects.equals(dateTimeFormatter().format(), other.dateTimeFormatter().format()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [format] across all types."); } if (Objects.equals(dateTimeFormatter().locale(), other.dateTimeFormatter().locale()) == false) { conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [locale] across all types."); } } } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); CompletionFieldType other = (CompletionFieldType) fieldType; if (analyzingSuggestLookupProvider.hasPayloads() != other.analyzingSuggestLookupProvider.hasPayloads()) { conflicts.add("mapper [" + names().fullName() + "] has different [payload] values"); } if (analyzingSuggestLookupProvider.getPreservePositionsIncrements() != other.analyzingSuggestLookupProvider.getPreservePositionsIncrements()) { conflicts.add("mapper [" + names().fullName() + "] has different [preserve_position_increments] values"); } if (analyzingSuggestLookupProvider.getPreserveSep() != other.analyzingSuggestLookupProvider.getPreserveSep()) { conflicts.add("mapper [" + names().fullName() + "] has different [preserve_separators] values"); } if (!ContextMapping.mappingsAreEqual(getContextMapping(), other.getContextMapping())) { conflicts.add("mapper [" + names().fullName() + "] has different [context_mapping] values"); } }
@Override public void checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict) { super.checkCompatibility(fieldType, conflicts, strict); GeoPointFieldType other = (GeoPointFieldType)fieldType; if (isLatLonEnabled() != other.isLatLonEnabled()) { conflicts.add("mapper [" + names().fullName() + "] has different [lat_lon]"); } if (isLatLonEnabled() && other.isLatLonEnabled() && latFieldType().numericPrecisionStep() != other.latFieldType().numericPrecisionStep()) { conflicts.add("mapper [" + names().fullName() + "] has different [precision_step]"); } if (isGeoHashEnabled() != other.isGeoHashEnabled()) { conflicts.add("mapper [" + names().fullName() + "] has different [geohash]"); } if (geoHashPrecision() != other.geoHashPrecision()) { conflicts.add("mapper [" + names().fullName() + "] has different [geohash_precision]"); } if (isGeoHashPrefixEnabled() != other.isGeoHashPrefixEnabled()) { conflicts.add("mapper [" + names().fullName() + "] has different [geohash_prefix]"); } }