Skip to content

Commit a66753d

Browse files
committed
Fix index_prefixes cross-type compatibility check
Fixes #30955
1 parent 5325a99 commit a66753d

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,16 @@ public String toString() {
292292
@Override
293293
public void checkCompatibility(MappedFieldType other, List<String> conflicts, boolean strict) {
294294
super.checkCompatibility(other, conflicts, strict);
295-
PrefixFieldType otherFieldType = (PrefixFieldType) other;
296-
if (otherFieldType.minChars != this.minChars) {
297-
conflicts.add("mapper [" + name() + "] has different min_chars values");
298-
}
299-
if (otherFieldType.maxChars != this.maxChars) {
300-
conflicts.add("mapper [" + name() + "] has different max_chars values");
295+
if (strict) {
296+
PrefixFieldType otherFieldType = (PrefixFieldType) other;
297+
if (otherFieldType.minChars != this.minChars) {
298+
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
299+
+ "[index_prefixes.min_chars] across all types.");
300+
}
301+
if (otherFieldType.maxChars != this.maxChars) {
302+
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
303+
+ "[index_prefixes.max_chars] across all types.");
304+
}
301305
}
302306
}
303307

@@ -421,6 +425,10 @@ public void checkCompatibility(MappedFieldType other,
421425
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
422426
+ "[fielddata_frequency_filter.min_segment_size] across all types.");
423427
}
428+
if (Objects.equals(this.prefixFieldType, ((TextFieldType) other).prefixFieldType) == false) {
429+
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
430+
+ "[index_prefixes] across all types.");
431+
}
424432
}
425433
}
426434

server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -734,25 +734,6 @@ public void testIndexPrefixMapping() throws IOException {
734734
Query q6 = mapper.mappers().getMapper("field").fieldType().prefixQuery("goings",
735735
CONSTANT_SCORE_REWRITE, queryShardContext);
736736
assertThat(q6, instanceOf(PrefixQuery.class));
737-
738-
indexService.mapperService().merge("type", json, MergeReason.MAPPING_UPDATE, true);
739-
740-
String badUpdate = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
741-
.startObject("properties").startObject("field")
742-
.field("type", "text")
743-
.field("analyzer", "english")
744-
.startObject("index_prefixes")
745-
.field("min_chars", 1)
746-
.field("max_chars", 10)
747-
.endObject()
748-
.endObject().endObject()
749-
.endObject().endObject());
750-
751-
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
752-
indexService.mapperService()
753-
.merge("type", new CompressedXContent(badUpdate), MergeReason.MAPPING_UPDATE, true);
754-
});
755-
assertThat(e.getMessage(), containsString("mapper [field._index_prefix] has different min_chars values"));
756737
}
757738

758739
{

0 commit comments

Comments
 (0)