Fix testQuotedQueryStringWithBoost test (#43385)
Add more logging to indexRandom Seems that asynchronous indexing from indexRandom sometimes indexes the same document twice, which will mess up the expected score calculations. For example, indexing: { "index" : {"_id" : "1" } } {"important" :"phrase match", "less_important": "nothing important"} { "index" : {"_id" : "2" } } {"important" :"nothing important", "less_important" :"phrase match"} Produces the expected scores: 13.8 for doc1, and 1.38 for doc2 indexing: { "index" : {"_id" : "1" } } {"important" :"phrase match", "less_important": "nothing important"} { "index" : {"_id" : "2" } } {"important" :"nothing important", "less_important" :"phrase match"} { "index" : {"_id" : "3" } } {"important" :"phrase match", "less_important": "nothing important"} Produces scores: 9.4 for doc1, and 1.96 for doc2 which are found in the error logs. Relates to #43144
This commit is contained in:
parent
a154f49b94
commit
972a49312c
|
@ -52,6 +52,7 @@ import org.elasticsearch.search.SearchHits;
|
|||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.elasticsearch.test.junit.annotations.TestIssueLogging;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
@ -910,28 +911,23 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
assertFirstHit(searchResponse, hasId("1"));
|
||||
}
|
||||
|
||||
public void testQuotedQueryStringWithBoost() throws InterruptedException, ExecutionException {
|
||||
@TestIssueLogging(value = "org.elasticsearch.search.query.SearchQueryIT:DEBUG",
|
||||
issueUrl = "https://github.com/elastic/elasticsearch/issues/43144")
|
||||
public void testQuotedQueryStringWithBoost() throws InterruptedException {
|
||||
float boost = 10.0f;
|
||||
assertAcked(prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1)));
|
||||
indexRandom(true,
|
||||
client().prepareIndex("test", "type1", "1").setSource("important", "phrase match", "less_important", "nothing important"),
|
||||
client().prepareIndex("test", "type1", "2").setSource("important", "nothing important", "less_important", "phrase match")
|
||||
|
||||
indexRandom(true, false,
|
||||
client().prepareIndex("test", "type1", "1").setSource("important", "phrase match", "less_important", "nothing important"),
|
||||
client().prepareIndex("test", "type1", "2").setSource("important", "nothing important", "less_important", "phrase match")
|
||||
);
|
||||
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(queryStringQuery("\"phrase match\"").field("important", boost).field("less_important")).get();
|
||||
assertHitCount(searchResponse, 2L);
|
||||
assertFirstHit(searchResponse, hasId("1"));
|
||||
assertSecondHit(searchResponse, hasId("2"));
|
||||
assertThat((double)searchResponse.getHits().getAt(0).getScore(), closeTo(boost * searchResponse.getHits().getAt(1).getScore(), .1));
|
||||
|
||||
searchResponse = client().prepareSearch()
|
||||
.setQuery(queryStringQuery("\"phrase match\"").field("important", boost).field("less_important")).get();
|
||||
assertHitCount(searchResponse, 2L);
|
||||
assertFirstHit(searchResponse, hasId("1"));
|
||||
assertSecondHit(searchResponse, hasId("2"));
|
||||
assertThat((double)searchResponse.getHits().getAt(0).getScore(), closeTo(boost * searchResponse.getHits().getAt(1).getScore(), .1));
|
||||
}
|
||||
|
||||
public void testSpecialRangeSyntaxInQueryString() {
|
||||
|
|
|
@ -1452,7 +1452,9 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||
}
|
||||
final List<Exception> actualErrors = new ArrayList<>();
|
||||
for (Tuple<IndexRequestBuilder, Exception> tuple : errors) {
|
||||
if (ExceptionsHelper.unwrapCause(tuple.v2()) instanceof EsRejectedExecutionException) {
|
||||
Throwable t = ExceptionsHelper.unwrapCause(tuple.v2());
|
||||
if (t instanceof EsRejectedExecutionException) {
|
||||
logger.debug("Error indexing doc: " + t.getMessage() + ", reindexing.");
|
||||
tuple.v1().execute().actionGet(); // re-index if rejected
|
||||
} else {
|
||||
actualErrors.add(tuple.v2());
|
||||
|
|
Loading…
Reference in New Issue