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

Removed required index for Hit.java #831

Closed
wants to merge 6 commits into from

Conversation

jvan1997
Copy link
Contributor

@jvan1997 jvan1997 commented Feb 6, 2024

For InnerHits, since the index and id is assumed to be the same as parent, they were not included in the InnerHit object, but when converting it into a Hit object in the java sdk, it would throw an exception, saying index is required. Removed it, and also added unit tests.

Description

Describe what this change achieves.
Change removes the required field for index in the Hit.java

Issues Resolved

Closes #825

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.

For InnerHits, since the index and id is assumed to be the same as parent, they were not included in the InnerHit object, but when converting it into a Hit object in the java sdk, it would throw an exception, saying index is required. Removed it, and also added unit tests.
jvan1997 and others added 5 commits February 6, 2024 14:15
For InnerHits, since the index and id is assumed to be the same as parent, they were not included in the InnerHit object, but when converting it into a Hit object in the java sdk, it would throw an exception, saying index is required. Removed it, and also added unit tests.

Signed-off-by: jvan1997 <[email protected]>
…nsearch-project#828)

* Bump com.diffplug.spotless from 6.24.0 to 6.25.0 in /java-client

Bumps com.diffplug.spotless from 6.24.0 to 6.25.0.

---
updated-dependencies:
- dependency-name: com.diffplug.spotless
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update changelog

Signed-off-by: dependabot[bot] <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
Signed-off-by: jvan1997 <[email protected]>
For InnerHits, since the index and id is assumed to be the same as parent, they were not included in the InnerHit object, but when converting it into a Hit object in the java sdk, it would throw an exception, saying index is required. Removed it, and also added unit tests.

Signed-off-by: jvan1997 <[email protected]>
@jvan1997 jvan1997 closed this Feb 6, 2024
@@ -107,7 +107,7 @@ public class Hit<TDocument> implements JsonpSerializable {

private Hit(Builder<TDocument> builder) {

this.index = ApiTypeHelper.requireNonNull(builder.index, this, "index");
this.index = builder.index;
Copy link

Choose a reason for hiding this comment

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

How do you ensure that this is only for a inner hit ? And outer hits should enforce requireNonNull.

Copy link
Contributor Author

@jvan1997 jvan1997 Feb 7, 2024

Choose a reason for hiding this comment

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

I do think this is a good call out; The problem is that the the InnerHit is in a List in HitsMetadata, which is then in the InnerHitsResult.

So unless there is a file made explicitly to represent an InnerHit (which I think is a valid path), the other option would be to re-populate the Index and the Id to the InnerHits as well, even if they match the parent, or a third option to create a flag that allows a hit to know whether it is an InnerHit or main Hit.

import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.jsonb.JsonbJsonpMapper;

public class InnerHitsResultTest {
Copy link

Choose a reason for hiding this comment

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

Do we have unit tests for outer hits with nullable ? Should be allowed or not allowed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] InnerHIt result not containing a _index is throwing Hit.Index missing
2 participants