Skip to content

Commit 89663b8

Browse files
committed
Fixed failing bwc tests
1 parent 86256f6 commit 89663b8

File tree

8 files changed

+75
-73
lines changed

8 files changed

+75
-73
lines changed

server/src/main/java/org/elasticsearch/index/IndexSettings.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -813,33 +813,38 @@ public Iterator<Setting<?>> settings() {
813813
* occupy at most 4 bytes.
814814
*/
815815

816-
public static final int IGNORE_ABOVE_DEFAULT = Integer.MAX_VALUE;
817-
public static final int IGNORE_ABOVE_DEFAULT_LOGSDB = 8191;
816+
public static final int IGNORE_ABOVE_DEFAULT_STANDARD_INDICES = Integer.MAX_VALUE;
817+
public static final int IGNORE_ABOVE_DEFAULT_LOGSDB_INDICES = 8191;
818818

819819
public static final Setting<Integer> IGNORE_ABOVE_SETTING = Setting.intSetting(
820820
"index.mapping.ignore_above",
821-
IndexSettings::getIgnoreAboveDefaultValue,
821+
settings -> String.valueOf(getIgnoreAboveDefaultValue(settings)),
822822
0,
823823
Integer.MAX_VALUE,
824824
Property.IndexScope,
825825
Property.ServerlessPublic
826826
);
827827

828-
private static String getIgnoreAboveDefaultValue(final Settings settings) {
829-
return String.valueOf(
830-
getIgnoreAboveDefaultValue(IndexSettings.MODE.get(settings), IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings))
831-
);
828+
private static int getIgnoreAboveDefaultValue(final Settings settings) {
829+
if (settings == null) {
830+
return IGNORE_ABOVE_DEFAULT_STANDARD_INDICES;
831+
}
832+
return getIgnoreAboveDefaultValue(IndexSettings.MODE.get(settings), IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings));
832833
}
833834

834835
public static int getIgnoreAboveDefaultValue(final IndexMode indexMode, final IndexVersion indexCreatedVersion) {
835-
if (indexMode == IndexMode.LOGSDB
836-
&& (indexCreatedVersion != null && indexCreatedVersion.onOrAfter(IndexVersions.ENABLE_IGNORE_ABOVE_LOGSDB))) {
837-
return IGNORE_ABOVE_DEFAULT_LOGSDB;
836+
if (diffIgnoreAboveDefaultForLogs(indexMode, indexCreatedVersion)) {
837+
return IGNORE_ABOVE_DEFAULT_LOGSDB_INDICES;
838838
} else {
839-
return IGNORE_ABOVE_DEFAULT;
839+
return IGNORE_ABOVE_DEFAULT_STANDARD_INDICES;
840840
}
841841
}
842842

843+
private static boolean diffIgnoreAboveDefaultForLogs(final IndexMode indexMode, final IndexVersion indexCreatedVersion) {
844+
return indexMode == IndexMode.LOGSDB
845+
&& (indexCreatedVersion != null && indexCreatedVersion.onOrAfter(IndexVersions.ENABLE_IGNORE_ABOVE_LOGSDB));
846+
}
847+
843848
public static final Setting<SeqNoFieldMapper.SeqNoIndexOptions> SEQ_NO_INDEX_OPTIONS_SETTING = Setting.enumSetting(
844849
SeqNoFieldMapper.SeqNoIndexOptions.class,
845850
settings -> {

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,15 +1338,10 @@ public static Parameter<Boolean> normsParam(Function<FieldMapper, Boolean> initi
13381338
}
13391339

13401340
public static Parameter<Integer> ignoreAboveParam(Function<FieldMapper, Integer> initializer) {
1341-
return ignoreAboveParam(initializer, null, null);
1341+
return ignoreAboveParam(initializer, IndexSettings.IGNORE_ABOVE_DEFAULT_STANDARD_INDICES);
13421342
}
13431343

1344-
public static Parameter<Integer> ignoreAboveParam(
1345-
Function<FieldMapper, Integer> initializer,
1346-
final IndexMode indexMode,
1347-
final IndexVersion indexCreatedVersion
1348-
) {
1349-
final int defaultValue = IndexSettings.getIgnoreAboveDefaultValue(indexMode, indexCreatedVersion);
1344+
public static Parameter<Integer> ignoreAboveParam(Function<FieldMapper, Integer> initializer, final int defaultValue) {
13501345
return Parameter.intParam("ignore_above", true, initializer, defaultValue).addValidator(v -> {
13511346
if (v < 0) {
13521347
throw new IllegalArgumentException("[ignore_above] must be positive, got [" + v + "]");

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.elasticsearch.common.unit.Fuzziness;
4343
import org.elasticsearch.core.Nullable;
4444
import org.elasticsearch.index.IndexMode;
45+
import org.elasticsearch.index.IndexSettings;
4546
import org.elasticsearch.index.IndexSortConfig;
4647
import org.elasticsearch.index.IndexVersion;
4748
import org.elasticsearch.index.IndexVersions;
@@ -89,8 +90,9 @@
8990

9091
import static org.apache.lucene.index.IndexWriter.MAX_TERM_LENGTH;
9192
import static org.elasticsearch.core.Strings.format;
93+
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_DEFAULT_STANDARD_INDICES;
94+
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_SETTING;
9295
import static org.elasticsearch.index.IndexSettings.USE_DOC_VALUES_SKIPPER;
93-
import static org.elasticsearch.index.IndexSettings.getIgnoreAboveDefaultValue;
9496
import static org.elasticsearch.index.mapper.FieldArrayContext.getOffsetsFieldName;
9597

9698
/**
@@ -179,6 +181,7 @@ public static final class Builder extends FieldMapper.DimensionBuilder {
179181
false
180182
);
181183
private final Parameter<Integer> ignoreAbove;
184+
private final int ignoreAboveDefault;
182185
private final IndexSortConfig indexSortConfig;
183186
private final IndexMode indexMode;
184187
private final Parameter<String> indexOptions = TextParams.keywordIndexOptions(m -> toType(m).indexOptions);
@@ -217,6 +220,7 @@ public Builder(final String name, final MappingParserContext mappingParserContex
217220
name,
218221
mappingParserContext.getIndexAnalyzers(),
219222
mappingParserContext.scriptCompiler(),
223+
IGNORE_ABOVE_SETTING.get(mappingParserContext.getSettings()),
220224
mappingParserContext.getIndexSettings().getIndexVersionCreated(),
221225
mappingParserContext.getIndexSettings().getMode(),
222226
mappingParserContext.getIndexSettings().getIndexSortConfig(),
@@ -233,13 +237,25 @@ public Builder(final String name, final MappingParserContext mappingParserContex
233237
IndexVersion indexCreatedVersion,
234238
SourceKeepMode sourceKeepMode
235239
) {
236-
this(name, indexAnalyzers, scriptCompiler, indexCreatedVersion, IndexMode.STANDARD, null, false, false, sourceKeepMode);
240+
this(
241+
name,
242+
indexAnalyzers,
243+
scriptCompiler,
244+
IndexSettings.getIgnoreAboveDefaultValue(IndexMode.STANDARD, indexCreatedVersion),
245+
indexCreatedVersion,
246+
IndexMode.STANDARD,
247+
null,
248+
false,
249+
false,
250+
sourceKeepMode
251+
);
237252
}
238253

239254
private Builder(
240255
String name,
241256
IndexAnalyzers indexAnalyzers,
242257
ScriptCompiler scriptCompiler,
258+
int ignoreAboveDefault,
243259
IndexVersion indexCreatedVersion,
244260
IndexMode indexMode,
245261
IndexSortConfig indexSortConfig,
@@ -273,7 +289,8 @@ private Builder(
273289
);
274290
}
275291
}).precludesParameters(normalizer);
276-
this.ignoreAbove = Parameter.ignoreAboveParam(m -> toType(m).fieldType().ignoreAbove(), indexMode, indexCreatedVersion);
292+
this.ignoreAboveDefault = ignoreAboveDefault;
293+
this.ignoreAbove = Parameter.ignoreAboveParam(m -> toType(m).fieldType().ignoreAbove(), ignoreAboveDefault);
277294
this.indexSortConfig = indexSortConfig;
278295
this.indexMode = indexMode;
279296
this.enableDocValuesSkipper = enableDocValuesSkipper;
@@ -295,6 +312,7 @@ public static Builder buildWithDocValuesSkipper(
295312
name,
296313
null,
297314
ScriptCompiler.NONE,
315+
IndexSettings.getIgnoreAboveDefaultValue(indexMode, indexCreatedVersion),
298316
indexCreatedVersion,
299317
indexMode,
300318
// Sort config is used to decide if DocValueSkippers can be used. Since skippers are forced, a sort config is not needed.
@@ -564,7 +582,7 @@ public KeywordFieldType(String name) {
564582
public KeywordFieldType(String name, boolean isIndexed, boolean hasDocValues, Map<String, String> meta) {
565583
super(name, isIndexed, false, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
566584
this.normalizer = Lucene.KEYWORD_ANALYZER;
567-
this.ignoreAbove = this.ignoreAboveDefaultValue = getIgnoreAboveDefaultValue(IndexMode.STANDARD, IndexVersion.current());
585+
this.ignoreAbove = this.ignoreAboveDefaultValue = IGNORE_ABOVE_DEFAULT_STANDARD_INDICES;
568586
this.nullValue = null;
569587
this.eagerGlobalOrdinals = false;
570588
this.scriptValues = null;
@@ -585,7 +603,7 @@ public KeywordFieldType(String name, FieldType fieldType) {
585603
Collections.emptyMap()
586604
);
587605
this.normalizer = Lucene.KEYWORD_ANALYZER;
588-
this.ignoreAbove = this.ignoreAboveDefaultValue = getIgnoreAboveDefaultValue(IndexMode.STANDARD, IndexVersion.current());
606+
this.ignoreAbove = this.ignoreAboveDefaultValue = IGNORE_ABOVE_DEFAULT_STANDARD_INDICES;
589607
this.nullValue = null;
590608
this.eagerGlobalOrdinals = false;
591609
this.scriptValues = null;
@@ -599,7 +617,7 @@ public KeywordFieldType(String name, FieldType fieldType) {
599617
public KeywordFieldType(String name, NamedAnalyzer analyzer) {
600618
super(name, true, false, true, textSearchInfo(Defaults.FIELD_TYPE, null, analyzer, analyzer), Collections.emptyMap());
601619
this.normalizer = Lucene.KEYWORD_ANALYZER;
602-
this.ignoreAbove = this.ignoreAboveDefaultValue = getIgnoreAboveDefaultValue(IndexMode.STANDARD, IndexVersion.current());
620+
this.ignoreAbove = this.ignoreAboveDefaultValue = IGNORE_ABOVE_DEFAULT_STANDARD_INDICES;
603621
this.nullValue = null;
604622
this.eagerGlobalOrdinals = false;
605623
this.scriptValues = null;
@@ -1098,6 +1116,7 @@ public String originalName() {
10981116
private final boolean isSyntheticSource;
10991117

11001118
private final IndexAnalyzers indexAnalyzers;
1119+
private final int ignoreAboveDefault;
11011120
private final IndexMode indexMode;
11021121
private final IndexSortConfig indexSortConfig;
11031122
private final boolean enableDocValuesSkipper;
@@ -1129,6 +1148,7 @@ private KeywordFieldMapper(
11291148
this.scriptCompiler = builder.scriptCompiler;
11301149
this.indexCreatedVersion = builder.indexCreatedVersion;
11311150
this.isSyntheticSource = isSyntheticSource;
1151+
this.ignoreAboveDefault = builder.ignoreAboveDefault;
11321152
this.indexMode = builder.indexMode;
11331153
this.indexSortConfig = builder.indexSortConfig;
11341154
this.enableDocValuesSkipper = builder.enableDocValuesSkipper;
@@ -1284,6 +1304,7 @@ public FieldMapper.Builder getMergeBuilder() {
12841304
leafName(),
12851305
indexAnalyzers,
12861306
scriptCompiler,
1307+
ignoreAboveDefault,
12871308
indexCreatedVersion,
12881309
indexMode,
12891310
indexSortConfig,

server/src/main/java/org/elasticsearch/index/mapper/flattened/FlattenedFieldMapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.common.util.BigArrays;
4040
import org.elasticsearch.core.Nullable;
4141
import org.elasticsearch.index.IndexMode;
42+
import org.elasticsearch.index.IndexSettings;
4243
import org.elasticsearch.index.IndexVersion;
4344
import org.elasticsearch.index.analysis.NamedAnalyzer;
4445
import org.elasticsearch.index.fielddata.FieldData;
@@ -193,7 +194,10 @@ private Builder(String name, IndexMode indexMode, IndexVersion indexCreatedVersi
193194
super(name);
194195
this.indexMode = indexMode;
195196
this.indexCreatedVersion = indexCreatedVersion;
196-
this.ignoreAbove = Parameter.ignoreAboveParam(m -> builder(m).ignoreAbove.get(), indexMode, indexCreatedVersion);
197+
this.ignoreAbove = Parameter.ignoreAboveParam(
198+
m -> builder(m).ignoreAbove.get(),
199+
IndexSettings.getIgnoreAboveDefaultValue(indexMode, indexCreatedVersion)
200+
);
197201
this.dimensions.precludesParameters(ignoreAbove);
198202
}
199203

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
import java.util.List;
6262
import java.util.Map;
6363

64-
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_DEFAULT;
65-
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_DEFAULT_LOGSDB;
64+
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_DEFAULT_LOGSDB_INDICES;
65+
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_DEFAULT_STANDARD_INDICES;
6666
import static org.mockito.Mockito.doReturn;
6767
import static org.mockito.Mockito.mock;
6868

@@ -374,7 +374,7 @@ public void test_isIgnoreAboveSet_returns_false_when_ignore_above_is_given_but_i
374374
doReturn(mock(ScriptCompiler.class)).when(mappingParserContext).scriptCompiler();
375375

376376
KeywordFieldMapper.Builder builder = new KeywordFieldMapper.Builder("field", mappingParserContext);
377-
builder.ignoreAbove(IGNORE_ABOVE_DEFAULT);
377+
builder.ignoreAbove(IGNORE_ABOVE_DEFAULT_STANDARD_INDICES);
378378

379379
KeywordFieldMapper.KeywordFieldType fieldType = new KeywordFieldMapper.KeywordFieldType(
380380
"field",
@@ -405,7 +405,7 @@ public void test_isIgnoreAboveSet_returns_false_when_ignore_above_is_given_but_i
405405
doReturn(mock(ScriptCompiler.class)).when(mappingParserContext).scriptCompiler();
406406

407407
KeywordFieldMapper.Builder builder = new KeywordFieldMapper.Builder("field", mappingParserContext);
408-
builder.ignoreAbove(IGNORE_ABOVE_DEFAULT_LOGSDB);
408+
builder.ignoreAbove(IGNORE_ABOVE_DEFAULT_LOGSDB_INDICES);
409409

410410
KeywordFieldMapper.KeywordFieldType fieldType = new KeywordFieldMapper.KeywordFieldType(
411411
"field",
@@ -424,28 +424,28 @@ public void test_isIgnoreAboveSet_returns_false_when_ignore_above_is_given_but_i
424424
public void test_isIgnoreAboveSet_returns_true_when_ignore_above_is_given_as_logsdb_default_but_index_mod_is_not_logsdb() {
425425
// given
426426
Settings settings = Settings.builder()
427-
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
428-
.put(IndexSettings.MODE.getKey(), IndexMode.STANDARD)
429-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
430-
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
431-
.build();
427+
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
428+
.put(IndexSettings.MODE.getKey(), IndexMode.STANDARD)
429+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
430+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
431+
.build();
432432
IndexSettings indexSettings = new IndexSettings(IndexMetadata.builder("index").settings(settings).build(), settings);
433433
MappingParserContext mappingParserContext = mock(MappingParserContext.class);
434434
doReturn(settings).when(mappingParserContext).getSettings();
435435
doReturn(indexSettings).when(mappingParserContext).getIndexSettings();
436436
doReturn(mock(ScriptCompiler.class)).when(mappingParserContext).scriptCompiler();
437437

438438
KeywordFieldMapper.Builder builder = new KeywordFieldMapper.Builder("field", mappingParserContext);
439-
builder.ignoreAbove(IGNORE_ABOVE_DEFAULT_LOGSDB);
439+
builder.ignoreAbove(IGNORE_ABOVE_DEFAULT_LOGSDB_INDICES);
440440

441441
KeywordFieldMapper.KeywordFieldType fieldType = new KeywordFieldMapper.KeywordFieldType(
442-
"field",
443-
mock(FieldType.class),
444-
mock(NamedAnalyzer.class),
445-
mock(NamedAnalyzer.class),
446-
mock(NamedAnalyzer.class),
447-
builder,
448-
true
442+
"field",
443+
mock(FieldType.class),
444+
mock(NamedAnalyzer.class),
445+
mock(NamedAnalyzer.class),
446+
mock(NamedAnalyzer.class),
447+
builder,
448+
true
449449
);
450450

451451
// when/then

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

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99

1010
package org.elasticsearch.index.mapper;
1111

12-
import org.elasticsearch.index.IndexMode;
13-
import org.elasticsearch.index.IndexVersion;
1412
import org.elasticsearch.test.ESTestCase;
1513

16-
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_DEFAULT;
17-
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_DEFAULT_LOGSDB;
14+
import static org.elasticsearch.index.IndexSettings.IGNORE_ABOVE_DEFAULT_STANDARD_INDICES;
1815

1916
public class ParameterTests extends ESTestCase {
2017

@@ -23,31 +20,7 @@ public void test_ignore_above_param_default() {
2320
FieldMapper.Parameter<Integer> ignoreAbove = FieldMapper.Parameter.ignoreAboveParam((FieldMapper fm) -> 123);
2421

2522
// then
26-
assertEquals(IGNORE_ABOVE_DEFAULT, ignoreAbove.getValue().intValue());
27-
}
28-
29-
public void test_ignore_above_param_default_for_standard_indices() {
30-
// when
31-
FieldMapper.Parameter<Integer> ignoreAbove = FieldMapper.Parameter.ignoreAboveParam(
32-
(FieldMapper fm) -> 123,
33-
IndexMode.STANDARD,
34-
IndexVersion.current()
35-
);
36-
37-
// then
38-
assertEquals(IGNORE_ABOVE_DEFAULT, ignoreAbove.getValue().intValue());
39-
}
40-
41-
public void test_ignore_above_param_default_for_logsdb_indices() {
42-
// when
43-
FieldMapper.Parameter<Integer> ignoreAbove = FieldMapper.Parameter.ignoreAboveParam(
44-
(FieldMapper fm) -> 123,
45-
IndexMode.LOGSDB,
46-
IndexVersion.current()
47-
);
48-
49-
// then
50-
assertEquals(IGNORE_ABOVE_DEFAULT_LOGSDB, ignoreAbove.getValue().intValue());
23+
assertEquals(IGNORE_ABOVE_DEFAULT_STANDARD_INDICES, ignoreAbove.getValue().intValue());
5124
}
5225

5326
public void test_ignore_above_param_invalid_value() {

x-pack/plugin/logsdb/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/TextRollingUpgradeIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class TextRollingUpgradeIT extends AbstractRollingUpgradeWithSecurityTest
7979
}
8080
}""";
8181

82-
// when sorted, this message will appear at the top
82+
// when sorted, this message will appear at the top and hence can be used to validate query results
8383
private String smallestMessage;
8484

8585
public TextRollingUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {

x-pack/plugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/mapper/WildcardFieldMapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.elasticsearch.common.unit.Fuzziness;
5353
import org.elasticsearch.core.Nullable;
5454
import org.elasticsearch.index.IndexMode;
55+
import org.elasticsearch.index.IndexSettings;
5556
import org.elasticsearch.index.IndexVersion;
5657
import org.elasticsearch.index.IndexVersions;
5758
import org.elasticsearch.index.analysis.AnalyzerScope;
@@ -221,7 +222,10 @@ private Builder(String name, IndexMode indexMode, IndexVersion indexVersionCreat
221222
super(name);
222223
this.indexVersionCreated = indexVersionCreated;
223224
this.indexMode = indexMode;
224-
this.ignoreAbove = Parameter.ignoreAboveParam(m -> toType(m).ignoreAbove, indexMode, indexVersionCreated);
225+
this.ignoreAbove = Parameter.ignoreAboveParam(
226+
m -> toType(m).ignoreAbove,
227+
IndexSettings.getIgnoreAboveDefaultValue(indexMode, indexVersionCreated)
228+
);
225229
}
226230

227231
@Override

0 commit comments

Comments
 (0)