forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register mustache size limit setting (elastic#119291)
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.
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 119291 | ||
summary: Register mustache size limit setting | ||
area: Infra/Scripting | ||
type: bug | ||
issues: [] |
56 changes: 56 additions & 0 deletions
56
...he/src/internalClusterTest/java/org/elasticsearch/script/mustache/MustacheSettingsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.script.mustache; | ||
|
||
import org.elasticsearch.ElasticsearchParseException; | ||
import org.elasticsearch.action.search.SearchRequest; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.script.ScriptType; | ||
import org.elasticsearch.test.ESSingleNodeTestCase; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class MustacheSettingsIT extends ESSingleNodeTestCase { | ||
@Override | ||
protected Collection<Class<? extends Plugin>> getPlugins() { | ||
return List.of(MustachePlugin.class); | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings() { | ||
return Settings.builder().put(MustacheScriptEngine.MUSTACHE_RESULT_SIZE_LIMIT.getKey(), "10b").build(); | ||
} | ||
|
||
public void testResultSizeLimit() throws Exception { | ||
createIndex("test"); | ||
prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("text", "value1").endObject()).get(); | ||
indicesAdmin().prepareRefresh().get(); | ||
|
||
String query = """ | ||
{ "query": {"match_all": {}}, "size" : "{{my_size}}" }"""; | ||
SearchRequest searchRequest = new SearchRequest(); | ||
searchRequest.indices("test"); | ||
var e = expectThrows( | ||
ElasticsearchParseException.class, | ||
() -> new SearchTemplateRequestBuilder(client()).setRequest(searchRequest) | ||
.setScript(query) | ||
.setScriptType(ScriptType.INLINE) | ||
.setScriptParams(Collections.singletonMap("my_size", 1)) | ||
.get() | ||
); | ||
assertThat(e.getMessage(), equalTo("Mustache script result size limit exceeded")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters