Skip to content

Commit c1cd8bd

Browse files
authored
Clarify highlighting docs for semantic_text and interacting with chunks (#131871) (#132072)
(cherry picked from commit b3510c1)
1 parent 4697b96 commit c1cd8bd

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

docs/reference/elasticsearch/mapping-reference/semantic-text.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,34 @@ POST test-index/_search
144144
```
145145

146146
1. Specifies the maximum number of fragments to return.
147-
2. Sorts highlighted fragments by score when set to `score`. By default, fragments will be output in the order they appear in the field (order: none).
147+
2. Sorts the most relevant highlighted fragments by score when set to `score`. By default,
148+
fragments will be output in the order they appear in the field (order: none).
148149

150+
To use the `semantic` highlighter to view chunks in the order which they were indexed with no scoring,
151+
use the `match_all` query to retrieve them in the order they appear in the document:
149152

150-
Highlighting is supported on fields other than semantic_text. However, if you want to restrict highlighting to the semantic highlighter and return no fragments when the field is not of type semantic_text, you can explicitly enforce the `semantic` highlighter in the query:
153+
```console
154+
POST test-index/_search
155+
{
156+
"query": {
157+
"match_all": {}
158+
},
159+
"highlight": {
160+
"fields": {
161+
"my_semantic_field": {
162+
"number_of_fragments": 5 <1>
163+
}
164+
}
165+
}
166+
}
167+
```
168+
169+
1. This will return the first 5 chunks, set this number higher to retrieve more chunks.
170+
171+
Highlighting is supported on fields other than semantic_text. However, if you
172+
want to restrict highlighting to the semantic highlighter and return no
173+
fragments when the field is not of type semantic_text, you can explicitly
174+
enforce the `semantic` highlighter in the query:
151175

152176
```console
153177
PUT test-index

docs/reference/elasticsearch/rest-apis/highlighting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ applies_to:
77

88
# Highlighting [highlighting]
99

10-
Highlighters enable you to get highlighted snippets from one or more fields in your search results so you can show users where the query matches are. When you request highlights, the response contains an additional `highlight` element for each search hit that includes the highlighted fields and the highlighted fragments.
10+
Highlighters enable you to retrieve the best-matching highlighted snippets from one or more fields in your search results so you can show users where the query matches are. When you request highlights, the response contains an additional `highlight` element for each search hit that includes the highlighted fields and the highlighted fragments.
1111

1212
::::{note}
1313
Highlighters don’t reflect the boolean logic of a query when extracting terms to highlight. Thus, for some complex boolean queries (e.g nested boolean queries, queries using `minimum_should_match` etc.), parts of documents may be highlighted that don’t correspond to query matches.

0 commit comments

Comments
 (0)