You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2025/02/06 11:20:25 UTC

(jackrabbit-oak) branch OAK-11460 created (now f2ce9d52dc)

This is an automated email from the ASF dual-hosted git repository.

thomasm pushed a change to branch OAK-11460
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


      at f2ce9d52dc OAK-11460 Allow configuring the index.mapping.total_fields.limit

This branch includes the following new commits:

     new f2ce9d52dc OAK-11460 Allow configuring the index.mapping.total_fields.limit

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(jackrabbit-oak) 01/01: OAK-11460 Allow configuring the index.mapping.total_fields.limit

Posted by th...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

thomasm pushed a commit to branch OAK-11460
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit f2ce9d52dcf339b4521e42b7049ac95ed4c27e4d
Author: Thomas Mueller <th...@apache.org>
AuthorDate: Thu Feb 6 12:20:08 2025 +0100

    OAK-11460 Allow configuring the index.mapping.total_fields.limit
---
 .../oak/plugins/index/elastic/ElasticIndexDefinition.java |  7 +++++++
 .../plugins/index/elastic/index/ElasticIndexHelper.java   |  3 ++-
 .../index/elastic/index/ElasticIndexHelperTest.java       | 15 +++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java
index 49bca01d7f..53e1f3c034 100644
--- a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java
+++ b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexDefinition.java
@@ -75,6 +75,11 @@ public class ElasticIndexDefinition extends IndexDefinition {
     // possible values are: true, false, runtime, strict. See https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html
     public static final String DYNAMIC_MAPPING_DEFAULT = "true";
 
+    // https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-settings-limit.html
+    // index.mapping.total_fields.limit
+    public static final String LIMIT_TOTAL_FIELDS = "limitTotalFields";
+    public static final long LIMIT_TOTAL_FIELDS_DEFAULT = 1000L;
+
     // when true, fails indexing in case of bulk failures
     public static final String FAIL_ON_ERROR = "failOnError";
     public static final boolean FAIL_ON_ERROR_DEFAULT = true;
@@ -185,6 +190,7 @@ public class ElasticIndexDefinition extends IndexDefinition {
     public final boolean failOnError;
     public final long indexNameSeed;
     public final InferenceDefinition inferenceDefinition;
+    public final long limitTotalFields;
 
     private final Map<String, List<PropertyDefinition>> propertiesByName;
     private final List<ElasticPropertyDefinition> dynamicBoostProperties;
@@ -220,6 +226,7 @@ public class ElasticIndexDefinition extends IndexDefinition {
         );
         this.indexNameSeed = getOptionalValue(defn, INDEX_NAME_SEED, INDEX_NAME_SEED_DEFAULT);
         this.similarityTagsFields = getOptionalValues(defn, SIMILARITY_TAGS_FIELDS, Type.STRINGS, String.class, SIMILARITY_TAGS_FIELDS_DEFAULT);
+        this.limitTotalFields = getOptionalValue(defn, LIMIT_TOTAL_FIELDS, LIMIT_TOTAL_FIELDS_DEFAULT);
 
         this.propertiesByName = getDefinedRules()
                 .stream()
diff --git a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelper.java b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelper.java
index dca9889d54..b49022403b 100644
--- a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelper.java
+++ b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelper.java
@@ -220,7 +220,8 @@ class ElasticIndexHelper {
         builder.index(indexBuilder -> indexBuilder
                         // Make the index more lenient when a field cannot be converted to the mapped type. Without this setting
                         // the entire document will fail to update. Instead, only the specific field won't be updated.
-                        .mapping(mf -> mf.ignoreMalformed(true))
+                        .mapping(mf -> mf.ignoreMalformed(true).
+                                totalFields(f -> f.limit(indexDefinition.limitTotalFields)))
                         // static setting: cannot be changed after the index gets created
                         .numberOfShards(Integer.toString(indexDefinition.numberOfShards))
                         // dynamic settings: see #enableIndexRequest
diff --git a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelperTest.java b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelperTest.java
index 131681c2b9..7418d2df55 100644
--- a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelperTest.java
+++ b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticIndexHelperTest.java
@@ -37,9 +37,24 @@ import org.junit.Test;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
 
 public class ElasticIndexHelperTest {
 
+    @Test
+    public void manyFields() {
+        IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();
+        builder.getBuilderTree().setProperty(ElasticIndexDefinition.LIMIT_TOTAL_FIELDS, 1234L);
+        IndexDefinitionBuilder.IndexRule indexRuleA = builder.indexRule("typeA");
+        indexRuleA.property("foo").type("String");
+        NodeState nodeState = builder.build();
+        ElasticIndexDefinition definition =
+                new ElasticIndexDefinition(nodeState, nodeState, "path", "prefix");
+        CreateIndexRequest request = ElasticIndexHelper.createIndexRequest("prefix.path", definition);
+        assertEquals(1234L, request.settings().index().mapping().totalFields().limit().longValue());
+        assertEquals(true, request.settings().index().mapping().ignoreMalformed().booleanValue());
+    }
+
     @Test
     public void multiRulesWithSamePropertyNames() {
         IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();