Skip to content

Conversation

svilen-mihaylov-elastic
Copy link
Contributor

@svilen-mihaylov-elastic svilen-mihaylov-elastic commented Dec 17, 2024

Add ability to set "max_analyzed_offet" implicitly to "index.highlight
.max_analyzed_offset", by setting it excplicitly to "-1".

Closes #112822

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.0.0 labels Dec 17, 2024
@svilen-mihaylov-elastic svilen-mihaylov-elastic force-pushed the svilen-mihaylov/112822 branch 3 times, most recently from 0f3e7c9 to cdc01a6 Compare December 18, 2024 15:37
@svilen-mihaylov-elastic svilen-mihaylov-elastic changed the title Add ability to set "max_analyzed_offet" implicitly to "index.highlight Add ability to set "max_analyzed_offset" implicitly to "index.highlight Dec 18, 2024
@svilen-mihaylov-elastic svilen-mihaylov-elastic force-pushed the svilen-mihaylov/112822 branch 4 times, most recently from 8fe10d5 to 11e82d3 Compare December 18, 2024 20:51
.max_analyzed_offset", by setting it excplicitly to "-1".
@svilen-mihaylov-elastic svilen-mihaylov-elastic added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Dec 18, 2024
@elasticsearchmachine elasticsearchmachine removed the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Dec 18, 2024
@svilen-mihaylov-elastic svilen-mihaylov-elastic added :Search Relevance/Suggesters "Did you mean" and suggestions as you type Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch labels Dec 18, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Dec 18, 2024
Copy link
Contributor

@john-wagster john-wagster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I agree (based on our discussion earlier today) some additional testing would be good. So probably worth a +1 from Mayya when she returns. Probably worth backporting this to v8.18.0 as well; I've thrown that label on the PR and thrown on the auto-back label for when you merge this. Feel free to take those off if you have questions or concerns for any reason.

@john-wagster john-wagster added v8.18.0 auto-backport Automatically create backport pull requests when merged labels Dec 19, 2024
public void testMaxQueryOffsetDefault() throws Exception {
assertAcked(
prepareCreate("test").setMapping(type1PostingsffsetsMapping())
.setSettings(Settings.builder().put("index.highlight.max_analyzed_offset", "10").build())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observe index offset is 10

logger.info("--> highlighting and searching on field1");
// Specific for this test: by passing "-1" as "maxAnalyzedOffset", the index highlight setting above will be used.
SearchSourceBuilder source = searchSource().query(termQuery("field1", "sentence"))
.highlighter(highlight().field("field1").order("score").maxAnalyzedOffset(-1));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observe query offset is -1

assertThat(field1.fragments().length, equalTo(1));
assertThat(
field1.fragments()[0].string(),
equalTo("This <em>sentence</em> contains one match, not that short. This sentence contains zero sentence matches.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observe only one match

no error is returned. The <<max-analyzed-offset, `max_analyzed_offset`>> query setting
no error is returned. If it is set to -1 then the value of
<<index-max-analyzed-offset, `index.highlight.max_analyzed_offset`>> is used instead.
For values <= -1, an error is returned. The <<max-analyzed-offset, `max_analyzed_offset`>> query setting
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting here doesnt seem affected by spotlessApply, is there another tool to lint?

@svilen-mihaylov-elastic
Copy link
Contributor Author

Looking at the CI tests, it looks like the backwards compatibility tests are failing since I've changed the exception message (https://buildkite.com/elastic/elasticsearch-pull-request/builds/48659#0194292d-5312-4ee2-a6f2-a3217e270df8). Also more generally we do not throw when the value is -1 now. This seems to be running against some older branch....

What would be the way to handle this? Should we backport this commit?

Copy link
Contributor

@mayya-sharipova mayya-sharipova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svilen-mihaylov-elastic Thanks for a great work!

@svilen-mihaylov-elastic
Copy link
Contributor Author

@elasticsearchmachine test this please

1 similar comment
@svilen-mihaylov-elastic
Copy link
Contributor Author

@elasticsearchmachine test this please

@svilen-mihaylov-elastic svilen-mihaylov-elastic merged commit 93c349c into main Jan 7, 2025
17 checks passed
@svilen-mihaylov-elastic svilen-mihaylov-elastic deleted the svilen-mihaylov/112822 branch January 7, 2025 16:19
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 118895

svilen-mihaylov-elastic added a commit to svilen-mihaylov-elastic/elasticsearch that referenced this pull request Jan 30, 2025
…ht (elastic#118895)

Add ability to set "max_analyzed_offet" implicitly to "index.highlight
.max_analyzed_offset", by setting it excplicitly to "-1".

Closes elastic#112822

(cherry picked from commit 93c349c)
@svilen-mihaylov-elastic
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.18

Questions ?

Please refer to the Backport tool documentation

elasticsearchmachine pushed a commit that referenced this pull request Jan 30, 2025
…ht (#118895) (#121323)

Add ability to set "max_analyzed_offet" implicitly to "index.highlight
.max_analyzed_offset", by setting it excplicitly to "-1".

Closes #112822

(cherry picked from commit 93c349c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged backport pending >enhancement :Search Relevance/Highlighting How a query matched a document Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set highlight parameter max_analyzed_offet to index.highlight.max_analyzed_offset

4 participants