From fe3bd8613e8b704f39f8ac3d79e5fb3095d3d4e6 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Wed, 24 Apr 2024 12:10:39 +0100 Subject: [PATCH] fix failing tests --- rest-api-spec/build.gradle | 1 - .../search/functionscore/QueryRescorerIT.java | 15 +++++++++++---- x-pack/qa/runtime-fields/build.gradle | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index 089b7470e9a97..146c78e3c8471 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -83,7 +83,6 @@ tasks.named("yamlRestTestV7CompatTransform").configure { task -> task.skipTest("search/370_profile/fetch source", "profile output has changed") task.skipTest("search/370_profile/fetch nested source", "profile output has changed") task.skipTest("search/240_date_nanos/doc value fields are working as expected across date and date_nanos fields", "Fetching docvalues field multiple times is no longer allowed") - task.skipTest("search/110_field_collapsing/field collapsing and rescore", "#107779 Field collapsing is compatible with rescore in 8.15") task.replaceValueInMatch("_type", "_doc") task.addAllowedWarningRegex("\\[types removal\\].*") diff --git a/server/src/internalClusterTest/java/org/elasticsearch/search/functionscore/QueryRescorerIT.java b/server/src/internalClusterTest/java/org/elasticsearch/search/functionscore/QueryRescorerIT.java index d82c4a212ad35..bdfe5c7dc36b5 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/search/functionscore/QueryRescorerIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/search/functionscore/QueryRescorerIT.java @@ -927,6 +927,11 @@ public void testRescoreAfterCollapseRandom() throws Exception { float bestScore = groups[group] == null ? -1 : groups[group].firstPassScore; var groupDoc = new GroupDoc(id, Integer.toString(group), firstPassScore, secondPassScore, shouldFilter); if (shouldFilter == false) { + if (firstPassScore == bestScore) { + // avoid tiebreaker + continue; + } + numHits++; if (firstPassScore > bestScore) { groups[group] = groupDoc; @@ -952,12 +957,14 @@ public void testRescoreAfterCollapseRandom() throws Exception { GroupDoc[] sortedGroups = Arrays.stream(groups) .filter(g -> g != null) - .sorted(Comparator.comparingDouble(GroupDoc::secondPassScore)) + .sorted(Comparator.comparingDouble(GroupDoc::secondPassScore).reversed()) .toArray(GroupDoc[]::new); var request = client().prepareSearch("test") .setQuery(fieldValueScoreQuery("firstPassScore")) - .addRescorer(new QueryRescorerBuilder(fieldValueScoreQuery("secondPassScore")).windowSize(numGroups)) + .addRescorer(new QueryRescorerBuilder(fieldValueScoreQuery("secondPassScore")) + .setQueryWeight(0f) + .windowSize(numGroups)) .setCollapse(new CollapseBuilder("group")) .setSize(Math.min(numGroups, 10)); long expectedNumHits = numHits; @@ -965,8 +972,8 @@ public void testRescoreAfterCollapseRandom() throws Exception { assertThat(resp.getHits().getTotalHits().value, equalTo(expectedNumHits)); for (int pos = 0; pos < resp.getHits().getHits().length; pos++) { SearchHit hit = resp.getHits().getAt(pos); - assertThat(hit.getId(), equalTo(groups[pos].id())); - int group = Integer.valueOf(hit.field("group").getValue()); + assertThat(hit.getId(), equalTo(sortedGroups[pos].id())); + String group = hit.field("group").getValue(); assertThat(group, equalTo(sortedGroups[pos].group())); assertThat(hit.getScore(), equalTo(sortedGroups[pos].secondPassScore)); } diff --git a/x-pack/qa/runtime-fields/build.gradle b/x-pack/qa/runtime-fields/build.gradle index dd7d0abc24b19..0c7d4ee770ee6 100644 --- a/x-pack/qa/runtime-fields/build.gradle +++ b/x-pack/qa/runtime-fields/build.gradle @@ -73,6 +73,7 @@ subprojects { 'aggregations/range/Date range', //source only date field should also emit values for numbers, it expects strings only 'search/115_multiple_field_collapsing/two levels fields collapsing', // Field collapsing on a runtime field does not work 'search/111_field_collapsing_with_max_score/*', // Field collapsing on a runtime field does not work + 'search/112_field_collapsing_with_rescore/*', // Field collapsing on a runtime field does not work 'field_caps/30_index_filter/Field caps with index filter', // We don't support filtering field caps on runtime fields. What should we do? 'search/350_point_in_time/point-in-time with index filter', // We don't support filtering pit on runtime fields. 'aggregations/filters_bucket/cache busting', // runtime keyword does not support split_queries_on_whitespace