Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix index_prefixes cross-type compatibility check #30956

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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