# ElasticSearch Inner Hits on has\_parent nested Inner hits

**URL:** <https://discuss.elastic.co/t/elasticsearch-inner-hits-on-has-parent-nested-inner-hits/229777>\
**Category:** Elasticsearch\
**Created:** [April 25, 2020, 5:26pm UTC](https://discuss.elastic.co/t/elasticsearch-inner-hits-on-has-parent-nested-inner-hits/229777 "2020-04-25T17:26:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlivet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jlivet/32/26856_2.png) [@jlivet](https://discuss.elastic.co/u/jlivet)\
**Post date:** [April 25, 2020, 5:26pm UTC](https://discuss.elastic.co/t/elasticsearch-inner-hits-on-has-parent-nested-inner-hits/229777/1 "2020-04-25T17:26:12Z")

</div>

I've searched for this and haven't found anything that says whether this is or is not supported. According to Elastic [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-request-body.html#request-body-search-inner-hits):

> "Inner hits can be used by defining an inner\_hits definition on a  
> nested, has\_child or has\_parent query and filter. "

I want to use inner\_hits on a has\_parent, nested object. I've tried it as illustrated in the example below. Does anyone know if this is possible?

Example Scenario (I've simplified the data and properties for the purpose of this post)

> We store task title & description translations as a nested object in  
> the parent task. Each nested title has an iso code and a translated  
> title & description. We distribute child tasks to, in some cases,  
> thousands of users so it didn't make sense replicating the  
> title/description into each child object.

**Parent Task Example**

```auto
    {
      "_id": "parenttask_177448",
      "startDate": "2020-05-01T00:00:00",
      "endDate": "2020-05-05T00:00:00",
      "type": "task",
      "taskjoin" : "parenttask",
      "priorityId": 1,
      "translations": [
        {
          "title": "This is a test task",
          "description": "test",
          "localeIsoCode": [
            "en-US"
          ]
        },
        {
          "description": "tester",
          "title": "Ceci est une tâche de test",
          "localeIsoCode": [
            "fr-FR"
          ]
        }
      ]
    }

```

**Children Task(s) Example**

```auto
    {
        "_id": "childtask_12345",
        "taskSubType": "distributed",
        "subtasks": [],
        "startDate": "2020-03-19T00:00:00",
        "endDate": "2020-03-19T00:00:00",
        "taskJoinField": {
          "name": "taskjoin",
          "parent": "parenttask_177448"
        },
        "assignedUserId": 12345,
        "assignedUserName": "Bob Jones"
    }

```

**Relevant part of the query I'm running that brings back no inner hits results**

```auto
    {
      "has_parent": {
        "ignore_unmapped": true,
        "parent_type": "parenttask",
        "query": {
          "nested": {
            "ignore_unmapped": true,
            "inner_hits": {
              "name": "innerhits_task",
              "_source": {
                "includes": [
                  "title"
                ]
              }
            },
            "path": "translations",
            "query": {
              "term": {
                "translations.localeIsoCode.keyword": {
                  "value": "fr-FR"
                }
              }
            },
            "boost": 1.1,
            "_name": "nested_isocode"
          }
        },
        "score": true,
        "boost": 1.1,
        "_name": "parent_isocode"
      }
    }

```

I'm getting results back from the child tasks but no inner hits matches. If I move the inner hits to the has\_parent, I get all the translations back.

My question is whether doing a parent nested inner hits is possible in Elastic? I'm surprised I didn't find anyone else trying to do this or examples on the Internet. This seems like a pretty common use case.

Posted the same question to StackOverflow. I hope that is Ok. This is my first post to [elastic.co](http://elastic.co).

Thanks for your help.

---

<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:** [May 23, 2020, 5:26pm UTC](https://discuss.elastic.co/t/elasticsearch-inner-hits-on-has-parent-nested-inner-hits/229777/2 "2020-05-23T17:26:19Z")

</div>

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