Skip to content

Commit 0ab3ca6

Browse files
OAK-11460 Allow configuring the index.mapping.total_fields.limit (#2058)
* OAK-11460 Allow configuring the index.mapping.total_fields.limit * OAK-11460 Allow configuring the index.mapping.total_fields.limit
1 parent fd0c57c commit 0ab3ca6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public class ElasticIndexDefinition extends IndexDefinition {
7575
// possible values are: true, false, runtime, strict. See https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html
7676
public static final String DYNAMIC_MAPPING_DEFAULT = "true";
7777

78+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-settings-limit.html
79+
// index.mapping.total_fields.limit
80+
public static final String LIMIT_TOTAL_FIELDS = "limitTotalFields";
81+
public static final long LIMIT_TOTAL_FIELDS_DEFAULT = 1000L;
82+
7883
// when true, fails indexing in case of bulk failures
7984
public static final String FAIL_ON_ERROR = "failOnError";
8085
public static final boolean FAIL_ON_ERROR_DEFAULT = true;
@@ -185,6 +190,7 @@ public class ElasticIndexDefinition extends IndexDefinition {
185190
public final boolean failOnError;
186191
public final long indexNameSeed;
187192
public final InferenceDefinition inferenceDefinition;
193+
public final long limitTotalFields;
188194

189195
private final Map<String, List<PropertyDefinition>> propertiesByName;
190196
private final List<ElasticPropertyDefinition> dynamicBoostProperties;
@@ -220,6 +226,7 @@ public ElasticIndexDefinition(NodeState root, NodeState defn, String indexPath,
220226
);
221227
this.indexNameSeed = getOptionalValue(defn, INDEX_NAME_SEED, INDEX_NAME_SEED_DEFAULT);
222228
this.similarityTagsFields = getOptionalValues(defn, SIMILARITY_TAGS_FIELDS, Type.STRINGS, String.class, SIMILARITY_TAGS_FIELDS_DEFAULT);
229+
this.limitTotalFields = getOptionalValue(defn, LIMIT_TOTAL_FIELDS, LIMIT_TOTAL_FIELDS_DEFAULT);
223230

224231
this.propertiesByName = getDefinedRules()
225232
.stream()

oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ private static ObjectBuilder<IndexSettings> loadSettings(@NotNull IndexSettings.
220220
builder.index(indexBuilder -> indexBuilder
221221
// Make the index more lenient when a field cannot be converted to the mapped type. Without this setting
222222
// the entire document will fail to update. Instead, only the specific field won't be updated.
223-
.mapping(mf -> mf.ignoreMalformed(true))
223+
.mapping(mf -> mf.ignoreMalformed(true).
224+
totalFields(f -> f.limit(indexDefinition.limitTotalFields)))
224225
// static setting: cannot be changed after the index gets created
225226
.numberOfShards(Integer.toString(indexDefinition.numberOfShards))
226227
// dynamic settings: see #enableIndexRequest

oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelperTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,24 @@
3737
import static org.hamcrest.CoreMatchers.notNullValue;
3838
import static org.hamcrest.CoreMatchers.is;
3939
import static org.hamcrest.MatcherAssert.assertThat;
40+
import static org.junit.Assert.assertEquals;
4041

4142
public class ElasticIndexHelperTest {
4243

44+
@Test
45+
public void manyFields() {
46+
IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();
47+
builder.getBuilderTree().setProperty(ElasticIndexDefinition.LIMIT_TOTAL_FIELDS, 1234L);
48+
IndexDefinitionBuilder.IndexRule indexRuleA = builder.indexRule("typeA");
49+
indexRuleA.property("foo").type("String");
50+
NodeState nodeState = builder.build();
51+
ElasticIndexDefinition definition =
52+
new ElasticIndexDefinition(nodeState, nodeState, "path", "prefix");
53+
CreateIndexRequest request = ElasticIndexHelper.createIndexRequest("prefix.path", definition);
54+
assertEquals(1234L, request.settings().index().mapping().totalFields().limit().longValue());
55+
assertEquals(true, request.settings().index().mapping().ignoreMalformed());
56+
}
57+
4358
@Test
4459
public void multiRulesWithSamePropertyNames() {
4560
IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();

0 commit comments

Comments
 (0)