Skip to content

Commit

Permalink
Test fix for PinnedQueryBuilderIT (elastic#46187)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markharwood committed Sep 2, 2019
1 parent d68e05a commit 981edc4
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.LinkedHashSet;
import java.util.List;

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

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

long numHits = searchResponse.getHits().getTotalHits().value;
Expand Down

0 comments on commit 981edc4

Please sign in to comment.