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

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-api-5-4-how-to-get-the-inner-hits-of-a-nested-query/90582>\
**Category:** Elasticsearch\
**Created:** [June 23, 2017, 6:40am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-5-4-how-to-get-the-inner-hits-of-a-nested-query/90582 "2017-06-23T06:40:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Dude](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@The\_Dude](https://discuss.elastic.co/u/The_Dude)\
**Post date:** [June 23, 2017, 6:40am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-5-4-how-to-get-the-inner-hits-of-a-nested-query/90582/1 "2017-06-23T06:40:22Z")

</div>

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)'_"

---

<div class="post-metadata">

**Author:** ![The\_Dude](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@The\_Dude](https://discuss.elastic.co/u/The_Dude)\
**Post date:** [July 5, 2017, 7:42pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-5-4-how-to-get-the-inner-hits-of-a-nested-query/90582/3 "2017-07-05T19:42:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 2, 2017, 7:42pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-5-4-how-to-get-the-inner-hits-of-a-nested-query/90582/4 "2017-08-02T19:42:30Z")

</div>

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