Skip to content

Commit 7d7d2f4

Browse files
committed
Ensure that index_prefixes settings cannot be changed (#30967)
1 parent 7d955f8 commit 7d7d2f4

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -289,22 +289,6 @@ public String toString() {
289289
return super.toString() + ",prefixChars=" + minChars + ":" + maxChars;
290290
}
291291

292-
@Override
293-
public void checkCompatibility(MappedFieldType other, List<String> conflicts, boolean strict) {
294-
super.checkCompatibility(other, conflicts, strict);
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-
}
305-
}
306-
}
307-
308292
@Override
309293
public Query existsQuery(QueryShardContext context) {
310294
throw new UnsupportedOperationException();
@@ -408,6 +392,19 @@ public void checkCompatibility(MappedFieldType other,
408392
List<String> conflicts, boolean strict) {
409393
super.checkCompatibility(other, conflicts, strict);
410394
TextFieldType otherType = (TextFieldType) other;
395+
if (Objects.equals(this.prefixFieldType, otherType.prefixFieldType) == false) {
396+
if (this.prefixFieldType == null) {
397+
conflicts.add("mapper [" + name()
398+
+ "] has different [index_prefixes] settings, cannot change from disabled to enabled");
399+
}
400+
else if (otherType.prefixFieldType == null) {
401+
conflicts.add("mapper [" + name()
402+
+ "] has different [index_prefixes] settings, cannot change from enabled to disabled");
403+
}
404+
else {
405+
conflicts.add("mapper [" + name() + "] has different [index_prefixes] settings");
406+
}
407+
}
411408
if (strict) {
412409
if (fielddata() != otherType.fielddata()) {
413410
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update [fielddata] "
@@ -425,10 +422,6 @@ public void checkCompatibility(MappedFieldType other,
425422
conflicts.add("mapper [" + name() + "] is used by multiple types. Set update_all_types to true to update "
426423
+ "[fielddata_frequency_filter.min_segment_size] across all types.");
427424
}
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-
}
432425
}
433426
}
434427

@@ -521,6 +514,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
521514
}
522515
return new PagedBytesIndexFieldData.Builder(fielddataMinFrequency, fielddataMaxFrequency, fielddataMinSegmentSize);
523516
}
517+
524518
}
525519

526520
private Boolean includeInAll;

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,20 @@
1818
*/
1919
package org.elasticsearch.index.mapper;
2020

21-
import java.util.ArrayList;
22-
import java.util.Arrays;
23-
import java.util.List;
24-
25-
import org.apache.lucene.document.LongPoint;
2621
import org.apache.lucene.index.IndexOptions;
2722
import org.apache.lucene.index.Term;
28-
import org.apache.lucene.search.TermInSetQuery;
2923
import org.apache.lucene.search.FuzzyQuery;
3024
import org.apache.lucene.search.RegexpQuery;
25+
import org.apache.lucene.search.TermInSetQuery;
3126
import org.apache.lucene.search.TermQuery;
3227
import org.apache.lucene.util.BytesRef;
3328
import org.elasticsearch.common.unit.Fuzziness;
34-
import org.elasticsearch.index.mapper.MappedFieldType;
35-
import org.elasticsearch.index.mapper.TextFieldMapper;
3629
import org.junit.Before;
3730

31+
import java.util.ArrayList;
32+
import java.util.Arrays;
33+
import java.util.List;
34+
3835
public class TextFieldTypeTests extends FieldTypeTestCase {
3936
@Override
4037
protected MappedFieldType createDefaultFieldType() {
@@ -71,7 +68,7 @@ public void modify(MappedFieldType ft) {
7168
tft.setFielddataMinSegmentSize(1000);
7269
}
7370
});
74-
addModifier(new Modifier("index_prefixes", true) {
71+
addModifier(new Modifier("index_prefixes", false) {
7572
@Override
7673
public void modify(MappedFieldType ft) {
7774
TextFieldMapper.TextFieldType tft = (TextFieldMapper.TextFieldType)ft;

0 commit comments

Comments
 (0)