Trying to import MongoDB documents as separate types in elasticsearch

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

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), the data is indexed with the MongoDB collection 'categories' being the only type, while all the MongoDB documents are elasticsearch documents:

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.

Note that mapping types are being deprecated 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.

1 Like

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 with reactive search.

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