From d4cb711ae08929b5d6fae2c1de9e29a5cc570213 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 30 May 2018 10:41:46 +0100 Subject: [PATCH] Fix index_prefixes cross-type compatibility check Fixes #30955 --- .../index/mapper/TextFieldMapper.java | 20 +++++++++++++------ .../index/mapper/TextFieldMapperTests.java | 19 ------------------ 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index 87daa6a6dbcf1..0e5d0fb131e15 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -292,12 +292,16 @@ public String toString() { @Override public void checkCompatibility(MappedFieldType other, List 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."); + } } } @@ -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."); + } } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java index 4bf7b2c5e075c..a0e6d309c75bc 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/TextFieldMapperTests.java @@ -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")); } {