When to insert data into elasticsearch?

I use mongodb as my primary data store and am planning to use elastic search for full text search.I have two options of inserting data in elasticsearch.
One is to insert formatted data at the same time I insert it mongodb,i.e., when user enters the data in the website.
Other is to create a replica of mongodb cluster and read from oplogs and carry out the operations in elasticsearch. This is the passive approach and some data will not be available in real time.
How should I choose between these methods or is their some other way available ??

I would prefer your first option. Keep Elasticsearch in sync to be able to search in your data in (near) real time. The latter seems more complex and I do not see the benefits.

1 Like