Extract ESIntegTestCase#prepareSearch (#101175)

Relates #101172
This commit is contained in:
David Turner 2023-10-20 11:18:58 +01:00 committed by GitHub
parent 8a1db8c6c3
commit 1eda6ac74b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
263 changed files with 4724 additions and 6555 deletions

View file

@ -565,30 +565,22 @@ public class MoreExpressionIT extends ESIntegTestCase {
client().prepareIndex("agg_index").setId("4").setSource("one", 4.0, "two", 2.0, "three", 3.0, "four", 4.0),
client().prepareIndex("agg_index").setId("5").setSource("one", 5.0, "two", 2.0, "three", 3.0, "four", 4.0)
);
SearchResponse response = client().prepareSearch("agg_index")
.addAggregation(
histogram("histogram").field("one")
.interval(2)
.subAggregation(sum("twoSum").field("two"))
.subAggregation(sum("threeSum").field("three"))
.subAggregation(sum("fourSum").field("four"))
.subAggregation(
bucketScript(
"totalSum",
new Script(
ScriptType.INLINE,
ExpressionScriptEngine.NAME,
"_value0 + _value1 + _value2",
Collections.emptyMap()
),
"twoSum",
"threeSum",
"fourSum"
)
SearchResponse response = prepareSearch("agg_index").addAggregation(
histogram("histogram").field("one")
.interval(2)
.subAggregation(sum("twoSum").field("two"))
.subAggregation(sum("threeSum").field("three"))
.subAggregation(sum("fourSum").field("four"))
.subAggregation(
bucketScript(
"totalSum",
new Script(ScriptType.INLINE, ExpressionScriptEngine.NAME, "_value0 + _value1 + _value2", Collections.emptyMap()),
"twoSum",
"threeSum",
"fourSum"
)
)
.execute()
.actionGet();
)
).execute().actionGet();
Histogram histogram = response.getAggregations().get("histogram");
assertThat(histogram, notNullValue());

View file

@ -61,13 +61,11 @@ public class StoredExpressionIT extends ESIntegTestCase {
assertThat(e.toString(), containsString("cannot execute scripts using [field] context"));
}
try {
client().prepareSearch("test")
.setSource(
new SearchSourceBuilder().aggregation(
AggregationBuilders.terms("test").script(new Script(ScriptType.STORED, null, "script1", Collections.emptyMap()))
)
prepareSearch("test").setSource(
new SearchSourceBuilder().aggregation(
AggregationBuilders.terms("test").script(new Script(ScriptType.STORED, null, "script1", Collections.emptyMap()))
)
.get();
).get();
} catch (Exception e) {
assertThat(e.toString(), containsString("cannot execute scripts using [aggs] context"));
}