public function flush()
    {
        $bulkRequest = array_filter($this->currentBulkRequest);
        if (count($bulkRequest) === 0) {
            return;
        }

        $content = '';
        foreach ($bulkRequest as $bulkRequestTuple) {
            $tupleAsJson = '';
            foreach ($bulkRequestTuple as $bulkRequestItem) {
                $itemAsJson = json_encode($bulkRequestItem);
                if ($itemAsJson === false) {
                    $this->errorHandlingService->log(
                        new MalformedBulkRequestError('Indexing Error: Bulk request item could not be encoded as JSON - ' . json_last_error_msg(), $bulkRequestItem)
                    );
                    continue 2;
                }
                $tupleAsJson .= $itemAsJson . chr(10);
            }
            $content .= $tupleAsJson;
        }

        if ($content !== '') {
            $response = $this->requestDriver->bulk($this->getIndex(), $content);
            foreach ($response as $responseLine) {
                if (isset($response['errors']) && $response['errors'] !== false) {
                    $this->errorHandlingService->log(
                        new BulkIndexingError($this->currentBulkRequest, $responseLine)
                    );
                }
            }
        }

        $this->currentBulkRequest = [];
    }