Test fix for PinnedQueryBuilderIT (#46187) (#46227)

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 #46174
This commit is contained in:
markharwood 2019-09-02 13:31:22 +01:00 committed by GitHub
parent d68e05aade
commit a9e3871fc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import java.util.Collection;
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;
@ -61,7 +62,7 @@ public class PinnedQueryBuilderIT extends ESIntegTestCase {
.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++) {
@ -101,6 +102,7 @@ public class PinnedQueryBuilderIT extends ESIntegTestCase {
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;