Skip to content

Commit c8ee1d5

Browse files
authored
Register mustache size limit setting (elastic#119291) (elastic#129002)
In elastic#114002 the maximum size of a mustache script output was made configurable. However, the setting was not registered. This commit registers the setting so that it can be set in elasticsearch.yml.
1 parent 8f6caab commit c8ee1d5

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

docs/changelog/119291.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 119291
2+
summary: Register mustache size limit setting
3+
area: Infra/Scripting
4+
type: bug
5+
issues: []
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.script.mustache;
11+
12+
import org.elasticsearch.ElasticsearchParseException;
13+
import org.elasticsearch.action.search.SearchRequest;
14+
import org.elasticsearch.common.settings.Settings;
15+
import org.elasticsearch.plugins.Plugin;
16+
import org.elasticsearch.script.ScriptType;
17+
import org.elasticsearch.test.ESSingleNodeTestCase;
18+
19+
import java.util.Collection;
20+
import java.util.Collections;
21+
import java.util.List;
22+
23+
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
24+
import static org.hamcrest.Matchers.equalTo;
25+
26+
public class MustacheSettingsIT extends ESSingleNodeTestCase {
27+
@Override
28+
protected Collection<Class<? extends Plugin>> getPlugins() {
29+
return List.of(MustachePlugin.class);
30+
}
31+
32+
@Override
33+
protected Settings nodeSettings() {
34+
return Settings.builder().put(MustacheScriptEngine.MUSTACHE_RESULT_SIZE_LIMIT.getKey(), "10b").build();
35+
}
36+
37+
public void testResultSizeLimit() throws Exception {
38+
createIndex("test");
39+
prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("text", "value1").endObject()).get();
40+
indicesAdmin().prepareRefresh().get();
41+
42+
String query = """
43+
{ "query": {"match_all": {}}, "size" : "{{my_size}}" }""";
44+
SearchRequest searchRequest = new SearchRequest();
45+
searchRequest.indices("test");
46+
var e = expectThrows(
47+
ElasticsearchParseException.class,
48+
() -> new SearchTemplateRequestBuilder(client()).setRequest(searchRequest)
49+
.setScript(query)
50+
.setScriptType(ScriptType.INLINE)
51+
.setScriptParams(Collections.singletonMap("my_size", 1))
52+
.get()
53+
);
54+
assertThat(e.getMessage(), equalTo("Mustache script result size limit exceeded"));
55+
}
56+
}

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1818
import org.elasticsearch.common.settings.ClusterSettings;
1919
import org.elasticsearch.common.settings.IndexScopedSettings;
20+
import org.elasticsearch.common.settings.Setting;
2021
import org.elasticsearch.common.settings.Settings;
2122
import org.elasticsearch.common.settings.SettingsFilter;
2223
import org.elasticsearch.features.NodeFeature;
@@ -73,4 +74,9 @@ public List<RestHandler> getRestHandlers(
7374
new RestRenderSearchTemplateAction()
7475
);
7576
}
77+
78+
@Override
79+
public List<Setting<?>> getSettings() {
80+
return List.of(MustacheScriptEngine.MUSTACHE_RESULT_SIZE_LIMIT);
81+
}
7682
}

0 commit comments

Comments
 (0)