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

[BUG] InnerHIt result not containing a _index is throwing Hit.Index missing #825

Closed
jvan1997 opened this issue Jan 30, 2024 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@jvan1997
Copy link
Contributor

What is the bug?

A clear and concise description of the bug.

Caused by: org.opensearch.client.util.MissingRequiredPropertyException: Missing required property 'Hit.index'

I have a query that I am getting back from opensearch that has a Hit of a parent, and alongside that, I added the option to retrieve all the children of that parent document as Innerhits.

I've included an example below of the query, where I think it should be getting a parent that has a child document of type childType, and then in the innerhits, get the children for it.

Query.of {
    it.hasChild {
        it.type("childType")
        it.query {
            it.matchAll { it -> it }
        }
        it.innerHits {
            it.source {
                it.fetch(true)
            }
        }
    }
}

Hit.java is able to convert the response to the java class for the parent perfectly fine, however when trying to convert its children, it fails because each InnerHit included with the parent Hit does not have a index specified in the response. I believe it was done under the intention that the the index of the InnerHits should always match the parent, however, the conversion is not aware of the Parent document's index for the InnerHit.

How can one reproduce the bug?

Steps to reproduce the behavior.
Reproduction steps would be to create two documents, and associate a parent-child relation to them. And then run a query for a property that would match the parent, and then adding the innerHits field:

it.innerHits {
            it.source {
                it.fetch(true)
            }
        }

What is the expected behavior?

A clear and concise description of what you expected to happen.
Hit.java should be able to convert the InnerHits into Hit objects properly.

What is your host/environment?

Operating system, version.
MacOS 14.2.1

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

I have to wonder why the index is set to mandatory? I did see a discussion on elasticsearch back in 2016 elastic/elasticsearch#18091 but I am not sure if it's the same.

@jvan1997 jvan1997 added bug Something isn't working untriaged labels Jan 30, 2024
@Sunhick
Copy link

Sunhick commented Feb 5, 2024

Starting with elasticsearch v5.0 _index, _type, _id aren't included with inner nested hits.

Nested inner hits will now no longer include _index, _type and _id keys. For nested inner hits these values are always the same as the _index, _type and _id keys of the root search hit.

reference:
https://github.com/elastic/elasticsearch/blob/v5.4.2/docs/reference/migration/migrate_5_0/search.asciidoc#:~:text=Nested%20inner%20hits%20will%20now%20no%20longer%20include%20_index%2C%20_type%20and%20_id%20keys.%20For%20nested%20inner%20hits%20these%20values%20are%20always%20the%20same%20as%20the%20_index%2C%20_type%20and%20_id%20keys%20of%20the%20root%20search%20hit.

@dblock dblock removed the untriaged label Feb 5, 2024
@dblock
Copy link
Member

dblock commented Feb 5, 2024

@Sunhick care to contribute a test+ fix?

@Sunhick
Copy link

Sunhick commented Feb 5, 2024

@jvan1997 Jonathan already has a fix. He will be submitting a PR soon.

@VachaShah
Copy link
Collaborator

This is done via #838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants