Elasticsearch Java API 5.4 - How to get the inner hits of a nested query?

I recently started to migrate from Elasticsearch version 2.4 to version 5.4. In version 2.4 I implemented some nested queries including inner hits, using the official Java API, which do not work in version 5.4 anymore.

Can anyone tell me, how to get the inner hits of a nested query using the Elasticsearch Java API 5.4? Unfortunately, I can't find any sources regarding this topic.

My functioning nested query in version 2.4:

QueryBuilders.nestedQuery("classes.links",
    QueryBuilders.boolQuery()
        .must(QueryBuilders.termQuery("classes.links.name", "xyz"))
).innerHit(new QueryInnerHitBuilder())

My attempt to get this query to work in version 5.4:

QueryBuilders.nestedQuery("classes.links",
    QueryBuilders.boolQuery()
        .must(QueryBuilders.termQuery("classes.links.name", "xyz")), 
    ScoreMode.Avg
).innerHit(new InnerHitBuilder()) //Error here

I tried to replace QueryInnerHitBuilder() with InnerHitBuilder(), but it still does not work. My IDE is showing following error:

"Cannot resolve method 'innerHit(org.elasticsearch.index.query.InnerHitBuilder)'"

1 Like

Bump. I still don't know, how to get the inner hits.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.