diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/SourceConfirmedTextQuery.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/SourceConfirmedTextQuery.java index 9e1efb34eccce..d132521670dc8 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/SourceConfirmedTextQuery.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/SourceConfirmedTextQuery.java @@ -50,6 +50,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -215,7 +216,9 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo return in.createWeight(searcher, scoreMode, boost); } - final Set terms = new HashSet<>(); + // We use a LinkedHashSet here to preserve the ordering of terms to ensure that + // later summing of float scores per term is consistent + final Set terms = new LinkedHashSet<>(); in.visit(QueryVisitor.termCollector(terms)); if (terms.isEmpty()) { throw new IllegalStateException("Query " + in + " doesn't have any term"); diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/SourceConfirmedTextQueryTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/SourceConfirmedTextQueryTests.java index 45dbb540c3a40..2b8d5870cb8aa 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/SourceConfirmedTextQueryTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/SourceConfirmedTextQueryTests.java @@ -147,7 +147,6 @@ public void testPhrase() throws Exception { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/98712") public void testMultiPhrase() throws Exception { try (Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(Lucene.STANDARD_ANALYZER))) {