Skip to content

Commit c3f8d87

Browse files
ignore_above default to 8191 for logsdb (#113442) (#115451)
In LogsDB we would like to use a default value of `8191` for the index-level setting `index.mapping.ignore_above`. The value for `ignore_above` is the _character count_, but Lucene counts bytes. Here we set the limit to `32766 / 4 = 8191` since UTF-8 characters may occupy at most 4 bytes. (cherry picked from commit 521e434) # Conflicts: # server/src/main/java/org/elasticsearch/common/settings/Setting.java Co-authored-by: Salvatore Campagna <[email protected]>
1 parent ea119e5 commit c3f8d87

File tree

4 files changed

+101
-4
lines changed

4 files changed

+101
-4
lines changed

modules/data-streams/src/javaRestTest/java/org/elasticsearch/datastreams/logsdb/LogsIndexModeCustomSettingsIT.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.common.settings.Settings;
1616
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1717
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
18+
import org.hamcrest.Matchers;
1819
import org.junit.Before;
1920
import org.junit.ClassRule;
2021

@@ -438,6 +439,66 @@ public void testIgnoreMalformedSetting() throws IOException {
438439
}
439440
}
440441

442+
public void testIgnoreAboveSetting() throws IOException {
443+
// with default template
444+
{
445+
assertOK(createDataStream(client, "logs-test-1"));
446+
String logsIndex1 = getDataStreamBackingIndex(client, "logs-test-1", 0);
447+
assertThat(getSetting(client, logsIndex1, "index.mapping.ignore_above"), equalTo("8191"));
448+
for (String newValue : List.of("512", "2048", "12000", String.valueOf(Integer.MAX_VALUE))) {
449+
closeIndex(logsIndex1);
450+
updateIndexSettings(logsIndex1, Settings.builder().put("index.mapping.ignore_above", newValue));
451+
assertThat(getSetting(client, logsIndex1, "index.mapping.ignore_above"), equalTo(newValue));
452+
}
453+
for (String newValue : List.of(String.valueOf((long) Integer.MAX_VALUE + 1), String.valueOf(Long.MAX_VALUE))) {
454+
closeIndex(logsIndex1);
455+
ResponseException ex = assertThrows(
456+
ResponseException.class,
457+
() -> updateIndexSettings(logsIndex1, Settings.builder().put("index.mapping.ignore_above", newValue))
458+
);
459+
assertThat(
460+
ex.getMessage(),
461+
Matchers.containsString("Failed to parse value [" + newValue + "] for setting [index.mapping.ignore_above]")
462+
);
463+
}
464+
}
465+
// with override template
466+
{
467+
var template = """
468+
{
469+
"template": {
470+
"settings": {
471+
"index": {
472+
"mapping": {
473+
"ignore_above": "128"
474+
}
475+
}
476+
}
477+
}
478+
}""";
479+
assertOK(putComponentTemplate(client, "logs@custom", template));
480+
assertOK(createDataStream(client, "logs-custom-dev"));
481+
String index = getDataStreamBackingIndex(client, "logs-custom-dev", 0);
482+
assertThat(getSetting(client, index, "index.mapping.ignore_above"), equalTo("128"));
483+
for (String newValue : List.of("64", "256", "12000", String.valueOf(Integer.MAX_VALUE))) {
484+
closeIndex(index);
485+
updateIndexSettings(index, Settings.builder().put("index.mapping.ignore_above", newValue));
486+
assertThat(getSetting(client, index, "index.mapping.ignore_above"), equalTo(newValue));
487+
}
488+
}
489+
// standard index
490+
{
491+
String index = "test-index";
492+
createIndex(index);
493+
assertThat(getSetting(client, index, "index.mapping.ignore_above"), equalTo(Integer.toString(Integer.MAX_VALUE)));
494+
for (String newValue : List.of("256", "512", "12000", String.valueOf(Integer.MAX_VALUE))) {
495+
closeIndex(index);
496+
updateIndexSettings(index, Settings.builder().put("index.mapping.ignore_above", newValue));
497+
assertThat(getSetting(client, index, "index.mapping.ignore_above"), equalTo(newValue));
498+
}
499+
}
500+
}
501+
441502
private static Map<String, Object> getMapping(final RestClient client, final String indexName) throws IOException {
442503
final Request request = new Request("GET", "/" + indexName + "/_mapping");
443504

server/src/main/java/org/elasticsearch/common/settings/Setting.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,27 @@ public static Setting<Integer> intSetting(String key, int defaultValue, int minV
13711371
}
13721372

13731373
public static Setting<Integer> intSetting(String key, int defaultValue, int minValue, Property... properties) {
1374-
return new Setting<>(key, Integer.toString(defaultValue), (s) -> parseInt(s, minValue, key, isFiltered(properties)), properties);
1374+
return new Setting<>(key, Integer.toString(defaultValue), intParser(key, minValue, properties), properties);
1375+
}
1376+
1377+
public static Setting<Integer> intSetting(
1378+
String key,
1379+
Function<Settings, String> defaultValueFn,
1380+
int minValue,
1381+
int maxValue,
1382+
Property... properties
1383+
) {
1384+
return new Setting<>(key, defaultValueFn, intParser(key, minValue, maxValue, properties), properties);
1385+
}
1386+
1387+
private static Function<String, Integer> intParser(String key, int minValue, Property[] properties) {
1388+
final boolean isFiltered = isFiltered(properties);
1389+
return s -> parseInt(s, minValue, key, isFiltered);
1390+
}
1391+
1392+
private static Function<String, Integer> intParser(String key, int minValue, int maxValue, Property[] properties) {
1393+
boolean isFiltered = isFiltered(properties);
1394+
return s -> parseInt(s, minValue, maxValue, key, isFiltered);
13751395
}
13761396

13771397
public static Setting<Integer> intSetting(

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public Iterator<Setting<?>> settings() {
713713
/**
714714
* The `index.mapping.ignore_above` setting defines the maximum length for the content of a field that will be indexed
715715
* or stored. If the length of the field’s content exceeds this limit, the field value will be ignored during indexing.
716-
* This setting is useful for `keyword`, `flattened`, and `wildcard` fields where very large values are undesirable.
716+
* This setting is useful for `keyword`, `flattened`, and `wildcard` fields where very large values are undesirable.
717717
* It allows users to manage the size of indexed data by skipping fields with excessively long content. As an index-level
718718
* setting, it applies to all `keyword` and `wildcard` fields, as well as to keyword values within `flattened` fields.
719719
* When it comes to arrays, the `ignore_above` setting applies individually to each element of the array. If any element's
@@ -725,14 +725,30 @@ public Iterator<Setting<?>> settings() {
725725
* <pre>
726726
* "index.mapping.ignore_above": 256
727727
* </pre>
728+
* <p>
729+
* NOTE: The value for `ignore_above` is the _character count_, but Lucene counts
730+
* bytes. Here we set the limit to `32766 / 4 = 8191` since UTF-8 characters may
731+
* occupy at most 4 bytes.
728732
*/
733+
729734
public static final Setting<Integer> IGNORE_ABOVE_SETTING = Setting.intSetting(
730735
"index.mapping.ignore_above",
731-
Integer.MAX_VALUE,
736+
IndexSettings::getIgnoreAboveDefaultValue,
732737
0,
738+
Integer.MAX_VALUE,
733739
Property.IndexScope,
734740
Property.ServerlessPublic
735741
);
742+
743+
private static String getIgnoreAboveDefaultValue(final Settings settings) {
744+
if (IndexSettings.MODE.get(settings) == IndexMode.LOGSDB
745+
&& IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings).onOrAfter(IndexVersions.ENABLE_IGNORE_ABOVE_LOGSDB)) {
746+
return "8191";
747+
} else {
748+
return String.valueOf(Integer.MAX_VALUE);
749+
}
750+
}
751+
736752
public static final NodeFeature IGNORE_ABOVE_INDEX_LEVEL_SETTING = new NodeFeature("mapper.ignore_above_index_level_setting");
737753

738754
private final Index index;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static IndexVersion def(int id, Version luceneVersion) {
117117
public static final IndexVersion ENABLE_IGNORE_MALFORMED_LOGSDB = def(8_514_00_0, Version.LUCENE_9_11_1);
118118
public static final IndexVersion MERGE_ON_RECOVERY_VERSION = def(8_515_00_0, Version.LUCENE_9_11_1);
119119
public static final IndexVersion UPGRADE_TO_LUCENE_9_12 = def(8_516_00_0, Version.LUCENE_9_12_0);
120-
120+
public static final IndexVersion ENABLE_IGNORE_ABOVE_LOGSDB = def(8_517_00_0, Version.LUCENE_9_12_0);
121121
/*
122122
* STOP! READ THIS FIRST! No, really,
123123
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

0 commit comments

Comments
 (0)