Skip to content

Commit 96cbf4f

Browse files
committed
apply review comment
1 parent 49aa013 commit 96cbf4f

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,31 @@ PUT my-index-000004
411411
}
412412
```
413413

414+
To retrieve all fragments from the `semantic` highlighter in their original indexing order
415+
without scoring, use a `match_all` query as the `highlight_query`.
416+
This ensures fragments are returned in the order they appear in the document:
417+
418+
```console
419+
POST test-index/_search
420+
{
421+
"query": {
422+
"ids": {
423+
"values": ["1"]
424+
}
425+
},
426+
"highlight": {
427+
"fields": {
428+
"my_semantic_field": {
429+
"number_of_fragments": 5, <1>
430+
"highlight_query": { "match_all": {} }
431+
}
432+
}
433+
}
434+
}
435+
```
436+
437+
1. Returns the first 5 fragments. Increase this value to retrieve additional fragments.
438+
414439
### Customizing using ingest pipelines [custom-by-pipelines]
415440
```{applies_to}
416441
stack: ga 9.0

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ public List<Object> fetchValues(Source source, int doc, List<Object> ignoredValu
10821082
it.advance(previousParent);
10831083
}
10841084

1085-
return onlyTextChunks ? fetchTextChunks(source, doc, it) : fetchFullChunks(source, doc, it);
1085+
return onlyTextChunks ? fetchTextChunks(source, doc, it) : fetchFullField(source, doc, it);
10861086
}
10871087

10881088
private List<Object> fetchTextChunks(Source source, int doc, DocIdSetIterator it) throws IOException {
@@ -1102,7 +1102,7 @@ private List<Object> fetchTextChunks(Source source, int doc, DocIdSetIterator it
11021102
return chunks;
11031103
}
11041104

1105-
private List<Object> fetchFullChunks(Source source, int doc, DocIdSetIterator it) throws IOException {
1105+
private List<Object> fetchFullField(Source source, int doc, DocIdSetIterator it) throws IOException {
11061106
Map<String, List<SemanticTextField.Chunk>> chunkMap = new LinkedHashMap<>();
11071107

11081108
iterateChildDocs(doc, it, offset -> {

0 commit comments

Comments
 (0)