[TASK] Some (automated) code cleanup
[TASK] Handle JSON encoding errors during bulk request flush

This makes bulk requests safe against JSON encoding errors (e.g.
malformed UTF-8 sequences in input data).

For this bulk requests are grouped and the result of json_encode() is
checked before being added to the bulk request. If an error is detected
a log message is written.
[BUGFIX] make indexing more robust towards JSON errors