# Create parent field mapping in ES with MongoDB-river

**URL:** <https://discuss.elastic.co/t/create-parent-field-mapping-in-es-with-mongodb-river/10874>\
**Category:** Elasticsearch\
**Created:** [February 25, 2013, 7:09am UTC](https://discuss.elastic.co/t/create-parent-field-mapping-in-es-with-mongodb-river/10874 "2013-02-25T07:09:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Margaret\_2](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@Margaret\_2](https://discuss.elastic.co/u/Margaret_2)\
**Post date:** [February 25, 2013, 7:09am UTC](https://discuss.elastic.co/t/create-parent-field-mapping-in-es-with-mongodb-river/10874/1 "2013-02-25T07:09:25Z")

</div>

I have some data stored in MongoDB. These data are separated into two  
collections: one is 'bare\_authors' which contains basic information of  
authors like name; the other one is 'books' which contains information of  
books written by the author. For example, in MongoDB, we have:

db.bare\_authors.find()  
{ "\_id" : ObjectId("512b01b955922c6270d96d8e"), "name" : "Multi G.Enre" }  
{ "\_id" : ObjectId("512b01c455922c6270d96d8f"), "name" : "Alastair  
Reynolds" }

db.books.find()  
{ "\_id" : ObjectId("512af8d455922c6270d96d8c"), "name" : "Revelation  
Space", "genre" : "scifi" }  
{ "\_id" : ObjectId("512af99155922c6270d96d8d"), "name" : "Dead in the  
night", "genre" : "thriller" }

I want to use the 'parent field mapping' in ES. So I created a mapping in  
elasticsearch:

$ curl -XPOST localhost:9200/authors/book/\_mapping -d '{  
"book":{  
"\_parent":{"type":"bare\_author"}  
}  
}'

Then I created the river:

$ curl -XPUT '[http://localhost:9200/\_river/authors/\_meta](http://localhost:9200/_river/authors/_meta)' -d '  
{  
type:"mongodb",  
mongodb:{  
db:"authors",collection:"bare\_authors",  
host:"localhost",  
port:"27017"  
},  
index:{  
name:"authors",  
type:"bare\_author",  
bulk\_size:"1000",  
bulk\_timeout:"30"  
}  
}'  
{"ok":true,"\_index":"\_river","\_type":"authors","\_id":"\_meta","\_version":1}

and

$ curl -XPUT '[http://localhost:9200/\_river/books/\_meta](http://localhost:9200/_river/books/_meta)' -d '  
{  
type:"mongodb",  
mongodb:{  
db:"authors",collection:"books",  
host:"localhost",  
port:"27017"  
},  
index:{  
name:"authors",  
type:"book",  
bulk\_size:"1000",  
bulk\_timeout:"30"  
}  
}'  
{"ok":true,"\_index":"\_river","\_type":"books","\_id":"\_meta","\_version":1}

But I got error:

org.elasticsearch.action.RoutingMissingException: routing is required for  
[authors]/[book]/[512b01dd55922c6270d96d91]

Can anyone help? Thanks.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [February 25, 2013, 11:46am UTC](https://discuss.elastic.co/t/create-parent-field-mapping-in-es-with-mongodb-river/10874/2 "2013-02-25T11:46:58Z")

</div>

I have no experience with the mongo river, but in general when indexing  
child documents the parent id needs to be provided during the index  
operation. That doesn't seem to happen here. A quick look at the plugin  
tells me that specifying the parent id during indexing isn't implemented.  
Maybe writing a small script that syncs your data with ES is sufficient in  
your case?

Martijn

On 25 February 2013 08:09, Maggie [xiaowen.huang.bjtu@gmail.com](mailto:xiaowen.huang.bjtu@gmail.com) wrote:

> I have some data stored in MongoDB. These data are separated into two  
> collections: one is 'bare\_authors' which contains basic information of  
> authors like name; the other one is 'books' which contains information of  
> books written by the author. For example, in MongoDB, we have:
> 
> db.bare\_authors.find()  
> { "\_id" : ObjectId("512b01b955922c6270d96d8e"), "name" : "Multi G.Enre" }  
> { "\_id" : ObjectId("512b01c455922c6270d96d8f"), "name" : "Alastair  
> Reynolds" }
> 
> db.books.find()  
> { "\_id" : ObjectId("512af8d455922c6270d96d8c"), "name" : "Revelation  
> Space", "genre" : "scifi" }  
> { "\_id" : ObjectId("512af99155922c6270d96d8d"), "name" : "Dead in the  
> night", "genre" : "thriller" }
> 
> I want to use the 'parent field mapping' in ES. So I created a mapping in  
> elasticsearch:
> 
> $ curl -XPOST localhost:9200/authors/book/\_mapping -d '{  
> "book":{  
> "\_parent":{"type":"bare\_author"}  
> }  
> }'
> 
> Then I created the river:
> 
> $ curl -XPUT '[http://localhost:9200/\_river/authors/\_meta](http://localhost:9200/_river/authors/_meta)' -d '  
> {  
> type:"mongodb",  
> mongodb:{  
> db:"authors",collection:"bare\_authors",  
> host:"localhost",  
> port:"27017"  
> },  
> index:{  
> name:"authors",  
> type:"bare\_author",  
> bulk\_size:"1000",  
> bulk\_timeout:"30"  
> }  
> }'  
> {"ok":true,"\_index":"\_river","\_type":"authors","\_id":"\_meta","\_version":1}
> 
> and
> 
> $ curl -XPUT '[http://localhost:9200/\_river/books/\_meta](http://localhost:9200/_river/books/_meta)' -d '  
> {  
> type:"mongodb",  
> mongodb:{  
> db:"authors",collection:"books",  
> host:"localhost",  
> port:"27017"  
> },  
> index:{  
> name:"authors",  
> type:"book",  
> bulk\_size:"1000",  
> bulk\_timeout:"30"  
> }  
> }'  
> {"ok":true,"\_index":"\_river","\_type":"books","\_id":"\_meta","\_version":1}
> 
> But I got error:
> 
> org.elasticsearch.action.RoutingMissingException: routing is required for  
> [authors]/[book]/[512b01dd55922c6270d96d91]
> 
> Can anyone help? Thanks.
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:49am UTC](https://discuss.elastic.co/t/create-parent-field-mapping-in-es-with-mongodb-river/10874/3 "2017-07-06T02:49:44Z")

</div>


