# Inner\_hits in has parent giving error-"Couldn't find nested source for path currentCompany"

**URL:** <https://discuss.elastic.co/t/inner-hits-in-has-parent-giving-error-couldnt-find-nested-source-for-path-currentcompany/318232>\
**Category:** Elasticsearch\
**Created:** [November 5, 2022, 10:18am UTC](https://discuss.elastic.co/t/inner-hits-in-has-parent-giving-error-couldnt-find-nested-source-for-path-currentcompany/318232 "2022-11-05T10:18:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Venkat\_Koushik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkat_koushik/32/104158_2.png) [@Venkat\_Koushik](https://discuss.elastic.co/u/Venkat_Koushik)\
**Post date:** [November 5, 2022, 10:18am UTC](https://discuss.elastic.co/t/inner-hits-in-has-parent-giving-error-couldnt-find-nested-source-for-path-currentcompany/318232/1 "2022-11-05T10:18:28Z")

</div>

Hello  
We are migrating to Elasticsearch 8 and when we are trying to fetch the data of parent document inner hits using has parent query it is returning exception but the reverse scenario is working good.Elasticsearch returning exception when running innerhits for has parent query. tried to replicate all the steps and created a pseudo index for your understanding.  
1)created a index  
2)added mapping to it  
3)created the parent document  
4)created a child document  
ran query to get all the candidate details  
ran query to get has child documents  
ran query to get has parent documents  
currentCompany is of type nested.  
created a index  
PUT testinnerhits3  
PUT testinnerhits3/\_mappings

```auto
{
   "properties": {
      "relation_type": {
         "type": "join",
         "eager_global_ordinals": true,
         "relations": {
            "parentField": [
               "childField"
            ]
         }
      },
         "currentCompany": {
         "type": "nested",
         "include_in_parent": true,
         "properties": {
            "summary": {     
               "type": "text"
            }
         }
      }
       }
   }
}

```

ran query to get all the has child data  
GET testinnerhits2/\_search

```auto
{
   "query": {
      "has_parent": {
         "parent_type": "parentField",
         "query": {
            "match_all": {}
         },
          "inner_hits": {
            "size": 5,
            "from": 0,
            "sort": [],
            "_source": {
               "excludes": [],
               "includes": [
               ]
            }
         }
      }
   }
}

```

ran query to get all the has parent data  
GET testinnerhits/\_search

```auto
{
   "query": {
     "has_child": {
         "query": {
             "match_all": {
             }
         },"type": "childField",
          "inner_hits": {
            "size": 5,
            "from": 0,
            "sort": [],
            "_source": {
               "excludes": [],
               "includes": [
               "userId"
               ]
            }
         }
     }
   }
}

```

when i remove has parent inner hit query in last query its running good.  
here parentField is the parent type and childField is the child type  
currentCompany is of type nested.

```auto

I tried to add config through dynamic template but its failing there as well

**ERROR after hitting has_parent query**

{
   "error": {
      "root_cause": [
         {
            "type": "illegal_state_exception",
            "reason": "Couldn't find nested source for path currentCompany"
         }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
         {
            "shard": 0,
            "index": "testinnerhits2",
            "node": "XGFornQYTEKvJISCCwmntA",
            "reason": {
               "type": "illegal_state_exception",
               "reason": "Couldn't find nested source for path currentCompany"
            }
         }
      ],
      "caused_by": {
         "type": "illegal_state_exception",
         "reason": "Couldn't find nested source for path currentCompany",
         "caused_by": {
            "type": "illegal_state_exception",
            "reason": "Couldn't find nested source for path currentCompany"
         }
      }
   },
   "status": 500
}

```

---

<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:** [December 3, 2022, 10:19am UTC](https://discuss.elastic.co/t/inner-hits-in-has-parent-giving-error-couldnt-find-nested-source-for-path-currentcompany/318232/2 "2022-12-03T10:19:03Z")

</div>

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