Skip to content

Commit 9794c6e

Browse files
authored
Use ESIntegTestCase#prepareSearch more (#101179)
The refactoring in #101175 only covered all the one-arg call sites. This PR does the rest.
1 parent 1521484 commit 9794c6e

File tree

102 files changed

+974
-1527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+974
-1527
lines changed

modules/aggregations/src/internalClusterTest/java/org/elasticsearch/aggregations/pipeline/DateDerivativeIT.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,12 @@ public void testUnmapped() throws Exception {
555555
}
556556

557557
public void testPartiallyUnmapped() throws Exception {
558-
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
559-
.addAggregation(
560-
dateHistogram("histo").field("date")
561-
.calendarInterval(DateHistogramInterval.MONTH)
562-
.minDocCount(0)
563-
.subAggregation(new DerivativePipelineAggregationBuilder("deriv", "_count"))
564-
)
565-
.get();
558+
SearchResponse response = prepareSearch("idx", "idx_unmapped").addAggregation(
559+
dateHistogram("histo").field("date")
560+
.calendarInterval(DateHistogramInterval.MONTH)
561+
.minDocCount(0)
562+
.subAggregation(new DerivativePipelineAggregationBuilder("deriv", "_count"))
563+
).get();
566564

567565
assertNoFailures(response);
568566

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/HighlighterWithAnalyzersTests.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,21 @@ public void testMultiPhraseCutoff() throws IOException {
158158
)
159159
.get();
160160
refresh();
161-
SearchResponse search = client().prepareSearch()
162-
.setQuery(matchPhraseQuery("body", "Test: http://www.facebook.com "))
161+
SearchResponse search = prepareSearch().setQuery(matchPhraseQuery("body", "Test: http://www.facebook.com "))
163162
.highlighter(new HighlightBuilder().field("body").highlighterType("fvh"))
164163
.get();
165164
assertHighlight(search, 0, "body", 0, startsWith("<em>Test: http://www.facebook.com</em>"));
166-
search = client().prepareSearch()
167-
.setQuery(
168-
matchPhraseQuery(
169-
"body",
170-
"Test: http://www.facebook.com "
171-
+ "http://elasticsearch.org http://xing.com http://cnn.com "
172-
+ "http://quora.com http://twitter.com this is a test for highlighting "
173-
+ "feature Test: http://www.facebook.com http://elasticsearch.org "
174-
+ "http://xing.com http://cnn.com http://quora.com http://twitter.com this "
175-
+ "is a test for highlighting feature"
176-
)
165+
search = prepareSearch().setQuery(
166+
matchPhraseQuery(
167+
"body",
168+
"Test: http://www.facebook.com "
169+
+ "http://elasticsearch.org http://xing.com http://cnn.com "
170+
+ "http://quora.com http://twitter.com this is a test for highlighting "
171+
+ "feature Test: http://www.facebook.com http://elasticsearch.org "
172+
+ "http://xing.com http://cnn.com http://quora.com http://twitter.com this "
173+
+ "is a test for highlighting feature"
177174
)
178-
.highlighter(new HighlightBuilder().field("body").highlighterType("fvh"))
179-
.execute()
180-
.actionGet();
175+
).highlighter(new HighlightBuilder().field("body").highlighterType("fvh")).execute().actionGet();
181176
assertHighlight(
182177
search,
183178
0,

modules/lang-expression/src/internalClusterTest/java/org/elasticsearch/script/expression/MoreExpressionIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private SearchRequestBuilder buildRequest(String script, Object... params) {
6666
paramsMap.put(params[i].toString(), params[i + 1]);
6767
}
6868

69-
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
69+
SearchRequestBuilder req = prepareSearch().setIndices("test");
7070
req.setQuery(QueryBuilders.matchAllQuery())
7171
.addSort(SortBuilders.fieldSort("id").order(SortOrder.ASC).unmappedType("long"))
7272
.addScriptField("foo", new Script(ScriptType.INLINE, "expression", script, paramsMap));
@@ -113,7 +113,7 @@ public void testScore() throws Exception {
113113
ScriptScoreFunctionBuilder score = ScoreFunctionBuilders.scriptFunction(
114114
new Script(ScriptType.INLINE, "expression", "1 / _score", Collections.emptyMap())
115115
);
116-
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
116+
SearchRequestBuilder req = prepareSearch().setIndices("test");
117117
req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode(CombineFunction.REPLACE));
118118
req.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); // make sure DF is consistent
119119
SearchResponse rsp = req.get();
@@ -124,7 +124,7 @@ public void testScore() throws Exception {
124124
assertEquals("3", hits.getAt(1).getId());
125125
assertEquals("2", hits.getAt(2).getId());
126126

127-
req = client().prepareSearch().setIndices("test");
127+
req = prepareSearch().setIndices("test");
128128
req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode(CombineFunction.REPLACE));
129129
score = ScoreFunctionBuilders.scriptFunction(new Script(ScriptType.INLINE, "expression", "1 / _score", Collections.emptyMap()));
130130
req.addAggregation(AggregationBuilders.max("max_score").script((score).getScript()));
@@ -466,7 +466,7 @@ public void testSpecialValueVariable() throws Exception {
466466
client().prepareIndex("test").setId("3").setSource("x", 13, "y", 1.8)
467467
);
468468

469-
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
469+
SearchRequestBuilder req = prepareSearch().setIndices("test");
470470
req.setQuery(QueryBuilders.matchAllQuery())
471471
.addAggregation(
472472
AggregationBuilders.stats("int_agg")
@@ -512,7 +512,7 @@ public void testStringSpecialValueVariable() throws Exception {
512512
client().prepareIndex("test").setId("3").setSource("text", "hello")
513513
);
514514

515-
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
515+
SearchRequestBuilder req = prepareSearch().setIndices("test");
516516
req.setQuery(QueryBuilders.matchAllQuery())
517517
.addAggregation(
518518
AggregationBuilders.terms("term_agg")

modules/lang-expression/src/internalClusterTest/java/org/elasticsearch/script/expression/StoredExpressionIT.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ public void testAllOpsDisabledIndexedScripts() throws IOException {
5050
assertThat(e.getCause().getMessage(), containsString("Failed to compile stored script [script1] using lang [expression]"));
5151
}
5252
try {
53-
client().prepareSearch()
54-
.setSource(
55-
new SearchSourceBuilder().scriptField("test1", new Script(ScriptType.STORED, null, "script1", Collections.emptyMap()))
56-
)
57-
.setIndices("test")
58-
.get();
53+
prepareSearch().setSource(
54+
new SearchSourceBuilder().scriptField("test1", new Script(ScriptType.STORED, null, "script1", Collections.emptyMap()))
55+
).setIndices("test").get();
5956
fail("search script should have been rejected");
6057
} catch (Exception e) {
6158
assertThat(e.toString(), containsString("cannot execute scripts using [field] context"));

modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/query/ChildQuerySearchIT.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,26 +1259,20 @@ public void testParentChildCaching() throws Exception {
12591259
indicesAdmin().prepareRefresh("test").get();
12601260

12611261
for (int i = 0; i < 2; i++) {
1262-
SearchResponse searchResponse = client().prepareSearch()
1263-
.setQuery(
1264-
boolQuery().must(matchAllQuery())
1265-
.filter(
1266-
boolQuery().must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)).must(matchAllQuery())
1267-
)
1268-
)
1269-
.get();
1262+
SearchResponse searchResponse = prepareSearch().setQuery(
1263+
boolQuery().must(matchAllQuery())
1264+
.filter(boolQuery().must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)).must(matchAllQuery()))
1265+
).get();
12701266
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
12711267
}
12721268

12731269
createIndexRequest("test", "child", "c3", "p2", "c_field", "blue").get();
12741270
indicesAdmin().prepareRefresh("test").get();
12751271

1276-
SearchResponse searchResponse = client().prepareSearch()
1277-
.setQuery(
1278-
boolQuery().must(matchAllQuery())
1279-
.filter(boolQuery().must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)).must(matchAllQuery()))
1280-
)
1281-
.get();
1272+
SearchResponse searchResponse = prepareSearch().setQuery(
1273+
boolQuery().must(matchAllQuery())
1274+
.filter(boolQuery().must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)).must(matchAllQuery()))
1275+
).get();
12821276

12831277
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
12841278
}

modules/parent-join/src/internalClusterTest/java/org/elasticsearch/join/query/InnerHitsIT.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,12 @@ public void testInnerHitsWithIgnoreUnmapped() {
590590
client().prepareIndex("index2").setId("3").setSource("key", "value").get();
591591
refresh();
592592
assertSearchHitsWithoutFailures(
593-
client().prepareSearch("index1", "index2")
594-
.setQuery(
595-
boolQuery().should(
596-
hasChildQuery("child_type", matchAllQuery(), ScoreMode.None).ignoreUnmapped(true)
597-
.innerHit(new InnerHitBuilder().setIgnoreUnmapped(true))
598-
).should(termQuery("key", "value"))
599-
),
593+
prepareSearch("index1", "index2").setQuery(
594+
boolQuery().should(
595+
hasChildQuery("child_type", matchAllQuery(), ScoreMode.None).ignoreUnmapped(true)
596+
.innerHit(new InnerHitBuilder().setIgnoreUnmapped(true))
597+
).should(termQuery("key", "value"))
598+
),
600599
"1",
601600
"3"
602601
);

0 commit comments

Comments
 (0)