private void processBody(QueueingConsumer.Delivery task, BulkRequestBuilder bulkRequestBuilder)
        throws Exception {
      if (null == task) return;
      byte[] body = task.getBody();
      if (body == null) return;

      // check for custom commands, which can be specified in the task header
      String customCommand = null;
      Map<String, Object> headers = task.getProperties().getHeaders();
      if (null != headers) {
        Object headerVal = headers.get("X-ES-Command");
        if (null != headerVal) customCommand = headerVal.toString();
      }

      if (null == customCommand || customCommand.isEmpty()) {
        // first, the "full bulk" script
        if (bulkScript != null) {
          String bodyStr = new String(body);
          bulkScript.setNextVar("body", bodyStr);
          String newBodyStr = (String) bulkScript.run();
          if (newBodyStr == null) return;
          body = newBodyStr.getBytes();
        }

        // second, the "doc per doc" script
        if (script != null) {
          processBodyPerLine(body, bulkRequestBuilder);
        } else {
          bulkRequestBuilder.add(body, 0, body.length, false);
        }
      } else {
        // handle the custom command
        handleCustomCommand(customCommand, task);
      }
    }