code: def bulk_upload(self, items, field_id):
          
  
          current = 0
          new_items = 0  # total items added with bulk
          bulk_json = ""
  
          if not items:
              return new_items
  
          url = self.index_url + '/items/_bulk'
  
          logger.debug("Adding items to %s (in %i packs)", self.anonymize_url(url), self.max_items_bulk)
          task_init = time()
  
          for item in items:
              if current >= self.max_items_bulk:
                  task_init = time()
                  new_items += self.safe_put_bulk(url, bulk_json)
                  current = 0
                  json_size = sys.getsizeof(bulk_json) / (1024 * 1024)
                  logger.debug("bulk packet sent (%.2f sec, %i total, %.2f MB)"
                               % (time() - task_init, new_items, json_size))
                  bulk_json = ""
              data_json = json.dumps(item)
              bulk_json += '{"index" : {"_id" : "%s" } }\n' % (item[field_id])
              bulk_json += data_json + "\n"  # Bulk document
              current += 1
  
          if current > 0:
              new_items += self.safe_put_bulk(url, bulk_json)
              json_size = sys.getsizeof(bulk_json) / (1024 * 1024)
              logger.debug("bulk packet sent (%.2f sec prev, %i total, %.2f MB)"
                           % (time() - task_init, new_items, json_size))
  
          return new_items
docs: Upload in controlled packs items to ES using bulk API