# Elastic join query not returning correct result

**URL:** <https://discuss.elastic.co/t/elastic-join-query-not-returning-correct-result/123155>\
**Category:** Elasticsearch\
**Created:** [March 8, 2018, 10:49pm UTC](https://discuss.elastic.co/t/elastic-join-query-not-returning-correct-result/123155 "2018-03-08T22:49:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chetan\_vartak](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@chetan\_vartak](https://discuss.elastic.co/u/chetan_vartak)\
**Post date:** [March 8, 2018, 10:49pm UTC](https://discuss.elastic.co/t/elastic-join-query-not-returning-correct-result/123155/1 "2018-03-08T22:49:43Z")

</div>

I have data in elastic with parent-child relationship. But both "has\_child" and "has\_parent" queries is missing few inner hits.

Query with "has\_child" is returning 2 doc. But there are 3 doc. If I remove the "has\_child" part of query, it returns 3 doc. But I know that the missing doc also have a child -  
`{"_source":false,"query":{"bool":{"must":[{"terms":{"order_doc_type":["order_line"]}},{"terms":{"channel_order_id":["mf806561363"]}},{"has_child":{"type":"shipment_line","query":{"match_all":{}},"inner_hits":{"size":10,"_source":false}}}]}}}`

I have the same result when I look with "has\_parent".

I can verify that the parent-child relationship exists for the missing doc -  
This 2 is returned with the above query -  
GET perfectorder\_v2/order/mf806561363-1-sg830139117?\_source=false&routing=mf806561363-1  
GET perfectorder\_v2/order/mf806561363-2-sg830139117?\_source=false&routing=mf806561363-2

And this one not  
GET perfectorder\_v2/order/mf806561363-3-sg830139117?\_source=false&routing=mf806561363-3

I can provide more details... but here few questions -

1. Is having "-" in the \_id have any impact?
2. My mapping looks fine... but please let me know if this could be an issue

{  
"perfectorder\_v2": {  
"mappings": {  
"order": {  
"properties": {  
"doc\_type": {  
"type": "join",  
"eager\_global\_ordinals": true,  
"relations": {  
"order\_header": "order\_line",  
"order\_line": [  
"backorder\_line",  
"shipment\_line",  
"stop\_shipment\_line",  
"cancel\_line",  
"return\_line",  
"release\_line"  
]  
}  
},  
"order\_doc\_type": {  
"type": "keyword"  
},

1. I'm using ES 6.1.1 right now

---

<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:** [April 5, 2018, 10:49pm UTC](https://discuss.elastic.co/t/elastic-join-query-not-returning-correct-result/123155/2 "2018-04-05T22:49:57Z")

</div>

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