Skip to content

Commit f139e85

Browse files
Fix test and update docs
1 parent a6a4623 commit f139e85

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

docs/reference/search/search-your-data/highlighting.asciidoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ max_analyzed_offset:: By default, the maximum number of characters
262262
analyzed for a highlight request is bounded by the value defined in the
263263
<<index-max-analyzed-offset, `index.highlight.max_analyzed_offset`>> setting,
264264
and when the number of characters exceeds this limit an error is returned. If
265-
this setting is set to a non-negative value, the highlighting stops at this defined
265+
this setting is set to a non-negative (>=0) value, the highlighting stops at this defined
266266
maximum limit, and the rest of the text is not processed, thus not highlighted and
267-
no error is returned. The <<max-analyzed-offset, `max_analyzed_offset`>> query setting
267+
no error is returned. If it is set to -1 then the value of
268+
<<index-max-analyzed-offset, `index.highlight.max_analyzed_offset`>> is used instead.
269+
For values <= -1, an error is returned. The <<max-analyzed-offset, `max_analyzed_offset`>> query setting
268270
does *not* override the <<index-max-analyzed-offset, `index.highlight.max_analyzed_offset`>>
269271
which prevails when it's set to lower value than the query setting.
270272

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.highlight/30_max_analyzed_offset.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ setup:
114114
body: {"query" : {"match" : {"field2" : "fox"}}, "highlight" : {"type" : "plain", "fields" : {"field2" : {}}, "max_analyzed_offset": 20}}
115115
- match: {hits.hits.0.highlight.field2.0: "The quick brown <em>fox</em> went to the forest and saw another fox."}
116116

117+
---
118+
"Plain highlighter on a field WITH OFFSETS exceeding index.highlight.max_analyzed_offset with max_analyzed_offset=1 should SUCCEED":
119+
120+
- requires:
121+
cluster_features: ["gte_v7.12.0"]
122+
reason: max_analyzed_offset query param added in 7.12.0
123+
124+
- do:
125+
search:
126+
rest_total_hits_as_int: true
127+
index: test1
128+
body: {"query" : {"match" : {"field2" : "fox"}}, "highlight" : {"type" : "plain", "fields" : {"field2" : {}}, "max_analyzed_offset": 1}}
129+
- match: { hits.hits.0.highlight: null }
130+
117131
---
118132
"Plain highlighter with max_analyzed_offset < -1 should FAIL":
119133

server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlightBuilderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ public void testPreTagsWithoutPostTags() throws IOException {
577577
public void testInvalidMaxAnalyzedOffset() throws IOException {
578578
XContentParseException e = expectParseThrows(
579579
XContentParseException.class,
580-
"{ \"max_analyzed_offset\" : " + randomIntBetween(-100, 0) + "}"
580+
"{ \"max_analyzed_offset\" : " + randomIntBetween(-100, -1) + "}"
581581
);
582582
assertThat(e.getMessage(), containsString("[highlight] failed to parse field [" + MAX_ANALYZED_OFFSET_FIELD.toString() + "]"));
583583
assertThat(e.getCause().getMessage(), containsString("[max_analyzed_offset] must be an integer >= -1"));

0 commit comments

Comments
 (0)