# River MongoDB-\>Elasticsearch (parent/child)

**URL:** <https://discuss.elastic.co/t/river-mongodb-elasticsearch-parent-child/20303>\
**Category:** Elasticsearch\
**Created:** [October 17, 2014, 1:14pm UTC](https://discuss.elastic.co/t/river-mongodb-elasticsearch-parent-child/20303 "2014-10-17T13:14:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ludovic\_MEYER](https://avatars.discourse-cdn.com/v4/letter/l/e8c25b/32.png) [@Ludovic\_MEYER](https://discuss.elastic.co/u/Ludovic_MEYER)\
**Post date:** [October 17, 2014, 1:14pm UTC](https://discuss.elastic.co/t/river-mongodb-elasticsearch-parent-child/20303/1 "2014-10-17T13:14:52Z")

</div>

Hello,

I'm looking for a solution to creat parent/child relation with the script  
of the river mongodb-\>ES plugine.

I don't know if the relation parent/child must be present already in  
MongoDB to do that. For now, I just have the field "parent\_id" in the all  
document with an ID which is the same between the parent and children. The  
type (parent or child) is in the field "estype" to dispatch them in their  
right type.

My mapping :

POST mongo\_index\_log  
{  
"mappings": {  
"parent": {},  
"child": {  
"\_parent": {"type": "parent"}  
}  
},  
"settings": {  
"number\_of\_shards": 1,  
"number\_of\_replica": 0  
}  
}

My river :

PUT \_river/mongo\_index\_log/\_meta  
{  
"type": "mongodb",  
"mongodb": {  
"servers": [  
{ "host": "127.0.0.1", "port": 27017 }  
],  
"options": { "secondary\_read\_preference": true },  
"db": "test",  
"collection": "mongodb\_base",  
"script": "ctx.\_type = ctx.document.estype; if (ctx.\_type == 'fils') {  
ctx.\_parent = ctx.document.parent\_id; }"  
},  
"index": {  
"name": "mongo\_index\_log",  
"type": "mongo\_type"  
}  
}

In this case, the split into the right type is ok, but the relarion  
parent/child doesn't do anything when I put the following command : (and  
i'm waiting for the parent who have at least 1 child)

POST mongo\_index\_log/parent/\_search  
{  
"query": {  
"bool": {  
"must": [  
{  
"top\_children": {  
"type": "child",  
"query": {  
"match\_all": {}  
}  
}  
}  
]  
}  
}  
}

Also, i tried changing the "\_id" of the parent like that :

"script": "ctx.\_type = ctx.document.estype; if (ctx.\_type == 'fils') {  
ctx.\_parent = ctx.document.parent\_id; } else { ctx.\_id =  
ctx.document.parent\_id; } "

But in this case, the split in the right type doe'nt works et so the  
relation parent/child neither.

Any ideas ? I found on this link, but nothing about my problems :  
[https://github.com/richardwilly98/elasticsearch-river-mongodb/tree/master/manual-testing/issues/64](https://github.com/richardwilly98/elasticsearch-river-mongodb/tree/master/manual-testing/issues/64)

Have a good day,

--  
Ludovic M

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fba13a13-afaa-464f-ad82-b57c8e86197b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fba13a13-afaa-464f-ad82-b57c8e86197b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:55am UTC](https://discuss.elastic.co/t/river-mongodb-elasticsearch-parent-child/20303/2 "2017-07-06T00:55:30Z")

</div>


