Skip to content

Commit 981edc4

Browse files
committed
Test fix for PinnedQueryBuilderIT (elastic#46187)
Fix test issue to stabilise scoring through use of DFS search mode. Randomised index-then-delete docs introduced by the test framework likely caused an imbalance in IDF scores across shards. Also made number of shards used in test a random number for added test coverage. Closes elastic#46174
1 parent d68e05a commit 981edc4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.LinkedHashSet;
2424
import java.util.List;
2525

26+
import static org.elasticsearch.action.search.SearchType.DFS_QUERY_THEN_FETCH;
2627
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
2728
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
2829
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFirstHit;
@@ -61,7 +62,7 @@ public void testPinnedPromotions() throws Exception {
6162
.addMapping("type1",
6263
jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1")
6364
.field("analyzer", "whitespace").field("type", "text").endObject().endObject().endObject().endObject())
64-
.setSettings(Settings.builder().put(indexSettings()).put("index.number_of_shards", 2)));
65+
.setSettings(Settings.builder().put(indexSettings()).put("index.number_of_shards", randomIntBetween(2, 5))));
6566

6667
int numRelevantDocs = randomIntBetween(1, 100);
6768
for (int i = 0; i < numRelevantDocs; i++) {
@@ -101,6 +102,7 @@ public void testPinnedPromotions() throws Exception {
101102
int from = randomIntBetween(0, numRelevantDocs);
102103
int size = randomIntBetween(10, 100);
103104
SearchResponse searchResponse = client().prepareSearch().setQuery(pqb).setTrackTotalHits(true).setSize(size).setFrom(from)
105+
.setSearchType(DFS_QUERY_THEN_FETCH)
104106
.get();
105107

106108
long numHits = searchResponse.getHits().getTotalHits().value;

0 commit comments

Comments
 (0)