I am using elastic
package for golang
. I want to use its BulkProcessor
for sending huge amount of documents in background. As per shown in wiki, I could create a processor. But I don't want to create it every time I send the documents. I want to know if there is processor service exists in the connection and pass data to existing processor rather than creating new. How can I achieve it?
Register the bulk processor separately from sending the documents. The bulk processor only lives as long as your process, so to ensure you only create it once, create it when your process starts. Then elsewhere in your application, you can send documents whenever you need to.
Alternatively, if you must do it on-demand, you can use a sync.Once
to ensure the creation only happens once.