# Best way to migrate data from mongoDB to elastic

**URL:** <https://discuss.elastic.co/t/best-way-to-migrate-data-from-mongodb-to-elastic/362671>\
**Category:** Elastic Search\
**Tags:** connectors\
**Created:** [July 8, 2024, 5:15am UTC](https://discuss.elastic.co/t/best-way-to-migrate-data-from-mongodb-to-elastic/362671 "2024-07-08T05:15:24Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)\
**Post date:** [July 11, 2024, 11:50am UTC](https://discuss.elastic.co/t/best-way-to-migrate-data-from-mongodb-to-elastic/362671/10 "2024-07-11T11:50:37Z")

</div>

> [@Moni\_Hazarika](#):
>
> - the bulk api can be used for events that belong to 1 tenant right? If we maybe be fix the change events for different tenant how will the filtering of data per tenant happen?

[Bulk API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html) allows to perform operations on different indices:

```json
POST _bulk
{ "index" : { "_index" : "test1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test2", "_id" : "2" } }
{ "create" : { "_index" : "test3", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test4"} }
{ "doc" : {"field2" : "value2"} }

```

Each doc line is preceded by a metadata line that indicates the action and the target index.

> [@Moni\_Hazarika](#):
>
> - even for the same tenant using bulk api would mean introducing some lag right?

If you mean the lag between the indexing is done vs when it is available for search, yes there is. There's a tradeoff between [tuning for indexing speed](https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html) and [tuning for search speed](https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-search-speed.html).

You will need to check what your refresh interval should be, and the overall indexing strategy, depending on your data size and needs.

Bulk API is the most effective way of dealing with bulk changes and the way to go for your integration with change streams.

It would also be interesting to check [this post](https://discuss.elastic.co/t/how-to-implement-multi-tenant-environment-in-elasticsearch/341606/11) with a discussion of multi tenancy implementation in Elasticsearch.

---

_[View the full topic](https://discuss.elastic.co/t/best-way-to-migrate-data-from-mongodb-to-elastic/362671)._
