# Java API: client.prepareGet and parent documents

**URL:** <https://discuss.elastic.co/t/java-api-client-prepareget-and-parent-documents/5083>\
**Category:** Elasticsearch\
**Created:** [August 8, 2011, 3:16pm UTC](https://discuss.elastic.co/t/java-api-client-prepareget-and-parent-documents/5083 "2011-08-08T15:16:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicco/32/3106_2.png) [@nicco](https://discuss.elastic.co/u/nicco)\
**Post date:** [August 8, 2011, 3:16pm UTC](https://discuss.elastic.co/t/java-api-client-prepareget-and-parent-documents/5083/1 "2011-08-08T15:16:14Z")

</div>

Hi!

this is my mapping:

{  
"connection": {  
properties: {  
state: {type: "string", index: "not\_analyzed",  
include\_in\_all: false},  
groupid: {type: "string", index: "not\_analyzed",  
include\_in\_all: false},  
tags: {type: "string", index\_name: "tag", index:  
"not\_analyzed", include\_in\_all: false}  
},  
\_parent: {type: "company"}  
}  
}

when i try to retrieve a document using the JAVA API:

GetResponse response = client.prepareGet(indexName, 'connection',  
'id').execute().actionGet();

i only get the fields of connection and not the ones of company!

any hint?

Thanks  
Niccoló

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 8, 2011, 3:20pm UTC](https://discuss.elastic.co/t/java-api-client-prepareget-and-parent-documents/5083/2 "2011-08-08T15:20:29Z")

</div>

You need to fetch the company as well. You can ask for the \_parent field  
from the child doc, and use that id to fetch the parent document.

On Mon, Aug 8, 2011 at 6:16 PM, nicco [nicco82@gmail.com](mailto:nicco82@gmail.com) wrote:

> Hi!
> 
> this is my mapping:
> 
> {  
> "connection": {  
> properties: {  
> state: {type: "string", index: "not\_analyzed",  
> include\_in\_all: false},  
> groupid: {type: "string", index: "not\_analyzed",  
> include\_in\_all: false},  
> tags: {type: "string", index\_name: "tag", index:  
> "not\_analyzed", include\_in\_all: false}  
> },  
> \_parent: {type: "company"}  
> }  
> }
> 
> when i try to retrieve a document using the JAVA API:
> 
> GetResponse response = client.prepareGet(indexName, 'connection',  
> 'id').execute().actionGet();
> 
> i only get the fields of connection and not the ones of company!
> 
> any hint?
> 
> Thanks  
> Niccoló

---

<div class="post-metadata">

**Author:** ![nicco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicco/32/3106_2.png) [@nicco](https://discuss.elastic.co/u/nicco)\
**Post date:** [August 9, 2011, 8:19am UTC](https://discuss.elastic.co/t/java-api-client-prepareget-and-parent-documents/5083/3 "2011-08-09T08:19:07Z")

</div>

Thabks for your answer, another question is there a way to dynamically  
get the parent type when i retrieve a connection?

Thanks!

On Aug 8, 5:20 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> You need to fetch the company as well. You can ask for the \_parent field  
> from the child doc, and use that id to fetch the parent document.
> 
> On Mon, Aug 8, 2011 at 6:16 PM, nicco [nicc...@gmail.com](mailto:nicc...@gmail.com) wrote:
> 
> > Hi!
> 
> > this is my mapping:
> 
> > {  
> > "connection": {  
> > properties: {  
> > state: {type: "string", index: "not\_analyzed",  
> > include\_in\_all: false},  
> > groupid: {type: "string", index: "not\_analyzed",  
> > include\_in\_all: false},  
> > tags: {type: "string", index\_name: "tag", index:  
> > "not\_analyzed", include\_in\_all: false}  
> > },  
> > \_parent: {type: "company"}  
> > }  
> > }
> 
> > when i try to retrieve a document using the JAVA API:
> 
> > GetResponse response = client.prepareGet(indexName, 'connection',  
> > 'id').execute().actionGet();
> 
> > i only get the fields of connection and not the ones of company!
> 
> > any hint?
> 
> > Thanks  
> > Niccoló

---

<div class="post-metadata">

**Author:** ![nicco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicco/32/3106_2.png) [@nicco](https://discuss.elastic.co/u/nicco)\
**Post date:** [August 9, 2011, 8:44am UTC](https://discuss.elastic.co/t/java-api-client-prepareget-and-parent-documents/5083/4 "2011-08-09T08:44:05Z")

</div>

I'm having issues finging the parentId

this is the map i get when executing response.getSource():

{tags=, groupid=210dc7b0-1cbd-4320-a044-5061318c12d4}

any hint?  
thanks  
On Aug 8, 5:20 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> You need to fetch the company as well. You can ask for the \_parent field  
> from the child doc, and use that id to fetch the parent document.
> 
> On Mon, Aug 8, 2011 at 6:16 PM, nicco [nicc...@gmail.com](mailto:nicc...@gmail.com) wrote:
> 
> > Hi!
> 
> > this is my mapping:
> 
> > {  
> > "connection": {  
> > properties: {  
> > state: {type: "string", index: "not\_analyzed",  
> > include\_in\_all: false},  
> > groupid: {type: "string", index: "not\_analyzed",  
> > include\_in\_all: false},  
> > tags: {type: "string", index\_name: "tag", index:  
> > "not\_analyzed", include\_in\_all: false}  
> > },  
> > \_parent: {type: "company"}  
> > }  
> > }
> 
> > when i try to retrieve a document using the JAVA API:
> 
> > GetResponse response = client.prepareGet(indexName, 'connection',  
> > 'id').execute().actionGet();
> 
> > i only get the fields of connection and not the ones of company!
> 
> > any hint?
> 
> > Thanks  
> > Niccoló

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 9, 2011, 8:52am UTC](https://discuss.elastic.co/t/java-api-client-prepareget-and-parent-documents/5083/5 "2011-08-09T08:52:52Z")

</div>

You need to explicitly ask for the \_parent field when you get the doc. The  
type is not provided since its part of the mapping..., though, you can ask  
for the mapping.

On Tue, Aug 9, 2011 at 11:44 AM, nicco [nicco82@gmail.com](mailto:nicco82@gmail.com) wrote:

> I'm having issues finging the parentId
> 
> this is the map i get when executing response.getSource():
> 
> {tags=, groupid=210dc7b0-1cbd-4320-a044-5061318c12d4}
> 
> any hint?  
> thanks  
> On Aug 8, 5:20 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > You need to fetch the company as well. You can ask for the \_parent field  
> > from the child doc, and use that id to fetch the parent document.
> > 
> > On Mon, Aug 8, 2011 at 6:16 PM, nicco [nicc...@gmail.com](mailto:nicc...@gmail.com) wrote:
> > 
> > > Hi!
> > 
> > > this is my mapping:
> > 
> > > {  
> > > "connection": {  
> > > properties: {  
> > > state: {type: "string", index: "not\_analyzed",  
> > > include\_in\_all: false},  
> > > groupid: {type: "string", index: "not\_analyzed",  
> > > include\_in\_all: false},  
> > > tags: {type: "string", index\_name: "tag", index:  
> > > "not\_analyzed", include\_in\_all: false}  
> > > },  
> > > \_parent: {type: "company"}  
> > > }  
> > > }
> > 
> > > when i try to retrieve a document using the JAVA API:
> > 
> > > GetResponse response = client.prepareGet(indexName, 'connection',  
> > > 'id').execute().actionGet();
> > 
> > > i only get the fields of connection and not the ones of company!
> > 
> > > any hint?
> > 
> > > Thanks  
> > > Niccoló

---

<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:** [July 6, 2017, 3:57am UTC](https://discuss.elastic.co/t/java-api-client-prepareget-and-parent-documents/5083/6 "2017-07-06T03:57:50Z")

</div>


