From 972a49312ca9c342bef47caded5ac1025872468d Mon Sep 17 00:00:00 2001 From: Mayya Sharipova Date: Fri, 19 Jul 2019 12:05:55 -0400 Subject: [PATCH] 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 --- .../search/query/SearchQueryIT.java | 20 ++++++++----------- .../elasticsearch/test/ESIntegTestCase.java | 4 +++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index 7007c7650f4..37688645f1d 100644 --- a/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -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() { diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index 7c2460660a1..1315f4cd6aa 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -1452,7 +1452,9 @@ public abstract class ESIntegTestCase extends ESTestCase { } final List actualErrors = new ArrayList<>(); for (Tuple 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());