Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #321: fix highlight max_analyzer_offset field name to match OS 2.2.0 #322

Merged
merged 4 commits into from
Aug 20, 2023

Conversation

gjunge
Copy link
Contributor

@gjunge gjunge commented Aug 17, 2023

Fix field max_analyzed_offset to max_analyzer_offset

Description

The current field max_analyzed_offset used in ElasticSearch doesn't match the field added to OpenSearch version 2.2.0, max_analyzer_offset.
This means the current client implementation have two problems:

It doesn't work for versions before version 2.2.0, because no equivalent field exist on OpenSearch.
It doesn't work for version after 2.2.0, because the field is misspelled.

Even though the Property changes, which is normally a breaking change, since the current field is unusable, this change is not "breaking" anything.

For further information see:

Issues Resolved:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@gjunge gjunge force-pushed the issue-321 branch 2 times, most recently from 9ce7ea2 to d998073 Compare August 17, 2023 10:38
@gjunge gjunge marked this pull request as ready for review August 17, 2023 10:39
@Yury-Fridlyand
Copy link
Collaborator

Can you add a unit and/or integration test please?

@gjunge
Copy link
Contributor Author

gjunge commented Aug 18, 2023

Can you add a unit and/or integration test please?

I have extended the existing Highlighting unit test. Have to say, was working a little blindly, since I was not able to get these tests running.

@Yury-Fridlyand
Copy link
Collaborator

You have to add a switch or keep both options, because this .Net client should work with all OpenSearch versions.
As you can see from CI, all IT failed on pre 2.2 versions:

[xUnit.net 00:01:16.42]     Tests.Search.Request.HighlightingUsageTests.ReturnsExpectedIsValid [FAIL]
  Failed Tests.Search.Request.HighlightingUsageTests.ReturnsExpectedIsValid [798 ms]
  Error Message:
   Tests.Framework.EndpointTests.ResponseAssertionException : Expected response.IsValid to be True because Invalid OpenSearch.Client response built from a unsuccessful (400) low level call on POST: /project/_search?pretty=true&error_trace=true&typed_keys=true
# Audit trail of this API call:
 - [1] BadResponse: Node: https://localhost:9200/ Took: 00:00:00.1518266
# OriginalException: OpenSearch.Net.OpenSearchClientException: Request failed to execute. Call: Status code 400 from: POST /project/_search?pretty=true&error_trace=true&typed_keys=true. ServerError: Type: x_content_parse_exception Reason: "[1:675] [highlight] unknown field [max_analyzer_offset]"
# Request:
{"highlight":{"encoder":"html","fields":{"name.standard":{"force_source":true,"fragmenter":"span","fragment_size":150,"no_match_size":150,"number_of_fragments":3,"type":"plain"},"leadDeveloper.firstName":{"boundary_max_scan":50,"highlight_query":{"match":{"leadDeveloper.firstName":{"query":"Kurt Edgardo Naomi Dariana Justice Felton"}}},"phrase_limit":10,"post_tags":["</name>"],"pre_tags":["<name>"],"type":"fvh"},"leadDeveloper.lastName":{"highlight_query":{"match":{"leadDeveloper.lastName":{"query":"Mante"}}},"post_tags":["</name>"],"pre_tags":["<name>"],"type":"unified"}},"highlight_query":{"match":{"name.standard":{"query":"Upton Sons Shield Rice Rowe Roberts"}}},"max_analyzer_offset":1000000,"post_tags":["</tag1>"],"pre_tags":["<tag1>"]},"query":{"match":{"name.standard":{"query":"Upton Sons Shield Rice Rowe Roberts"}}}}
[xUnit.net 00:01:16.48]     Tests.Search.Request.HighlightingUsageTests.ReturnsExpectedResponse [FAIL]
# Response:
{
  "error" : {
    "root_cause" : [
      {
        "type" : "x_content_parse_exception",
        "reason" : "[1:675] [highlight] unknown field [max_analyzer_offset]",

@gjunge
Copy link
Contributor Author

gjunge commented Aug 18, 2023

Understood. Do you have a pointer where this already happens in the project so I can implement it consistently?

@Yury-Fridlyand
Copy link
Collaborator

Understood. Do you have a pointer where this already happens in the project so I can implement it consistently?

I think you need to keep both in the client code, like we have with master/cluster_manager:

///<remarks>Deprecated as of OpenSearch 2.0, use <see cref="ClusterManager"/> instead</remarks>
[EnumMember(Value = "master")]
Master,
///<remarks>Introduced in OpenSearch 2.0 instead of <see cref="Master"/></remarks>
[EnumMember(Value = "cluster_manager")]
ClusterManager,

For integration tests you can duplicate tests and use SkipVersion attribute:

[SkipVersion("<2.0.0", "CatClusterManager API was introdused in 2.0.0 release instead of CatMaster")]
public class CatClusterManagerApiTests
: ApiIntegrationTestBase<ReadOnlyCluster, CatResponse<CatClusterManagerRecord>, ICatClusterManagerRequest, CatClusterManagerDescriptor, CatClusterManagerRequest>

[SkipVersion(">=2.0.0", "CatMaster API was renamed to CatClusterManager in 2.0.0 release")]
public class CatMasterApiTests
: ApiIntegrationTestBase<ReadOnlyCluster, CatResponse<CatMasterRecord>, ICatMasterRequest, CatMasterDescriptor, CatMasterRequest>

So client will be compatible with all OpenSearch version and test framework will skip test of incompatible feature for given version range.

gjunge added 4 commits August 19, 2023 10:53
… name to match OS 2.2.0

Signed-off-by: Gideon Junge <[email protected]>
Signed-off-by: Gideon Junge <[email protected]>
max_analyzer_offset can be set both on highlight in general, and on specific fields.

Signed-off-by: Gideon Junge <[email protected]>
@gjunge
Copy link
Contributor Author

gjunge commented Aug 19, 2023

Added also field level max_analyzer_offset. Gives the new unit test some more "reason to exist".

Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this fix @gjunge, looks good!

@Xtansia Xtansia merged commit 8ad8057 into opensearch-project:main Aug 20, 2023
@Xtansia Xtansia added the backport 1.x Backport to 1.x branch label Aug 20, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.x 1.x
# Navigate to the new working tree
cd .worktrees/backport-1.x
# Create a new branch
git switch --create backport/backport-322-to-1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 8ad8057696044485d53858b794f2d6d0dc74aa8d
# Push it to GitHub
git push --set-upstream origin backport/backport-322-to-1.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.x

Then, create a pull request where the base branch is 1.x and the compare/head branch is backport/backport-322-to-1.x.

Xtansia pushed a commit to Xtansia/opensearch-net that referenced this pull request Aug 20, 2023
… name to match OS 2.2.0 (opensearch-project#322)

* Fixes opensearch-project#321: fix highlight max_analyzer_offset field name to match OS 2.2.0

Signed-off-by: Gideon Junge <[email protected]>

* extend existing highlighting unit test

Signed-off-by: Gideon Junge <[email protected]>

* Create > 2.2.0 unit test

Signed-off-by: Gideon Junge <[email protected]>

* Implement HighlightField level max_analyzer_offset

max_analyzer_offset can be set both on highlight in general, and on specific fields.

Signed-off-by: Gideon Junge <[email protected]>

---------

Signed-off-by: Gideon Junge <[email protected]>
(cherry picked from commit 8ad8057)
Xtansia pushed a commit to Xtansia/opensearch-net that referenced this pull request Aug 20, 2023
… name to match OS 2.2.0 (opensearch-project#322)

* Fixes opensearch-project#321: fix highlight max_analyzer_offset field name to match OS 2.2.0

Signed-off-by: Gideon Junge <[email protected]>

* extend existing highlighting unit test

Signed-off-by: Gideon Junge <[email protected]>

* Create > 2.2.0 unit test

Signed-off-by: Gideon Junge <[email protected]>

* Implement HighlightField level max_analyzer_offset

max_analyzer_offset can be set both on highlight in general, and on specific fields.

Signed-off-by: Gideon Junge <[email protected]>

---------

Signed-off-by: Gideon Junge <[email protected]>
(cherry picked from commit 8ad8057)
Xtansia added a commit that referenced this pull request Aug 22, 2023
…2.2.0 (#322) (#324)

* Fixes #321: fix highlight max_analyzer_offset field name to match OS 2.2.0

Signed-off-by: Gideon Junge <[email protected]>

* extend existing highlighting unit test

Signed-off-by: Gideon Junge <[email protected]>

* Create > 2.2.0 unit test

Signed-off-by: Gideon Junge <[email protected]>

* Implement HighlightField level max_analyzer_offset

max_analyzer_offset can be set both on highlight in general, and on specific fields.

Signed-off-by: Gideon Junge <[email protected]>

---------

Signed-off-by: Gideon Junge <[email protected]>
(cherry picked from commit 8ad8057)

Co-authored-by: Gideon Junge <[email protected]>
@gjunge gjunge deleted the issue-321 branch September 15, 2023 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.x Backport to 1.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants