# To access the parent fields using ES query

**URL:** <https://discuss.elastic.co/t/to-access-the-parent-fields-using-es-query/163391>\
**Category:** Elasticsearch\
**Created:** [January 8, 2019, 3:36pm UTC](https://discuss.elastic.co/t/to-access-the-parent-fields-using-es-query/163391 "2019-01-08T15:36:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naveena](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@Naveena](https://discuss.elastic.co/u/Naveena)\
**Post date:** [January 8, 2019, 3:36pm UTC](https://discuss.elastic.co/t/to-access-the-parent-fields-using-es-query/163391/1 "2019-01-08T15:36:27Z")

</div>

Hi,  
I have created a parent - child relationship between employee and address.

PUT my\_index10  
{  
"mappings": {  
"doc": {  
"properties": {  
"my\_join\_field": {  
"type": "join",  
"relations": {  
"employee": "address"  
}  
}  
}  
}  
}  
}

PUT my\_index10/doc/1?refresh  
{  
"id": "1",  
"name": "John",  
"age": "26",  
"my\_join\_field": {  
"name": "employee"  
}  
}

PUT my\_index10/doc/2?refresh  
{  
"id": "2",  
"name": "Watson",  
"age": "25",  
"my\_join\_field": {  
"name": "employee"  
}  
}

PUT my\_index10/doc/3?routing=1&refresh  
{  
"city": "NewYork",  
"country": "USA",  
"my\_join\_field": {  
"name": "address",  
"parent": "1"  
}  
}

PUT my\_index10/doc/4?routing=1&refresh  
{  
"city": "Chicago",  
"country": "USA",  
"my\_join\_field": {  
"name": "address",  
"parent": "2"  
}  
}

GET my\_index10/\_search  
{  
"query": {  
"match\_all": {}  
},  
"sort": ["\_id"]  
}

I could get the fields of child (address) using the below query.

GET my\_index10/\_search  
{  
"query": {  
"parent\_id": {  
"type": "address",  
"id": "1"  
}  
},  
"aggs": {  
"parents": {  
"terms": {  
"field": "my\_join\_field#employee",  
"size": 10  
}  
}  
},  
"script\_fields": {  
"parent": {  
"script": {  
"source": "doc['my\_join\_field#employee']"  
}  
}  
}  
}

Now I am supposed to get the fields and values of parent (employee) as well. How do I get that.  
Any help would be appreciated.  
Thanks in advance.

---

<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:** [February 5, 2019, 3:36pm UTC](https://discuss.elastic.co/t/to-access-the-parent-fields-using-es-query/163391/2 "2019-02-05T15:36:28Z")

</div>

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