Skip to content

Use ESIntegTestCase#prepareSearch more #101179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,12 @@ public void testUnmapped() throws Exception {
}

public void testPartiallyUnmapped() throws Exception {
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
.addAggregation(
dateHistogram("histo").field("date")
.calendarInterval(DateHistogramInterval.MONTH)
.minDocCount(0)
.subAggregation(new DerivativePipelineAggregationBuilder("deriv", "_count"))
)
.get();
SearchResponse response = prepareSearch("idx", "idx_unmapped").addAggregation(
dateHistogram("histo").field("date")
.calendarInterval(DateHistogramInterval.MONTH)
.minDocCount(0)
.subAggregation(new DerivativePipelineAggregationBuilder("deriv", "_count"))
).get();

assertNoFailures(response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,21 @@ public void testMultiPhraseCutoff() throws IOException {
)
.get();
refresh();
SearchResponse search = client().prepareSearch()
.setQuery(matchPhraseQuery("body", "Test: http://www.facebook.com "))
SearchResponse search = prepareSearch().setQuery(matchPhraseQuery("body", "Test: http://www.facebook.com "))
.highlighter(new HighlightBuilder().field("body").highlighterType("fvh"))
.get();
assertHighlight(search, 0, "body", 0, startsWith("<em>Test: http://www.facebook.com</em>"));
search = client().prepareSearch()
.setQuery(
matchPhraseQuery(
"body",
"Test: http://www.facebook.com "
+ "http://elasticsearch.org http://xing.com http://cnn.com "
+ "http://quora.com http://twitter.com this is a test for highlighting "
+ "feature Test: http://www.facebook.com http://elasticsearch.org "
+ "http://xing.com http://cnn.com http://quora.com http://twitter.com this "
+ "is a test for highlighting feature"
)
search = prepareSearch().setQuery(
matchPhraseQuery(
"body",
"Test: http://www.facebook.com "
+ "http://elasticsearch.org http://xing.com http://cnn.com "
+ "http://quora.com http://twitter.com this is a test for highlighting "
+ "feature Test: http://www.facebook.com http://elasticsearch.org "
+ "http://xing.com http://cnn.com http://quora.com http://twitter.com this "
+ "is a test for highlighting feature"
)
.highlighter(new HighlightBuilder().field("body").highlighterType("fvh"))
.execute()
.actionGet();
).highlighter(new HighlightBuilder().field("body").highlighterType("fvh")).execute().actionGet();
assertHighlight(
search,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private SearchRequestBuilder buildRequest(String script, Object... params) {
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));
Expand Down Expand Up @@ -113,7 +113,7 @@ public void testScore() throws Exception {
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();
Expand All @@ -124,7 +124,7 @@ public void testScore() throws Exception {
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()));
Expand Down Expand Up @@ -466,7 +466,7 @@ public void testSpecialValueVariable() throws Exception {
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")
Expand Down Expand Up @@ -512,7 +512,7 @@ public void testStringSpecialValueVariable() throws Exception {
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ public void testAllOpsDisabledIndexedScripts() throws IOException {
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,26 +1259,20 @@ public void testParentChildCaching() throws Exception {
indicesAdmin().prepareRefresh("test").get();

for (int i = 0; i < 2; i++) {
SearchResponse searchResponse = client().prepareSearch()
.setQuery(
boolQuery().must(matchAllQuery())
.filter(
boolQuery().must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)).must(matchAllQuery())
)
)
.get();
SearchResponse searchResponse = prepareSearch().setQuery(
boolQuery().must(matchAllQuery())
.filter(boolQuery().must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)).must(matchAllQuery()))
).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
}

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

SearchResponse searchResponse = client().prepareSearch()
.setQuery(
boolQuery().must(matchAllQuery())
.filter(boolQuery().must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)).must(matchAllQuery()))
)
.get();
SearchResponse searchResponse = prepareSearch().setQuery(
boolQuery().must(matchAllQuery())
.filter(boolQuery().must(hasChildQuery("child", matchQuery("c_field", "red"), ScoreMode.None)).must(matchAllQuery()))
).get();

assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,12 @@ public void testInnerHitsWithIgnoreUnmapped() {
client().prepareIndex("index2").setId("3").setSource("key", "value").get();
refresh();
assertSearchHitsWithoutFailures(
client().prepareSearch("index1", "index2")
.setQuery(
boolQuery().should(
hasChildQuery("child_type", matchAllQuery(), ScoreMode.None).ignoreUnmapped(true)
.innerHit(new InnerHitBuilder().setIgnoreUnmapped(true))
).should(termQuery("key", "value"))
),
prepareSearch("index1", "index2").setQuery(
boolQuery().should(
hasChildQuery("child_type", matchAllQuery(), ScoreMode.None).ignoreUnmapped(true)
.innerHit(new InnerHitBuilder().setIgnoreUnmapped(true))
).should(termQuery("key", "value"))
),
"1",
"3"
);
Expand Down
Loading