This is an automated email from the ASF dual-hosted git repository.
thomasm pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 0ab3ca607d OAK-11460 Allow configuring the
index.mapping.total_fields.limit (#2058)
0ab3ca607d is described below
commit 0ab3ca607d3597b753c09cb3c6fc87b76a4f3fea
Author: Thomas Mueller <[email protected]>
AuthorDate: Tue Feb 11 09:55:49 2025 +0100
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
---
.../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..c168237b02 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());
+ }
+
@Test
public void multiRulesWithSamePropertyNames() {
IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();