-
Notifications
You must be signed in to change notification settings - Fork 191
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee95d73
Removed required index for Hit.java
jvan1997 66804d6
Removed required index for Hit.java
jvan1997 eb6cb65
Merge branch 'main' of https://github.com/jvan1997/opensearch-java
jvan1997 336baaa
Bump com.diffplug.spotless from 6.24.0 to 6.25.0 in /java-client (#828)
dependabot[bot] 2a2ce72
Removed required index for Hit.java
jvan1997 ee26b63
Merge branch 'main' of https://github.com/jvan1997/opensearch-java
jvan1997 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...lient/src/test/java/org/opensearch/client/opensearch/core/search/InnerHitsResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.opensearch.client.opensearch.core.search; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import java.io.StringReader; | ||
import org.junit.Test; | ||
import org.opensearch.client.json.JsonData; | ||
import org.opensearch.client.json.JsonpMapper; | ||
import org.opensearch.client.json.jsonb.JsonbJsonpMapper; | ||
|
||
public class InnerHitsResultTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
private final JsonpMapper mapper = new JsonbJsonpMapper(); | ||
private final String storedSalary = "details.salary"; | ||
private final String storedJobId = "details.jobId"; | ||
|
||
/** | ||
* test if the InnerHitsResult will build the Hit<JsonData> | ||
*/ | ||
@Test | ||
public void testInnerHits() { | ||
|
||
String classString = String.valueOf(hitResultWithIdIndex.innerHits().get("test_child").getClass()); | ||
assertEquals(classString, InnerHitsResult.class.toString()); | ||
// take hitResult and get the InnerHit | ||
InnerHitsResult innerHitsResult = hitResultWithIdIndex.innerHits().get("test_child"); | ||
Hit<JsonData> innerHitResult = innerHitsResult.hits().hits().get(0); | ||
assertNotNull(innerHitResult.index()); | ||
assertEquals(innerHitResult.index(), "_index"); | ||
assertNotNull(innerHitResult.id()); | ||
assertEquals(innerHitResult.id(), "child_id"); | ||
} | ||
|
||
/** | ||
* test if the InnerHitsResult will still build the Hit<JsonData> even if id and index is not specified | ||
*/ | ||
@Test | ||
public void testInnerHitWithoutIdIndex() { | ||
|
||
String classString = String.valueOf(hitResultNoIdIndex.innerHits().get("test_child").getClass()); | ||
assertEquals(classString, InnerHitsResult.class.toString()); | ||
// take hitResult and get the InnerHit | ||
InnerHitsResult innerHitsResult = hitResultNoIdIndex.innerHits().get("test_child"); | ||
Hit<JsonData> innerHitResult = innerHitsResult.hits().hits().get(0); | ||
// Id and index are now nullable. | ||
assertNull(innerHitResult.index()); | ||
assertNull(innerHitResult.id()); | ||
} | ||
|
||
private final String innerHitJsonWithNoIdOrIndex = "{\"key\":\"value\"}"; | ||
private final String innerHitJsonWithIdOrIndex = "{\"id\":\"value\",\"index\":\"value\"}"; | ||
|
||
private final Hit<JsonData> hitResultNoIdIndex = Hit.of( | ||
it -> it.id("test_parent") | ||
.index("_index") | ||
.innerHits( | ||
"test_child", | ||
innerHitsResultBuilder -> innerHitsResultBuilder.hits( | ||
innerHitsMetadataBuilder -> innerHitsMetadataBuilder.total(total -> total.value(1).relation(TotalHitsRelation.Eq)) | ||
.hits( | ||
innerHitsListMemberBuilder -> innerHitsListMemberBuilder.source( | ||
JsonData.from(mapper.jsonProvider().createParser(new StringReader(innerHitJsonWithNoIdOrIndex)), mapper) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
private final Hit<JsonData> hitResultWithIdIndex = Hit.of( | ||
it -> it.id("test_parent") | ||
.index("_index") | ||
.innerHits( | ||
"test_child", | ||
innerHitsResultBuilder -> innerHitsResultBuilder.hits( | ||
innerHitsMetadataBuilder -> innerHitsMetadataBuilder.total(total -> total.value(1).relation(TotalHitsRelation.Eq)) | ||
.hits( | ||
innerHitsListMemberBuilder -> innerHitsListMemberBuilder.id("child_id").index("_index").source( | ||
JsonData.from(mapper.jsonProvider().createParser(new StringReader(innerHitJsonWithIdOrIndex)), mapper) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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.