# Trying to import MongoDB documents as separate types in elasticsearch

**URL:** <https://discuss.elastic.co/t/trying-to-import-mongodb-documents-as-separate-types-in-elasticsearch/142034>\
**Category:** Elasticsearch\
**Created:** [July 28, 2018, 3:22pm UTC](https://discuss.elastic.co/t/trying-to-import-mongodb-documents-as-separate-types-in-elasticsearch/142034 "2018-07-28T15:22:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![committer](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@committer](https://discuss.elastic.co/u/committer)\
**Post date:** [July 28, 2018, 3:22pm UTC](https://discuss.elastic.co/t/trying-to-import-mongodb-documents-as-separate-types-in-elasticsearch/142034/1 "2018-07-28T15:22:56Z")

</div>

If there's anybody who can point me in the right direction, that would be greatly appreciated 🙂

I'm able to import a collection from MongoDB to elasticsearch, with the following transform\_file.js code:

```
t.Source("source", source, '/^categories$/').Save("sink", sink, "/.*/")

```

In elasticsearch (using [appbase.io](http://appbase.io)), the data is indexed with the MongoDB collection 'categories' being the only type, while all the MongoDB documents are elasticsearch documents:

 ![2018-07-28_1642](https://us1.discourse-cdn.com/elastic/original/3X/b/5/b51676ae7edd0f16c564371b20dd63e9f95e26ec.png)

However, I want each of the MongoDB documents to instead be their own elasticsearch type. So instead of 'categories' being the only type in elasticsearch, I want the types to be BMW and Audi. Ideally named category\_bmw and category\_audi.

I assume it's the code after '.Save' that has to be changed, but I'm not exactly sure what changes to make.

EDIT: I'm using elasticsearch version 5.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 29, 2018, 11:01am UTC](https://discuss.elastic.co/t/trying-to-import-mongodb-documents-as-separate-types-in-elasticsearch/142034/2 "2018-07-29T11:01:33Z")

</div>

Note that [mapping types are being deprecated](https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html) and indices with more than one type can not be created in version 6.0 onwards. By relying on different types in your induces you are setting yourself up for a difficult upgrade path.

---

<div class="post-metadata">

**Author:** ![committer](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@committer](https://discuss.elastic.co/u/committer)\
**Post date:** [July 29, 2018, 12:04pm UTC](https://discuss.elastic.co/t/trying-to-import-mongodb-documents-as-separate-types-in-elasticsearch/142034/3 "2018-07-29T12:04:01Z")

</div>

Thanks for letting me know. I assume I would just have to make some changes to the transform\_files.js when upgrading to v6. Any alternative way you would suggest I do this? Using mapping types seems to be the only way I can do this at the moment, because I'm using [appbase.io](http://appbase.io) with reactive search.

---

<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:** [August 26, 2018, 12:04pm UTC](https://discuss.elastic.co/t/trying-to-import-mongodb-documents-as-separate-types-in-elasticsearch/142034/4 "2018-08-26T12:04:04Z")

</div>

Closed on August 26, 2018, 12:04pm UTC

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