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

IndexOutOfBoundsException when try to map inner hits with no results returned #1997

Closed
xhaggi opened this issue Nov 16, 2021 · 9 comments · Fixed by #1998
Closed

IndexOutOfBoundsException when try to map inner hits with no results returned #1997

xhaggi opened this issue Nov 16, 2021 · 9 comments · Fixed by #1998
Labels
type: bug A general bug

Comments

@xhaggi
Copy link
Contributor

xhaggi commented Nov 16, 2021

Configuring inner_hits with a size of 0 will result in an IndexOutOfBoundsException when mapping inner hits.

WARN  o.s.d.e.core.SearchHitMapping - Could not map inner_hits
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:372)
	at java.base/java.util.ArrayList.get(ArrayList.java:459)
	at org.springframework.data.elasticsearch.core.SearchHitsImpl.getSearchHit(SearchHitsImpl.java:97)
	at org.springframework.data.elasticsearch.core.SearchHitMapping.mapInnerDocuments(SearchHitMapping.java:181)
	at org.springframework.data.elasticsearch.core.SearchHitMapping.mapInnerHits(SearchHitMapping.java:158)
	at org.springframework.data.elasticsearch.core.SearchHitMapping.mapHit(SearchHitMapping.java:115)
	at org.springframework.data.elasticsearch.core.SearchHitMapping.mapHitsFromResponse(SearchHitMapping.java:95)
	at org.springframework.data.elasticsearch.core.SearchHitMapping.mapHits(SearchHitMapping.java:71)
	at org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate$ReadSearchDocumentResponseCallback.doWith(AbstractElasticsearchTemplate.java:875)
	at org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate$ReadSearchDocumentResponseCallback.doWith(AbstractElasticsearchTemplate.java:860)
	at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.search(ElasticsearchRestTemplate.java:299)
	at org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate.search(AbstractElasticsearchTemplate.java:513)
	at ch.x28.jobportal.core.searchindex.SearchIndexRepositoryImpl.findAll(SearchIndexRepositoryImpl.java:56)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 16, 2021
@xhaggi xhaggi changed the title IndexOutOfBoundsException when try to map inner hits documents with no results returned IndexOutOfBoundsException when try to map inner hits with no results returned Nov 16, 2021
@sothawo sothawo added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 17, 2021
@AntonLGVS
Copy link
Contributor

AntonLGVS commented Nov 19, 2021

Maybe, this is thrown out here:
org.springframework.data.elasticsearch.core.SearchHitMapping#mapInnerDocuments
[line:202] NestedMetaData nestedMetaData = searchHits.getSearchHit(0).getContent().getNestedMetaData();

@xhaggi
Copy link
Contributor Author

xhaggi commented Nov 23, 2021

@AntonLGVS the stacktrace is clear enough to know what the root cause is. I have already created a pull request and fixed this problem.

sothawo pushed a commit that referenced this issue Nov 23, 2021
…lts returned.

Original Pull Request #1998 
Closes #1997
Co-authored-by: Peter-Josef Meisch <pj.meisch@sothawo.com>
@sothawo sothawo added this to the 4.4 M1 (2022.0.0) milestone Nov 23, 2021
sothawo pushed a commit that referenced this issue Nov 23, 2021
…lts returned.

Original Pull Request #1998
Closes #1997
Co-authored-by: Peter-Josef Meisch <pj.meisch@sothawo.com>

(cherry picked from commit 49324a3)
@sothawo
Copy link
Collaborator

sothawo commented Nov 23, 2021

backported to 4.3. Did not backport to 4.2 and 4.1 because the test cannot be backported there as NativeSearchQueryBuilder.withCollapseBuilder was introduced in 4.3

@xhaggi
Copy link
Contributor Author

xhaggi commented Nov 23, 2021

IMO we should adjust the test for 4.2, 4.1 because the issue also exists in these versions.

@xhaggi
Copy link
Contributor Author

xhaggi commented Nov 23, 2021

We could use a nested query with inner hits [1] instead of collapse to test the issue.

[1] https://www.elastic.co/guide/en/elasticsearch/reference/7.16/inner-hits.html#nested-inner-hits

@sothawo
Copy link
Collaborator

sothawo commented Nov 23, 2021

Can you please cherrypick the commit from 4.3 to 4.2 and adjust the test then? And then further cherrypick from 4.2 to 4.1?

@xhaggi
Copy link
Contributor Author

xhaggi commented Nov 23, 2021

Sure will do that tomorrow.

xhaggi added a commit that referenced this issue Nov 24, 2021
…lts returned.

Original Pull Request #1998
Closes #1997

(cherry picked from commit 49324a3)
xhaggi added a commit that referenced this issue Nov 24, 2021
…lts returned.

Original Pull Request #1998
Closes #1997

(cherry picked from commit 2aba7a5)
@xhaggi
Copy link
Contributor Author

xhaggi commented Nov 24, 2021

Backported to 4.2.x and 4.1.x.

@sothawo
Copy link
Collaborator

sothawo commented Nov 24, 2021

thanks a lot

sothawo added a commit that referenced this issue Dec 5, 2021
…lts returned.

Original Pull Request #1998
Closes #1997
Co-authored-by: Peter-Josef Meisch <pj.meisch@sothawo.com>

(cherry picked from commit 49324a3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
4 participants