mattbaird / elastigo

A Go (golang) based Elasticsearch client library.
Apache License 2.0
943 stars 241 forks source link

tracking individual messages successes or failures in bulkindexer #236

Closed Dieterbe closed 8 years ago

Dieterbe commented 9 years ago

i would like to use the bulkindexer, but it is important for me to know which messages were successfully bulk-indexed and which were not.

how this could be done is, make func (b *BulkIndexer) Index() also take a message id (which would be like a uint64 or a []byte), keep track of the id's as the data goes through WriteBulkBytes and gets appended to b.buf so that on failed flush, we can include the appropriate id's on the ErrorChannel message, or on success we can write the succeeded id's to a SuccessChannel

that way, as the caller of the bulkindexer i can know if the/which messages were successfully processed or not, so that i can ack the message to my message queue

Dieterbe commented 8 years ago

looks like the nicest solution to this is just set a custom Sender function attribute on the BulkIndexer. Here's an example of this approach in practice: https://github.com/raintank/raintank-metric/blob/master/eventdef/eventdef.go#L169