Inner_hits in has parent giving error-"Couldn't find nested source for path currentCompany"

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

{
   "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

{
   "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

{
   "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.



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
}
2 Likes

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