Skip to content

Commit

Permalink
Fix index_prefixes cross-type compatibility check (#30956)
Browse files Browse the repository at this point in the history
Fixes #30955
  • Loading branch information
romseygeek authored May 30, 2018
1 parent a36ec74 commit 63d57b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,16 @@ public String toString() {
@Override
public void checkCompatibility(MappedFieldType other, List<String> conflicts, boolean strict) {
super.checkCompatibility(other, conflicts, strict);
PrefixFieldType otherFieldType = (PrefixFieldType) other;
if (otherFieldType.minChars != this.minChars) {
conflicts.add("mapper [" + name() + "] has different min_chars values");
}
if (otherFieldType.maxChars != this.maxChars) {
conflicts.add("mapper [" + name() + "] has different max_chars values");
if (strict) {
PrefixFieldType otherFieldType = (PrefixFieldType) other;
if (otherFieldType.minChars != this.minChars) {
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
+ "[index_prefixes.min_chars] across all types.");
}
if (otherFieldType.maxChars != this.maxChars) {
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
+ "[index_prefixes.max_chars] across all types.");
}
}
}

Expand Down Expand Up @@ -421,6 +425,10 @@ public void checkCompatibility(MappedFieldType other,
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
+ "[fielddata_frequency_filter.min_segment_size] across all types.");
}
if (Objects.equals(this.prefixFieldType, ((TextFieldType) other).prefixFieldType) == false) {
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
+ "[index_prefixes] across all types.");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,25 +734,6 @@ public void testIndexPrefixMapping() throws IOException {
Query q6 = mapper.mappers().getMapper("field").fieldType().prefixQuery("goings",
CONSTANT_SCORE_REWRITE, queryShardContext);
assertThat(q6, instanceOf(PrefixQuery.class));

indexService.mapperService().merge("type", json, MergeReason.MAPPING_UPDATE, true);

String badUpdate = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field")
.field("type", "text")
.field("analyzer", "english")
.startObject("index_prefixes")
.field("min_chars", 1)
.field("max_chars", 10)
.endObject()
.endObject().endObject()
.endObject().endObject());

IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
indexService.mapperService()
.merge("type", new CompressedXContent(badUpdate), MergeReason.MAPPING_UPDATE, true);
});
assertThat(e.getMessage(), containsString("mapper [field._index_prefix] has different min_chars values"));
}

{
Expand Down

0 comments on commit 63d57b4

Please sign in to comment.