diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c3ba3fa0875..e3c11f0ef4a29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix GRPC AUX_TRANSPORT_PORT and SETTING_GRPC_PORT settings and remove lingering HTTP terminology ([#17037](https://github.com/opensearch-project/OpenSearch/pull/17037)) - [WLM] Fix the QueryGroupTask logging bug ([#17169](https://github.com/opensearch-project/OpenSearch/pull/17169)) - Use OpenSearch version to deserialize remote custom metadata([#16494](https://github.com/opensearch-project/OpenSearch/pull/16494)) +- Add highlighting for wildcard search on `match_only_text` field ([#17101](https://github.com/opensearch-project/OpenSearch/pull/17101)) - Fix the failing CI's with `Failed to load eclipse jdt formatter` error ([#17172](https://github.com/opensearch-project/OpenSearch/pull/17172)) - Fix AutoDateHistogramAggregator rounding assertion failure ([#17023](https://github.com/opensearch-project/OpenSearch/pull/17023)) diff --git a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/11_match_field_match_only_text.yml b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/11_match_field_match_only_text.yml index 140d70414a4a7..b891c5496ac65 100644 --- a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/11_match_field_match_only_text.yml +++ b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/11_match_field_match_only_text.yml @@ -1,5 +1,5 @@ # integration tests for queries with specific analysis chains - +--- "match query with stacked stems": - skip: version: " - 2.11.99" @@ -68,3 +68,80 @@ query: fox runs operator: AND - match: {hits.total: 2} + +--- +"wildcard highlighting on match_only_text": + - skip: + version: " - 2.99.99" + reason: "wildcard highlighting on match_only_text type was added in 2.19" + - do: + indices.create: + index: test + body: + settings: + number_of_shards: 1 + number_of_replicas: 1 + analysis: + analyzer: + index: + tokenizer: standard + filter: [lowercase] + search: + rest_total_hits_as_int: true + tokenizer: standard + filter: [lowercase, keyword_repeat, porter_stem, unique_stem] + filter: + unique_stem: + type: unique + only_on_same_position: true + mappings: + properties: + text: + type: match_only_text + analyzer: index + search_analyzer: search + + - do: + index: + index: test + id: 1 + body: { "text": "the fox runs across the street" } + refresh: true + + - do: + search: + rest_total_hits_as_int: true + body: + query: + match: + text: + query: fox runs + operator: AND + highlight: + fields: + - text: {} + - match: {hits.total: 1} + - match: {hits.hits.0.highlight.text.0: "the fox runs across the street"} + + - do: + index: + index: test + id: 2 + body: { "text": "run fox run" } + refresh: true + + - do: + search: + rest_total_hits_as_int: true + body: + query: + match: + text: + query: fox runs + operator: AND + highlight: + fields: + - text: {} + - match: {hits.total: 2} + - match: {hits.hits.0.highlight.text.0: "the fox runs across the street"} + - match: {hits.hits.1.highlight.text.0: "run fox run"} diff --git a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/30_ngram_highligthing.yml b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/30_ngram_highlighting.yml similarity index 100% rename from modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/30_ngram_highligthing.yml rename to modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/30_ngram_highlighting.yml diff --git a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/30_ngram_highligthing_field_match_only_text.yml b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/30_ngram_highlighting_field_match_only_text.yml similarity index 100% rename from modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/30_ngram_highligthing_field_match_only_text.yml rename to modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/search.query/30_ngram_highlighting_field_match_only_text.yml diff --git a/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/HighlightPhase.java b/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/HighlightPhase.java index 41a7e9934fc4d..22b6948ab4ec1 100644 --- a/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/HighlightPhase.java +++ b/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/HighlightPhase.java @@ -37,6 +37,7 @@ import org.opensearch.common.regex.Regex; import org.opensearch.index.mapper.KeywordFieldMapper; import org.opensearch.index.mapper.MappedFieldType; +import org.opensearch.index.mapper.MatchOnlyTextFieldMapper; import org.opensearch.index.mapper.SourceFieldMapper; import org.opensearch.index.mapper.TextFieldMapper; import org.opensearch.search.fetch.FetchContext; @@ -152,7 +153,8 @@ private Map> contextBuilders continue; } - // We should prevent highlighting if a field is anything but a text or keyword field. + // We should prevent highlighting if a field is anything but a text, match_only_text + // or keyword field. // However, someone might implement a custom field type that has text and still want to // highlight on that. We cannot know in advance if the highlighter will be able to // highlight such a field and so we do the following: @@ -162,7 +164,8 @@ private Map> contextBuilders // what they were doing and try to highlight anyway. if (fieldNameContainsWildcards) { if (fieldType.typeName().equals(TextFieldMapper.CONTENT_TYPE) == false - && fieldType.typeName().equals(KeywordFieldMapper.CONTENT_TYPE) == false) { + && fieldType.typeName().equals(KeywordFieldMapper.CONTENT_TYPE) == false + && fieldType.typeName().equals(MatchOnlyTextFieldMapper.CONTENT_TYPE) == false) { continue; } if (highlighter.canHighlight(fieldType) == false) {