Skip to content

Commit f9c5939

Browse files
committed
Fix Unified highlighter for nested fields when using matchPhrasePrefixQuery
Signed-off-by: sjs004 <simarjeet.singh004@gmail.com>
1 parent a036313 commit f9c5939

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,34 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4848
- Fix IndexOutOfBoundsException when running include/exclude on non-existent prefix in terms aggregations ([#19637](https://github.com/opensearch-project/OpenSearch/pull/19637))
4949
- Fixed assertion unsafe use of ClusterService.state() in ResourceUsageCollectorService ([#19775])(https://github.com/opensearch-project/OpenSearch/pull/19775))
5050
- Add S3Repository.LEGACY_MD5_CHECKSUM_CALCULATION to list of repository-s3 settings ([#19788](https://github.com/opensearch-project/OpenSearch/pull/19788))
51+
- Fix unnecessary refreshes on update preparation failures ([#15261](https://github.com/opensearch-project/OpenSearch/issues/15261))
52+
- Fix NullPointerException in segment replicator ([#18997](https://github.com/opensearch-project/OpenSearch/pull/18997))
53+
- Ensure that plugins that utilize dumpCoverage can write to jacoco.dir when tests.security.manager is enabled ([#18983](https://github.com/opensearch-project/OpenSearch/pull/18983))
54+
- Fix OOM due to large number of shard result buffering ([#19066](https://github.com/opensearch-project/OpenSearch/pull/19066))
55+
- Fix flaky tests in CloseIndexIT by addressing cluster state synchronization issues ([#18878](https://github.com/opensearch-project/OpenSearch/issues/18878))
56+
- [Tiered Caching] Handle query execution exception ([#19000](https://github.com/opensearch-project/OpenSearch/issues/19000))
57+
- Grant access to testclusters dir for tests ([#19085](https://github.com/opensearch-project/OpenSearch/issues/19085))
58+
- Fix assertion error when collapsing search results with concurrent segment search enabled ([#19053](https://github.com/opensearch-project/OpenSearch/pull/19053))
59+
- Fix skip_unavailable setting changing to default during node drop issue ([#18766](https://github.com/opensearch-project/OpenSearch/pull/18766))
60+
- Fix issue with s3-compatible repositories due to missing checksum trailing headers ([#19220](https://github.com/opensearch-project/OpenSearch/pull/19220))
61+
- Add reference count control in NRTReplicationEngine#acquireLastIndexCommit ([#19214](https://github.com/opensearch-project/OpenSearch/pull/19214))
62+
- Fix pull-based ingestion pause state initialization during replica promotion ([#19212](https://github.com/opensearch-project/OpenSearch/pull/19212))
63+
- Fix QueryPhaseResultConsumer incomplete callback loops ([#19231](https://github.com/opensearch-project/OpenSearch/pull/19231))
64+
- Fix the `scaled_float` precision issue ([#19188](https://github.com/opensearch-project/OpenSearch/pull/19188))
65+
- Fix Using an excessively large reindex slice can lead to a JVM OutOfMemoryError on coordinator.([#18964](https://github.com/opensearch-project/OpenSearch/pull/18964))
66+
- Add alias write index policy to control writeIndex during restore([#1511](https://github.com/opensearch-project/OpenSearch/pull/19368))
67+
- [Flaky Test] Fix flaky test in SecureReactorNetty4HttpServerTransportTests with reproducible seed ([#19327](https://github.com/opensearch-project/OpenSearch/pull/19327))
68+
- Remove unnecessary looping in field data cache clear ([#19116](https://github.com/opensearch-project/OpenSearch/pull/19116))
69+
- [Flaky Test] Fix flaky test IngestFromKinesisIT.testAllActiveIngestion ([#19380](https://github.com/opensearch-project/OpenSearch/pull/19380))
70+
- Fix lag metric for pull-based ingestion when streaming source is empty ([#19393](https://github.com/opensearch-project/OpenSearch/pull/19393))
71+
- Fix IntervalQuery flaky test ([#19332](https://github.com/opensearch-project/OpenSearch/pull/19332))
72+
- Fix ingestion state xcontent serialization in IndexMetadata and fail fast on mapping errors([#19320](https://github.com/opensearch-project/OpenSearch/pull/19320))
73+
- Fix updated keyword field params leading to stale responses from request cache ([#19385](https://github.com/opensearch-project/OpenSearch/pull/19385))
74+
- Fix cardinality agg pruning optimization by self collecting ([#19473](https://github.com/opensearch-project/OpenSearch/pull/19473))
75+
- Implement SslHandler retrieval logic for transport-reactor-netty4 plugin ([#19458](https://github.com/opensearch-project/OpenSearch/pull/19458))
76+
- Cache serialised cluster state based on cluster state version and node version.([#19307](https://github.com/opensearch-project/OpenSearch/pull/19307))
77+
- Handle negative search request nodes stats ([#19340](https://github.com/opensearch-project/OpenSearch/pull/19340))
78+
- Fix Unified highlighter for nested fields when using matchPhrasePrefixQuery ([#19442](https://github.com/opensearch-project/OpenSearch/pull/19442))
5179

5280
### Dependencies
5381
- Update to Gradle 9.1 ([#19575](https://github.com/opensearch-project/OpenSearch/pull/19575))

server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/highlight/HighlighterSearchIT.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
import static org.opensearch.index.query.QueryBuilders.constantScoreQuery;
100100
import static org.opensearch.index.query.QueryBuilders.existsQuery;
101101
import static org.opensearch.index.query.QueryBuilders.fuzzyQuery;
102+
import static org.opensearch.index.query.QueryBuilders.matchPhrasePrefixQuery;
102103
import static org.opensearch.index.query.QueryBuilders.matchPhraseQuery;
103104
import static org.opensearch.index.query.QueryBuilders.matchQuery;
104105
import static org.opensearch.index.query.QueryBuilders.multiMatchQuery;
@@ -3518,7 +3519,7 @@ public void testWithNestedQuery() throws Exception {
35183519
jsonBuilder().startObject()
35193520
.startArray("foo")
35203521
.startObject()
3521-
.field("text", "brown")
3522+
.field("text", "brown cat")
35223523
.endObject()
35233524
.startObject()
35243525
.field("text", "cow")
@@ -3539,7 +3540,7 @@ public void testWithNestedQuery() throws Exception {
35393540
assertHitCount(searchResponse, 1);
35403541
HighlightField field = searchResponse.getHits().getAt(0).getHighlightFields().get("foo.text");
35413542
assertThat(field.getFragments().length, equalTo(2));
3542-
assertThat(field.getFragments()[0].string(), equalTo("<em>brown</em>"));
3543+
assertThat(field.getFragments()[0].string(), equalTo("<em>brown</em> cat"));
35433544
assertThat(field.getFragments()[1].string(), equalTo("<em>cow</em>"));
35443545

35453546
searchResponse = client().prepareSearch()
@@ -3549,16 +3550,25 @@ public void testWithNestedQuery() throws Exception {
35493550
assertHitCount(searchResponse, 1);
35503551
field = searchResponse.getHits().getAt(0).getHighlightFields().get("foo.text");
35513552
assertThat(field.getFragments().length, equalTo(1));
3552-
assertThat(field.getFragments()[0].string(), equalTo("<em>brown</em>"));
3553+
assertThat(field.getFragments()[0].string(), equalTo("<em>brown</em> cat"));
35533554

35543555
searchResponse = client().prepareSearch()
3555-
.setQuery(nestedQuery("foo", prefixQuery("foo.text", "bro"), ScoreMode.None))
3556-
.highlighter(new HighlightBuilder().field(new Field("foo.text").highlighterType("plain")))
3556+
.setQuery(nestedQuery("foo", matchPhraseQuery("foo.text", "brown cat"), ScoreMode.None))
3557+
.highlighter(new HighlightBuilder().field(new Field("foo.text").highlighterType(type)))
35573558
.get();
35583559
assertHitCount(searchResponse, 1);
35593560
field = searchResponse.getHits().getAt(0).getHighlightFields().get("foo.text");
35603561
assertThat(field.getFragments().length, equalTo(1));
3561-
assertThat(field.getFragments()[0].string(), equalTo("<em>brown</em>"));
3562+
assertThat(field.getFragments()[0].string(), equalTo("<em>brown</em> <em>cat</em>"));
3563+
3564+
searchResponse = client().prepareSearch()
3565+
.setQuery(nestedQuery("foo", matchPhrasePrefixQuery("foo.text", "bro"), ScoreMode.None))
3566+
.highlighter(new HighlightBuilder().field(new Field("foo.text").highlighterType(type)))
3567+
.get();
3568+
assertHitCount(searchResponse, 1);
3569+
field = searchResponse.getHits().getAt(0).getHighlightFields().get("foo.text");
3570+
assertThat(field.getFragments().length, equalTo(1));
3571+
assertThat(field.getFragments()[0].string(), equalTo("<em>brown</em> cat"));
35623572
}
35633573

35643574
// For unified and fvh highlighters we just check that the nested query is correctly extracted

server/src/main/java/org/opensearch/lucene/search/uhighlight/CustomUnifiedHighlighter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.opensearch.common.Nullable;
5353
import org.opensearch.common.lucene.search.MultiPhrasePrefixQuery;
5454
import org.opensearch.index.IndexSettings;
55+
import org.opensearch.index.search.OpenSearchToParentBlockJoinQuery;
5556

5657
import java.io.IOException;
5758
import java.text.BreakIterator;
@@ -262,6 +263,8 @@ private Collection<Query> rewriteCustomQuery(Query query) {
262263
// if original slop is 0 then require inOrder
263264
boolean inorder = (mpq.getSlop() == 0);
264265
return Collections.singletonList(new SpanNearQuery(positionSpanQueries, mpq.getSlop() + positionGaps, inorder));
266+
} else if (query instanceof OpenSearchToParentBlockJoinQuery) {
267+
return Collections.singletonList(((OpenSearchToParentBlockJoinQuery) query).getChildQuery());
265268
} else {
266269
return null;
267270
}

0 commit comments

Comments
 (0)