# No success to create parent - child relation

**URL:** <https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158>\
**Category:** Elasticsearch\
**Created:** [December 14, 2011, 7:26am UTC](https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158 "2011-12-14T07:26:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy\_E](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_e/32/2271_2.png) [@Roy\_E](https://discuss.elastic.co/u/Roy_E)\
**Post date:** [December 14, 2011, 7:26am UTC](https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158/1 "2011-12-14T07:26:04Z")

</div>

Hi folks,

I've been trying to create a simple parent - child relation between  
different search types and finally gave up. I'll be happy if you guys  
give me a hand on this;

I have 2 types of search documents, simply "package" and "module" as  
in programming. Let's talk on the most famous web framework "Django"  
package in Python. First, the mappings:

# curl -XGET localhost:9200/pydoc/package/\_mapping

{"package":{"\_source":{"compress":true},"\_id":  
{"path":"package\_name"},"properties":{"summary":{"store":"yes","boost":  
1.2,"type":"string"},"keywords":  
{"index\_name":"tag","store":"yes","boost":  
1.4,"type":"string"},"description":{"boost":  
0.8,"type":"string"},"package\_name":{"store":"yes","boost":  
1.8,"type":"string"},"downloads":  
{"store":"yes","type":"integer"},"version":  
{"index":"not\_analyzed","store":"yes","type":"string"}}}}

# curl -XGET localhost:9200/pydoc/module/\_mapping

{"module":{"\_source":{"compress":true},"\_routing":  
{"required":true},"properties":{"source\_code":  
{"path":"full","type":"attachment","fields":{"source\_code":  
{"type":"string"},"author":{"type":"string"},"title":  
{"type":"string"},"keywords":{"type":"string"},"date":  
{"format":"dateOptionalTime","type":"date"},"content\_type":  
{"type":"string"}}},"file\_path":  
{"store":"yes","type":"string"},"import\_name":{"store":"yes","boost":  
1.8,"type":"string"}},"\_parent":{"type":"package"}}}

As we can see, \_parent is mapping to "package" type. Than, let's put  
our package:

# curl -XPUT localhost:9200/pydoc/package/Django -d '{"description":

null, "package\_name": "Django", "downloads": 83193, "summary": "A high-  
level Python Web framework that encourages rapid development and  
clean, pragmatic design.", "version": "1.3.1", "keywords": }'

{"ok":true,"\_index":"pydoc","\_type":"package","\_id":"Django","\_version":  
1}

Now, the problematic process, putting the module that has Django  
package as parent:

# curl -XPUT localhost:9200/pydoc/module/mytest?parent=Django -d

'{ "import\_name" : "django.mytest.etc", "file\_path" : "/path/to/  
module.py", "source\_code" : { "content": "" } }'

{"ok":true,"\_index":"pydoc","\_type":"module","\_id":"mytest","\_version":  
1}

Right, show me the module document we have just put:

# curl -XGET localhost:9200/pydoc/module/mytest

{"\_index":"pydoc","\_type":"module","\_id":"mytest","exists":false}

Exist false? Weird. What if we search?

# curl -XGET localhost:9200/pydoc/module/\_search?

q=import\_name:django.mytest.etc

{"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":  
5,"failed":0},"hits":{"total":1,"max\_score":1.75,"hits":  
[{"\_index":"pydoc","\_type":"module","\_id":"mytest","\_score":1.75,  
"\_source" : { "import\_name" : "django.mytest.etc", "file\_path" : "/  
path/to/module.py", "source\_code" : { "content": "" } }}]}}

No parent, no parent, no parent at all...

The funny thing when I \_search in opposite direction with has\_child  
query:

# curl -XGET localhost:9200/pydoc/package/\_search -d '{"query" : {

> ```
> "has_child": {
> "type": "module",
> "query": {
> "term": {
> "import_name" : "django.mytest.etc"
> }
> }
> }
> }
> }'
> 
> ```

gives me the expected result:  
{"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":  
5,"failed":0},"hits":{"total":1,"max\_score":1.0,"hits":  
[{"\_index":"pydoc","\_type":"package","\_id":"Django","\_score":1.0,  
"\_source" : {"description": null, "package\_name": "Django",  
"downloads": 83193, "summary": "A high-level Python Web framework that  
encourages rapid development and clean, pragmatic design.", "version":  
"1.3.1", "keywords": }}]}}

I don't understand. How can I get the parent docs from modules?

Cheers.

---

<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:** [December 16, 2011, 3:34pm UTC](https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158/2 "2011-12-16T15:34:06Z")

</div>

Answers below:

On Wed, Dec 14, 2011 at 9:26 AM, Roy E. [kirpit@gmail.com](mailto:kirpit@gmail.com) wrote:

> Hi folks,
> 
> I've been trying to create a simple parent - child relation between  
> different search types and finally gave up. I'll be happy if you guys  
> give me a hand on this;
> 
> I have 2 types of search documents, simply "package" and "module" as  
> in programming. Let's talk on the most famous web framework "Django"  
> package in Python. First, the mappings:
> 
> # curl -XGET localhost:9200/pydoc/package/\_mapping
> 
> {"package":{"\_source":{"compress":true},"\_id":  
> {"path":"package\_name"},"properties":{"summary":{"store":"yes","boost":  
> 1.2,"type":"string"},"keywords":  
> {"index\_name":"tag","store":"yes","boost":  
> 1.4,"type":"string"},"description":{"boost":  
> 0.8,"type":"string"},"package\_name":{"store":"yes","boost":  
> 1.8,"type":"string"},"downloads":  
> {"store":"yes","type":"integer"},"version":  
> {"index":"not\_analyzed","store":"yes","type":"string"}}}}
> 
> # curl -XGET localhost:9200/pydoc/module/\_mapping
> 
> {"module":{"\_source":{"compress":true},"\_routing":  
> {"required":true},"properties":{"source\_code":  
> {"path":"full","type":"attachment","fields":{"source\_code":  
> {"type":"string"},"author":{"type":"string"},"title":  
> {"type":"string"},"keywords":{"type":"string"},"date":  
> {"format":"dateOptionalTime","type":"date"},"content\_type":  
> {"type":"string"}}},"file\_path":  
> {"store":"yes","type":"string"},"import\_name":{"store":"yes","boost":  
> 1.8,"type":"string"}},"\_parent":{"type":"package"}}}
> 
> As we can see, \_parent is mapping to "package" type. Than, let's put  
> our package:
> 
> # curl -XPUT localhost:9200/pydoc/package/Django -d '{"description":
> 
> null, "package\_name": "Django", "downloads": 83193, "summary": "A high-  
> level Python Web framework that encourages rapid development and  
> clean, pragmatic design.", "version": "1.3.1", "keywords": }'
> 
> {"ok":true,"\_index":"pydoc","\_type":"package","\_id":"Django","\_version":  
> 1}
> 
> Now, the problematic process, putting the module that has Django  
> package as parent:
> 
> # curl -XPUT localhost:9200/pydoc/module/mytest?parent=Django -d
> 
> '{ "import\_name" : "django.mytest.etc", "file\_path" : "/path/to/  
> module.py", "source\_code" : { "content": "" } }'
> 
> {"ok":true,"\_index":"pydoc","\_type":"module","\_id":"mytest","\_version":  
> 1}
> 
> Right, show me the module document we have just put:
> 
> # curl -XGET localhost:9200/pydoc/module/mytest
> 
> {"\_index":"pydoc","\_type":"module","\_id":"mytest","exists":false}
> 
> Exist false? Weird.

children are mapped to the same shard as the parent (using the parent as  
the routing value). You need to provide the parent value to the get API as  
the routing value. i.e.: ?routing=Django

> What if we search?
> 
> # curl -XGET localhost:9200/pydoc/module/\_search?
> 
> q=import\_name:django.mytest.etc
> 
> {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":  
> 5,"failed":0},"hits":{"total":1,"max\_score":1.75,"hits":  
> [{"\_index":"pydoc","\_type":"module","\_id":"mytest","\_score":1.75,  
> "\_source" : { "import\_name" : "django.mytest.etc", "file\_path" : "/  
> path/to/module.py", "source\_code" : { "content": "" } }}]}}
> 
> No parent, no parent, no parent at all...

You need to explicitly ask for the \_parent field to get it back.

> The funny thing when I \_search in opposite direction with has\_child  
> query:
> 
> # curl -XGET localhost:9200/pydoc/package/\_search -d '{"query" : {
> 
> > ```
> > "has_child": {
> > "type": "module",
> > "query": {
> > "term": {
> > "import_name" : "django.mytest.etc"
> > }
> > }
> > }
> > }
> > }'
> > 
> > ```
> 
> gives me the expected result:  
> {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":  
> 5,"failed":0},"hits":{"total":1,"max\_score":1.0,"hits":  
> [{"\_index":"pydoc","\_type":"package","\_id":"Django","\_score":1.0,  
> "\_source" : {"description": null, "package\_name": "Django",  
> "downloads": 83193, "summary": "A high-level Python Web framework that  
> encourages rapid development and clean, pragmatic design.", "version":  
> "1.3.1", "keywords": }}]}}
> 
> I don't understand. How can I get the parent docs from modules?
> 
> Cheers.

---

<div class="post-metadata">

**Author:** ![Roy\_E](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_e/32/2271_2.png) [@Roy\_E](https://discuss.elastic.co/u/Roy_E)\
**Post date:** [December 21, 2011, 11:39am UTC](https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158/3 "2011-12-21T11:39:10Z")

</div>

I got it,

So you are saying that i have to do another query for each children if  
i want to display the results based on parents? Because \_parent only  
gives the id of the parent.. Don't you think that we should be able to  
access like;

"result.meta.parent.package\_name" or "result.meta.parent.version"?

cheers.

On Dec 17, 2:34 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Answers below:
> 
> On Wed, Dec 14, 2011 at 9:26 AM, Roy E. [kir...@gmail.com](mailto:kir...@gmail.com) wrote:
> 
> > Hi folks,
> 
> > I've been trying to create a simple parent - child relation between  
> > different search types and finally gave up. I'll be happy if you guys  
> > give me a hand on this;
> 
> > I have 2 types of search documents, simply "package" and "module" as  
> > in programming. Let's talk on the most famous web framework "Django"  
> > package in Python. First, the mappings:
> 
> > # curl -XGET localhost:9200/pydoc/package/\_mapping
> 
> > {"package":{"\_source":{"compress":true},"\_id":  
> > {"path":"package\_name"},"properties":{"summary":{"store":"yes","boost":  
> > 1.2,"type":"string"},"keywords":  
> > {"index\_name":"tag","store":"yes","boost":  
> > 1.4,"type":"string"},"description":{"boost":  
> > 0.8,"type":"string"},"package\_name":{"store":"yes","boost":  
> > 1.8,"type":"string"},"downloads":  
> > {"store":"yes","type":"integer"},"version":  
> > {"index":"not\_analyzed","store":"yes","type":"string"}}}}
> 
> > # curl -XGET localhost:9200/pydoc/module/\_mapping
> 
> > {"module":{"\_source":{"compress":true},"\_routing":  
> > {"required":true},"properties":{"source\_code":  
> > {"path":"full","type":"attachment","fields":{"source\_code":  
> > {"type":"string"},"author":{"type":"string"},"title":  
> > {"type":"string"},"keywords":{"type":"string"},"date":  
> > {"format":"dateOptionalTime","type":"date"},"content\_type":  
> > {"type":"string"}}},"file\_path":  
> > {"store":"yes","type":"string"},"import\_name":{"store":"yes","boost":  
> > 1.8,"type":"string"}},"\_parent":{"type":"package"}}}
> 
> > As we can see, \_parent is mapping to "package" type. Than, let's put  
> > our package:
> 
> > # curl -XPUT localhost:9200/pydoc/package/Django -d '{"description":
> > 
> > null, "package\_name": "Django", "downloads": 83193, "summary": "A high-  
> > level Python Web framework that encourages rapid development and  
> > clean, pragmatic design.", "version": "1.3.1", "keywords": }'
> 
> > {"ok":true,"\_index":"pydoc","\_type":"package","\_id":"Django","\_version":  
> > 1}
> 
> > Now, the problematic process, putting the module that has Django  
> > package as parent:
> 
> > # curl -XPUT localhost:9200/pydoc/module/mytest?parent=Django -d
> > 
> > '{ "import\_name" : "django.mytest.etc", "file\_path" : "/path/to/  
> > module.py", "source\_code" : { "content": "" } }'
> 
> > {"ok":true,"\_index":"pydoc","\_type":"module","\_id":"mytest","\_version":  
> > 1}
> 
> > Right, show me the module document we have just put:
> 
> > # curl -XGET localhost:9200/pydoc/module/mytest
> 
> > {"\_index":"pydoc","\_type":"module","\_id":"mytest","exists":false}
> 
> > Exist false? Weird.
> 
> children are mapped to the same shard as the parent (using the parent as  
> the routing value). You need to provide the parent value to the get API as  
> the routing value. i.e.: ?routing=Django
> 
> > What if we search?
> 
> > # curl -XGET localhost:9200/pydoc/module/\_search?
> > 
> > q=import\_name:django.mytest.etc
> 
> > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > 5,"failed":0},"hits":{"total":1,"max\_score":1.75,"hits":  
> > [{"\_index":"pydoc","\_type":"module","\_id":"mytest","\_score":1.75,  
> > "\_source" : { "import\_name" : "django.mytest.etc", "file\_path" : "/  
> > path/to/module.py", "source\_code" : { "content": "" } }}]}}
> 
> > No parent, no parent, no parent at all...
> 
> You need to explicitly ask for the \_parent field to get it back.
> 
> > The funny thing when I \_search in opposite direction with has\_child  
> > query:
> 
> > # curl -XGET localhost:9200/pydoc/package/\_search -d '{"query" : {
> > 
> > > ```
> > > "has_child": {
> > > "type": "module",
> > > "query": {
> > > "term": {
> > > "import_name" : "django.mytest.etc"
> > > }
> > > }
> > > }
> > > }
> > > }'
> > > 
> > > ```
> 
> > gives me the expected result:  
> > {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > 5,"failed":0},"hits":{"total":1,"max\_score":1.0,"hits":  
> > [{"\_index":"pydoc","\_type":"package","\_id":"Django","\_score":1.0,  
> > "\_source" : {"description": null, "package\_name": "Django",  
> > "downloads": 83193, "summary": "A high-level Python Web framework that  
> > encourages rapid development and clean, pragmatic design.", "version":  
> > "1.3.1", "keywords": }}]}}
> 
> > I don't understand. How can I get the parent docs from modules?
> 
> > Cheers.

---

<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:** [December 22, 2011, 12:51am UTC](https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158/4 "2011-12-22T00:51:46Z")

</div>

Yea, it would be nice to be able to access the parent in a script or  
something, but its not available now.

On Wed, Dec 21, 2011 at 1:39 PM, Roy E. [kirpit@gmail.com](mailto:kirpit@gmail.com) wrote:

> I got it,
> 
> So you are saying that i have to do another query for each children if  
> i want to display the results based on parents? Because \_parent only  
> gives the id of the parent.. Don't you think that we should be able to  
> access like;
> 
> "result.meta.parent.package\_name" or "result.meta.parent.version"?
> 
> cheers.
> 
> On Dec 17, 2:34 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Answers below:
> > 
> > On Wed, Dec 14, 2011 at 9:26 AM, Roy E. [kir...@gmail.com](mailto:kir...@gmail.com) wrote:
> > 
> > > Hi folks,
> > 
> > > I've been trying to create a simple parent - child relation between  
> > > different search types and finally gave up. I'll be happy if you guys  
> > > give me a hand on this;
> > 
> > > I have 2 types of search documents, simply "package" and "module" as  
> > > in programming. Let's talk on the most famous web framework "Django"  
> > > package in Python. First, the mappings:
> > 
> > > # curl -XGET localhost:9200/pydoc/package/\_mapping
> > 
> > > {"package":{"\_source":{"compress":true},"\_id":  
> > > {"path":"package\_name"},"properties":{"summary":{"store":"yes","boost":  
> > > 1.2,"type":"string"},"keywords":  
> > > {"index\_name":"tag","store":"yes","boost":  
> > > 1.4,"type":"string"},"description":{"boost":  
> > > 0.8,"type":"string"},"package\_name":{"store":"yes","boost":  
> > > 1.8,"type":"string"},"downloads":  
> > > {"store":"yes","type":"integer"},"version":  
> > > {"index":"not\_analyzed","store":"yes","type":"string"}}}}
> > 
> > > # curl -XGET localhost:9200/pydoc/module/\_mapping
> > 
> > > {"module":{"\_source":{"compress":true},"\_routing":  
> > > {"required":true},"properties":{"source\_code":  
> > > {"path":"full","type":"attachment","fields":{"source\_code":  
> > > {"type":"string"},"author":{"type":"string"},"title":  
> > > {"type":"string"},"keywords":{"type":"string"},"date":  
> > > {"format":"dateOptionalTime","type":"date"},"content\_type":  
> > > {"type":"string"}}},"file\_path":  
> > > {"store":"yes","type":"string"},"import\_name":{"store":"yes","boost":  
> > > 1.8,"type":"string"}},"\_parent":{"type":"package"}}}
> > 
> > > As we can see, \_parent is mapping to "package" type. Than, let's put  
> > > our package:
> > 
> > > # curl -XPUT localhost:9200/pydoc/package/Django -d '{"description":
> > > 
> > > null, "package\_name": "Django", "downloads": 83193, "summary": "A high-  
> > > level Python Web framework that encourages rapid development and  
> > > clean, pragmatic design.", "version": "1.3.1", "keywords": }'
> > 
> > >
> 
> {"ok":true,"\_index":"pydoc","\_type":"package","\_id":"Django","\_version":
> 
> > > 1}
> > 
> > > Now, the problematic process, putting the module that has Django  
> > > package as parent:
> > 
> > > # curl -XPUT localhost:9200/pydoc/module/mytest?parent=Django -d
> > > 
> > > '{ "import\_name" : "django.mytest.etc", "file\_path" : "/path/to/  
> > > module.py", "source\_code" : { "content": "" } }'
> > 
> > > {"ok":true,"\_index":"pydoc","\_type":"module","\_id":"mytest","\_version":  
> > > 1}
> > 
> > > Right, show me the module document we have just put:
> > 
> > > # curl -XGET localhost:9200/pydoc/module/mytest
> > 
> > > {"\_index":"pydoc","\_type":"module","\_id":"mytest","exists":false}
> > 
> > > Exist false? Weird.
> > 
> > children are mapped to the same shard as the parent (using the parent as  
> > the routing value). You need to provide the parent value to the get API  
> > as  
> > the routing value. i.e.: ?routing=Django
> > 
> > > What if we search?
> > 
> > > # curl -XGET localhost:9200/pydoc/module/\_search?
> > > 
> > > q=import\_name:django.mytest.etc
> > 
> > > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > > 5,"failed":0},"hits":{"total":1,"max\_score":1.75,"hits":  
> > > [{"\_index":"pydoc","\_type":"module","\_id":"mytest","\_score":1.75,  
> > > "\_source" : { "import\_name" : "django.mytest.etc", "file\_path" : "/  
> > > path/to/module.py", "source\_code" : { "content": "" } }}]}}
> > 
> > > No parent, no parent, no parent at all...
> > 
> > You need to explicitly ask for the \_parent field to get it back.
> > 
> > > The funny thing when I \_search in opposite direction with has\_child  
> > > query:
> > 
> > > # curl -XGET localhost:9200/pydoc/package/\_search -d '{"query" : {
> > > 
> > > > ```
> > > > "has_child": {
> > > > "type": "module",
> > > > "query": {
> > > > "term": {
> > > > "import_name" : "django.mytest.etc"
> > > > }
> > > > }
> > > > }
> > > > }
> > > > }'
> > > > 
> > > > ```
> > 
> > > gives me the expected result:  
> > > {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > > 5,"failed":0},"hits":{"total":1,"max\_score":1.0,"hits":  
> > > [{"\_index":"pydoc","\_type":"package","\_id":"Django","\_score":1.0,  
> > > "\_source" : {"description": null, "package\_name": "Django",  
> > > "downloads": 83193, "summary": "A high-level Python Web framework that  
> > > encourages rapid development and clean, pragmatic design.", "version":  
> > > "1.3.1", "keywords": }}]}}
> > 
> > > I don't understand. How can I get the parent docs from modules?
> > 
> > > Cheers.

---

<div class="post-metadata">

**Author:** ![Roy\_E](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_e/32/2271_2.png) [@Roy\_E](https://discuss.elastic.co/u/Roy_E)\
**Post date:** [January 1, 2012, 8:47pm UTC](https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158/5 "2012-01-01T20:47:14Z")

</div>

thanks a lot kimchy and all the elasticsearch community for letting us  
to have such a great search platform. and i also want to thank to the  
pyes community for their support on python driver.

as of now, pythonistas are able to "search" for any python package, on  
elasticsearch of course. give it a try;  
[http://pydoc.net/s?q=elastic+search](http://pydoc.net/s?q=elastic+search)

cheers,  
roy.

On Dec 22 2011, 11:51 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Yea, it would be nice to be able to access the parent in a script or  
> something, but its not available now.
> 
> On Wed, Dec 21, 2011 at 1:39 PM, Roy E. [kir...@gmail.com](mailto:kir...@gmail.com) wrote:
> 
> > I got it,
> 
> > So you are saying that i have to do another query for each children if  
> > i want to display the results based on parents? Because \_parent only  
> > gives the id of the parent.. Don't you think that we should be able to  
> > access like;
> 
> > "result.meta.parent.package\_name" or "result.meta.parent.version"?
> 
> > cheers.
> 
> > On Dec 17, 2:34 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > Answers below:
> 
> > > On Wed, Dec 14, 2011 at 9:26 AM, Roy E. [kir...@gmail.com](mailto:kir...@gmail.com) wrote:
> > > 
> > > > Hi folks,
> 
> > > > I've been trying to create a simple parent - child relation between  
> > > > different search types and finally gave up. I'll be happy if you guys  
> > > > give me a hand on this;
> 
> > > > I have 2 types of search documents, simply "package" and "module" as  
> > > > in programming. Let's talk on the most famous web framework "Django"  
> > > > package in Python. First, the mappings:
> 
> > > > # curl -XGET localhost:9200/pydoc/package/\_mapping
> 
> > > > {"package":{"\_source":{"compress":true},"\_id":  
> > > > {"path":"package\_name"},"properties":{"summary":{"store":"yes","boost":  
> > > > 1.2,"type":"string"},"keywords":  
> > > > {"index\_name":"tag","store":"yes","boost":  
> > > > 1.4,"type":"string"},"description":{"boost":  
> > > > 0.8,"type":"string"},"package\_name":{"store":"yes","boost":  
> > > > 1.8,"type":"string"},"downloads":  
> > > > {"store":"yes","type":"integer"},"version":  
> > > > {"index":"not\_analyzed","store":"yes","type":"string"}}}}
> 
> > > > # curl -XGET localhost:9200/pydoc/module/\_mapping
> 
> > > > {"module":{"\_source":{"compress":true},"\_routing":  
> > > > {"required":true},"properties":{"source\_code":  
> > > > {"path":"full","type":"attachment","fields":{"source\_code":  
> > > > {"type":"string"},"author":{"type":"string"},"title":  
> > > > {"type":"string"},"keywords":{"type":"string"},"date":  
> > > > {"format":"dateOptionalTime","type":"date"},"content\_type":  
> > > > {"type":"string"}}},"file\_path":  
> > > > {"store":"yes","type":"string"},"import\_name":{"store":"yes","boost":  
> > > > 1.8,"type":"string"}},"\_parent":{"type":"package"}}}
> 
> > > > As we can see, \_parent is mapping to "package" type. Than, let's put  
> > > > our package:
> 
> > > > # curl -XPUT localhost:9200/pydoc/package/Django -d '{"description":
> > > > 
> > > > null, "package\_name": "Django", "downloads": 83193, "summary": "A high-  
> > > > level Python Web framework that encourages rapid development and  
> > > > clean, pragmatic design.", "version": "1.3.1", "keywords": }'
> 
> > {"ok":true,"\_index":"pydoc","\_type":"package","\_id":"Django","\_version":
> > 
> > > > 1}
> 
> > > > Now, the problematic process, putting the module that has Django  
> > > > package as parent:
> 
> > > > # curl -XPUT localhost:9200/pydoc/module/mytest?parent=Django -d
> > > > 
> > > > '{ "import\_name" : "django.mytest.etc", "file\_path" : "/path/to/  
> > > > module.py", "source\_code" : { "content": "" } }'
> 
> > > > {"ok":true,"\_index":"pydoc","\_type":"module","\_id":"mytest","\_version":  
> > > > 1}
> 
> > > > Right, show me the module document we have just put:
> 
> > > > # curl -XGET localhost:9200/pydoc/module/mytest
> 
> > > > {"\_index":"pydoc","\_type":"module","\_id":"mytest","exists":false}
> 
> > > > Exist false? Weird.
> 
> > > children are mapped to the same shard as the parent (using the parent as  
> > > the routing value). You need to provide the parent value to the get API  
> > > as  
> > > the routing value. i.e.: ?routing=Django
> 
> > > > What if we search?
> 
> > > > # curl -XGET localhost:9200/pydoc/module/\_search?
> > > > 
> > > > q=import\_name:django.mytest.etc
> 
> > > > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > > > 5,"failed":0},"hits":{"total":1,"max\_score":1.75,"hits":  
> > > > [{"\_index":"pydoc","\_type":"module","\_id":"mytest","\_score":1.75,  
> > > > "\_source" : { "import\_name" : "django.mytest.etc", "file\_path" : "/  
> > > > path/to/module.py", "source\_code" : { "content": "" } }}]}}
> 
> > > > No parent, no parent, no parent at all...
> 
> > > You need to explicitly ask for the \_parent field to get it back.
> 
> > > > The funny thing when I \_search in opposite direction with has\_child  
> > > > query:
> 
> > > > # curl -XGET localhost:9200/pydoc/package/\_search -d '{"query" : {
> > > > 
> > > > > ```
> > > > > "has_child": {
> > > > > "type": "module",
> > > > > "query": {
> > > > > "term": {
> > > > > "import_name" : "django.mytest.etc"
> > > > > }
> > > > > }
> > > > > }
> > > > > }
> > > > > }'
> > > > > 
> > > > > ```
> 
> > > > gives me the expected result:  
> > > > {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > > > 5,"failed":0},"hits":{"total":1,"max\_score":1.0,"hits":  
> > > > [{"\_index":"pydoc","\_type":"package","\_id":"Django","\_score":1.0,  
> > > > "\_source" : {"description": null, "package\_name": "Django",  
> > > > "downloads": 83193, "summary": "A high-level Python Web framework that  
> > > > encourages rapid development and clean, pragmatic design.", "version":  
> > > > "1.3.1", "keywords": }}]}}
> 
> > > > I don't understand. How can I get the parent docs from modules?
> 
> > > > Cheers.

---

<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:** [January 3, 2012, 9:12am UTC](https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158/6 "2012-01-03T09:12:18Z")

</div>

Great job!

On Sun, Jan 1, 2012 at 10:47 PM, Roy E. [kirpit@gmail.com](mailto:kirpit@gmail.com) wrote:

> thanks a lot kimchy and all the elasticsearch community for letting us  
> to have such a great search platform. and i also want to thank to the  
> pyes community for their support on python driver.
> 
> as of now, pythonistas are able to "search" for any python package, on  
> elasticsearch of course. give it a try;  
> [http://pydoc.net/s?q=elastic+search](http://pydoc.net/s?q=elastic+search)
> 
> cheers,  
> roy.
> 
> On Dec 22 2011, 11:51 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Yea, it would be nice to be able to access the parent in a script or  
> > something, but its not available now.
> > 
> > On Wed, Dec 21, 2011 at 1:39 PM, Roy E. [kir...@gmail.com](mailto:kir...@gmail.com) wrote:
> > 
> > > I got it,
> > 
> > > So you are saying that i have to do another query for each children if  
> > > i want to display the results based on parents? Because \_parent only  
> > > gives the id of the parent.. Don't you think that we should be able to  
> > > access like;
> > 
> > > "result.meta.parent.package\_name" or "result.meta.parent.version"?
> > 
> > > cheers.
> > 
> > > On Dec 17, 2:34 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > > 
> > > > Answers below:
> > 
> > > > On Wed, Dec 14, 2011 at 9:26 AM, Roy E. [kir...@gmail.com](mailto:kir...@gmail.com) wrote:
> > > > 
> > > > > Hi folks,
> > 
> > > > > I've been trying to create a simple parent - child relation between  
> > > > > different search types and finally gave up. I'll be happy if you  
> > > > > guys  
> > > > > give me a hand on this;
> > 
> > > > > I have 2 types of search documents, simply "package" and "module"  
> > > > > as  
> > > > > in programming. Let's talk on the most famous web framework  
> > > > > "Django"  
> > > > > package in Python. First, the mappings:
> > 
> > > > > # curl -XGET localhost:9200/pydoc/package/\_mapping
> > 
> > > > > {"package":{"\_source":{"compress":true},"\_id":
> 
> {"path":"package\_name"},"properties":{"summary":{"store":"yes","boost":
> 
> > > > > 1.2,"type":"string"},"keywords":  
> > > > > {"index\_name":"tag","store":"yes","boost":  
> > > > > 1.4,"type":"string"},"description":{"boost":  
> > > > > 0.8,"type":"string"},"package\_name":{"store":"yes","boost":  
> > > > > 1.8,"type":"string"},"downloads":  
> > > > > {"store":"yes","type":"integer"},"version":  
> > > > > {"index":"not\_analyzed","store":"yes","type":"string"}}}}
> > 
> > > > > # curl -XGET localhost:9200/pydoc/module/\_mapping
> > 
> > > > > {"module":{"\_source":{"compress":true},"\_routing":  
> > > > > {"required":true},"properties":{"source\_code":  
> > > > > {"path":"full","type":"attachment","fields":{"source\_code":  
> > > > > {"type":"string"},"author":{"type":"string"},"title":  
> > > > > {"type":"string"},"keywords":{"type":"string"},"date":  
> > > > > {"format":"dateOptionalTime","type":"date"},"content\_type":  
> > > > > {"type":"string"}}},"file\_path":
> 
> {"store":"yes","type":"string"},"import\_name":{"store":"yes","boost":
> 
> > > > > 1.8,"type":"string"}},"\_parent":{"type":"package"}}}
> > 
> > > > > As we can see, \_parent is mapping to "package" type. Than, let's  
> > > > > put  
> > > > > our package:
> > 
> > > > > # curl -XPUT localhost:9200/pydoc/package/Django -d
> 
> '{"description":
> 
> > > > > null, "package\_name": "Django", "downloads": 83193, "summary": "A  
> > > > > high-  
> > > > > level Python Web framework that encourages rapid development and  
> > > > > clean, pragmatic design.", "version": "1.3.1", "keywords": }'
> > 
> > >
> 
> {"ok":true,"\_index":"pydoc","\_type":"package","\_id":"Django","\_version":
> 
> > > > > 1}
> > 
> > > > > Now, the problematic process, putting the module that has Django  
> > > > > package as parent:
> > 
> > > > > # curl -XPUT localhost:9200/pydoc/module/mytest?parent=Django -d
> > > > > 
> > > > > '{ "import\_name" : "django.mytest.etc", "file\_path" : "/path/to/  
> > > > > module.py", "source\_code" : { "content": "" } }'
> > 
> > > > >
> 
> {"ok":true,"\_index":"pydoc","\_type":"module","\_id":"mytest","\_version":
> 
> > > > > 1}
> > 
> > > > > Right, show me the module document we have just put:
> > 
> > > > > # curl -XGET localhost:9200/pydoc/module/mytest
> > 
> > > > > {"\_index":"pydoc","\_type":"module","\_id":"mytest","exists":false}
> > 
> > > > > Exist false? Weird.
> > 
> > > > children are mapped to the same shard as the parent (using the  
> > > > parent as  
> > > > the routing value). You need to provide the parent value to the get  
> > > > API  
> > > > as  
> > > > the routing value. i.e.: ?routing=Django
> > 
> > > > > What if we search?
> > 
> > > > > # curl -XGET localhost:9200/pydoc/module/\_search?
> > > > > 
> > > > > q=import\_name:django.mytest.etc
> > 
> > > > > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > > > > 5,"failed":0},"hits":{"total":1,"max\_score":1.75,"hits":  
> > > > > [{"\_index":"pydoc","\_type":"module","\_id":"mytest","\_score":1.75,  
> > > > > "\_source" : { "import\_name" : "django.mytest.etc", "file\_path" : "/  
> > > > > path/to/module.py", "source\_code" : { "content": "" } }}]}}
> > 
> > > > > No parent, no parent, no parent at all...
> > 
> > > > You need to explicitly ask for the \_parent field to get it back.
> > 
> > > > > The funny thing when I \_search in opposite direction with has\_child  
> > > > > query:
> > 
> > > > > # curl -XGET localhost:9200/pydoc/package/\_search -d '{"query" : {
> > > > > 
> > > > > > ```
> > > > > > "has_child": {
> > > > > > "type": "module",
> > > > > > "query": {
> > > > > > "term": {
> > > > > > "import_name" : "django.mytest.etc"
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > > }'
> > > > > > 
> > > > > > ```
> > 
> > > > > gives me the expected result:  
> > > > > {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":  
> > > > > 5,"failed":0},"hits":{"total":1,"max\_score":1.0,"hits":  
> > > > > [{"\_index":"pydoc","\_type":"package","\_id":"Django","\_score":1.0,  
> > > > > "\_source" : {"description": null, "package\_name": "Django",  
> > > > > "downloads": 83193, "summary": "A high-level Python Web framework  
> > > > > that  
> > > > > encourages rapid development and clean, pragmatic design.",  
> > > > > "version":  
> > > > > "1.3.1", "keywords": }}]}}
> > 
> > > > > I don't understand. How can I get the parent docs from modules?
> > 
> > > > > Cheers.

---

<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:44am UTC](https://discuss.elastic.co/t/no-success-to-create-parent-child-relation/6158/7 "2017-07-06T03:44:00Z")

</div>


