Use ESIntegTestCase#prepareSearch more (#101179)

The refactoring in #101175 only covered all the one-arg call sites. This
PR does the rest.
This commit is contained in:
David Turner 2023-10-20 18:33:00 +01:00 committed by GitHub
parent 1521484d11
commit 9794c6e205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
102 changed files with 976 additions and 1529 deletions

View file

@ -66,7 +66,7 @@ public class MoreExpressionIT extends ESIntegTestCase {
paramsMap.put(params[i].toString(), params[i + 1]);
}
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
SearchRequestBuilder req = prepareSearch().setIndices("test");
req.setQuery(QueryBuilders.matchAllQuery())
.addSort(SortBuilders.fieldSort("id").order(SortOrder.ASC).unmappedType("long"))
.addScriptField("foo", new Script(ScriptType.INLINE, "expression", script, paramsMap));
@ -113,7 +113,7 @@ public class MoreExpressionIT extends ESIntegTestCase {
ScriptScoreFunctionBuilder score = ScoreFunctionBuilders.scriptFunction(
new Script(ScriptType.INLINE, "expression", "1 / _score", Collections.emptyMap())
);
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
SearchRequestBuilder req = prepareSearch().setIndices("test");
req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode(CombineFunction.REPLACE));
req.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); // make sure DF is consistent
SearchResponse rsp = req.get();
@ -124,7 +124,7 @@ public class MoreExpressionIT extends ESIntegTestCase {
assertEquals("3", hits.getAt(1).getId());
assertEquals("2", hits.getAt(2).getId());
req = client().prepareSearch().setIndices("test");
req = prepareSearch().setIndices("test");
req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode(CombineFunction.REPLACE));
score = ScoreFunctionBuilders.scriptFunction(new Script(ScriptType.INLINE, "expression", "1 / _score", Collections.emptyMap()));
req.addAggregation(AggregationBuilders.max("max_score").script((score).getScript()));
@ -466,7 +466,7 @@ public class MoreExpressionIT extends ESIntegTestCase {
client().prepareIndex("test").setId("3").setSource("x", 13, "y", 1.8)
);
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
SearchRequestBuilder req = prepareSearch().setIndices("test");
req.setQuery(QueryBuilders.matchAllQuery())
.addAggregation(
AggregationBuilders.stats("int_agg")
@ -512,7 +512,7 @@ public class MoreExpressionIT extends ESIntegTestCase {
client().prepareIndex("test").setId("3").setSource("text", "hello")
);
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
SearchRequestBuilder req = prepareSearch().setIndices("test");
req.setQuery(QueryBuilders.matchAllQuery())
.addAggregation(
AggregationBuilders.terms("term_agg")

View file

@ -50,12 +50,9 @@ public class StoredExpressionIT extends ESIntegTestCase {
assertThat(e.getCause().getMessage(), containsString("Failed to compile stored script [script1] using lang [expression]"));
}
try {
client().prepareSearch()
.setSource(
new SearchSourceBuilder().scriptField("test1", new Script(ScriptType.STORED, null, "script1", Collections.emptyMap()))
)
.setIndices("test")
.get();
prepareSearch().setSource(
new SearchSourceBuilder().scriptField("test1", new Script(ScriptType.STORED, null, "script1", Collections.emptyMap()))
).setIndices("test").get();
fail("search script should have been rejected");
} catch (Exception e) {
assertThat(e.toString(), containsString("cannot execute scripts using [field] context"));