Index the records flagged as "to_index" on databox
called by task "indexer"

@param BulkOperation $bulk
@param databox $databox
324209
public function indexScheduled(BulkOperation $bulk, databox $databox)
    {
        $submitted_records = [];

        // Make fetcher
        $delegate = new ScheduledFetcherDelegate();
        $fetcher = $this->fetcherFactory->createFetcher($databox, $delegate);

        // post fetch : flag records as "indexing"
        $fetcher->setPostFetch(function(array $records) use ($databox, $fetcher) {
            $this->logger->debug(sprintf("indexing %d records", count($records)));
            RecordQueuer::didStartIndexingRecords($records, $databox);
            // because changing the flag on the records affects the "where" clause of the fetcher,
            // restart it each time
            $fetcher->restart();
        });

        // bulk flush : flag records as "indexed"
        $bulk->onFlush(function($operation_identifiers) use ($databox, &$submitted_records) {
            $this->onBulkFlush($databox, $operation_identifiers, $submitted_records);
        });

        // Perform indexing
        $this->indexFromFetcher($bulk, $fetcher, $submitted_records);
    }
1258475
protected base_resource[] get_nitro_bulk_response(nitro_service service, String response) throws Exception
	{
		mps_upgrade_responses result = (mps_upgrade_responses) service.get_payload_formatter().string_to_resource(mps_upgrade_responses.class, response);
		if(result.errorcode != 0)
		{
			if (result.errorcode == SESSION_NOT_EXISTS)
				service.clear_session();
			throw new nitro_exception(result.message, result.errorcode, (base_response [])result.mps_upgrade_response_array);
		}
		mps_upgrade[] result_mps_upgrade = new mps_upgrade[result.mps_upgrade_response_array.length];
		
		for(int i = 0; i < result.mps_upgrade_response_array.length; i++)
		{
			result_mps_upgrade[i] = result.mps_upgrade_response_array[i].mps_upgrade[0];
		}
		
		return result_mps_upgrade;
	}
850557
protected base_resource[] get_nitro_bulk_response(nitro_service service, String response) throws Exception
	{
		xen_health_resource_sw_responses result = (xen_health_resource_sw_responses) service.get_payload_formatter().string_to_resource(xen_health_resource_sw_responses.class, response);
		if(result.errorcode != 0)
		{
			if (result.errorcode == SESSION_NOT_EXISTS)
				service.clear_session();
			throw new nitro_exception(result.message, result.errorcode, (base_response [])result.xen_health_resource_sw_response_array);
		}
		xen_health_resource_sw[] result_xen_health_resource_sw = new xen_health_resource_sw[result.xen_health_resource_sw_response_array.length];
		
		for(int i = 0; i < result.xen_health_resource_sw_response_array.length; i++)
		{
			result_xen_health_resource_sw[i] = result.xen_health_resource_sw_response_array[i].xen_health_resource_sw[0];
		}
		
		return result_xen_health_resource_sw;
	}
103906
public static function get_records_by_originalname(databox $databox, $original_name, $caseSensitive = false, $offset_start = 0, $how_many = 10)
    {
        $offset_start = max(0, (int)$offset_start);
        $how_many = max(1, (int)$how_many);

        $sql = sprintf(
            'SELECT record_id FROM record WHERE originalname = :original_name COLLATE %s LIMIT %d, %d',
            $caseSensitive ? 'utf8_bin' : 'utf8_unicode_ci',
            $offset_start,
            $how_many
        );

        $stmt = $databox->get_connection()->prepare($sql);
        $stmt->execute([':original_name' => $original_name]);
        $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $stmt->closeCursor();

        $records = [];
        foreach ($rs as $row) {
            $records[] = $databox->get_record($row['record_id']);
        }

        return $records;
    }
121399
protected base_resource[] get_nitro_bulk_response(nitro_service service, String response) throws Exception
	{
		br_broker_responses result = (br_broker_responses) service.get_payload_formatter().string_to_resource(br_broker_responses.class, response);
		if(result.errorcode != 0)
		{
			if (result.errorcode == SESSION_NOT_EXISTS)
				service.clear_session();
			throw new nitro_exception(result.message, result.errorcode, (base_response [])result.br_broker_response_array);
		}
		br_broker[] result_br_broker = new br_broker[result.br_broker_response_array.length];
		
		for(int i = 0; i < result.br_broker_response_array.length; i++)
		{
			result_br_broker[i] = result.br_broker_response_array[i].br_broker[0];
		}
		
		return result_br_broker;
	}
24783
public void index(ViewDoc viewDoc) {
    BulkIndexer bulk = new BulkIndexer(esClient, TYPE_VIEW, Size.REGULAR);
    bulk.start();
    doIndex(bulk, viewDoc, true);
    bulk.stop();
  }
349171
public BulkRequestBuilder buildBulkIndexRequestBuilder(
            List<IndexRequestBuilder> indexRequestBuilderList) {
        BulkRequestBuilder bulkRequestBuilder = jmESClient.prepareBulk();
        for (IndexRequestBuilder indexRequestBuilder : indexRequestBuilderList)
            bulkRequestBuilder.add(indexRequestBuilder);
        return bulkRequestBuilder;
    }
1019628
protected base_resource[] get_nitro_bulk_response(nitro_service service, String response) throws Exception
	{
		br_configuresyslog_responses result = (br_configuresyslog_responses) service.get_payload_formatter().string_to_resource(br_configuresyslog_responses.class, response);
		if(result.errorcode != 0)
		{
			if (result.errorcode == SESSION_NOT_EXISTS)
				service.clear_session();
			throw new nitro_exception(result.message, result.errorcode, (base_response [])result.br_configuresyslog_response_array);
		}
		br_configuresyslog[] result_br_configuresyslog = new br_configuresyslog[result.br_configuresyslog_response_array.length];
		
		for(int i = 0; i < result.br_configuresyslog_response_array.length; i++)
		{
			result_br_configuresyslog[i] = result.br_configuresyslog_response_array[i].br_configuresyslog[0];
		}
		
		return result_br_configuresyslog;
	}
1124228
public function bulkWrite($namespace, $bulk)
    {
        if ($this->_writeConcern === null) {
            try {
                $this->_writeConcern = new WriteConcern(WriteConcern::MAJORITY, 10000);
            } catch (\Exception $exception) {
                throw new MongodbException($exception->getMessage(), $exception->getCode(), $exception);
            }
        }

        $start_time = microtime(true);
        if ($start_time - $this->_last_heartbeat > 1.0) {
            $this->_last_heartbeat = null;
        }
        try {
            $result = $this->_getManager()->executeBulkWrite($namespace, $bulk, $this->_writeConcern);
        } catch (\Exception $exception) {
            throw new MongodbException($exception->getMessage(), $exception->getCode(), $exception);
        }

        return $result;
    }
622810
protected function getNullUUIDs(\databox $databox)
    {
        $sql = 'SELECT r.coll_id, r.type, r.record_id, s.path, s.file, r.xml
                FROM record r, subdef s
                        WHERE ISNULL(uuid)
                        AND s.record_id = r.record_id AND s.name="document"
                        AND parent_record_id = 0 LIMIT 100';

        $stmt = $databox->get_connection()->prepare($sql);
        $stmt->execute();
        $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        $stmt->closeCursor();

        return $rs;
    }
353878
public void sendBulkDataAsync(List<? extends Map<String, ?>> bulkSourceList,
            String index, String type) {
        executeBulkRequestAsync(
                buildBulkIndexRequestBuilder(bulkSourceList
                        .stream().map(source -> jmESClient
                                .prepareIndex(index, type).setSource(source))
                        .collect(toList())));
    }
580099
protected base_resource[] get_nitro_bulk_response(nitro_service service, String response) throws Exception
	{
		syslog_sslvpn_responses result = (syslog_sslvpn_responses) service.get_payload_formatter().string_to_resource(syslog_sslvpn_responses.class, response);
		if(result.errorcode != 0)
		{
			if (result.errorcode == SESSION_NOT_EXISTS)
				service.clear_session();
			throw new nitro_exception(result.message, result.errorcode, (base_response [])result.syslog_sslvpn_response_array);
		}
		syslog_sslvpn[] result_syslog_sslvpn = new syslog_sslvpn[result.syslog_sslvpn_response_array.length];
		
		for(int i = 0; i < result.syslog_sslvpn_response_array.length; i++)
		{
			result_syslog_sslvpn[i] = result.syslog_sslvpn_response_array[i].syslog_sslvpn[0];
		}
		
		return result_syslog_sslvpn;
	}
775646
protected function getDataboxTimeEstimation(\databox $databox)
    {
        $sql = 'SELECT r.coll_id, r.type, r.record_id, s.path, s.file, r.xml
                FROM record r, subdef s
                        WHERE ISNULL(uuid)
                        AND s.record_id = r.record_id AND s.name="document"
                        AND parent_record_id = 0';

        $stmt = $databox->get_connection()->prepare($sql);
        $stmt->execute();
        $quantity = $stmt->rowCount();
        $stmt->closeCursor();

        return $quantity;
    }
711412
protected function updateRecordUUID(\databox $databox, array $record)
    {
        $pathfile = \p4string::addEndSlash($record['path']) . $record['file'];

        $uuid = Uuid::uuid4();
        try {
            $media = $this->app->getMediaFromUri($pathfile);
            $collection = \collection::getByCollectionId($this->$app, $databox, (int) $record['coll_id']);

            $file = new File($this->app, $media, $collection);
            $uuid = $file->getUUID(true, true);
            $sha256 = $file->getSha256();

            $this->app['monolog']->addInfo(sprintf("Upgrading record %d with uuid %s", $record['record_id'], $uuid));
        } catch (\Exception $e) {
            $this->app['monolog']->addError(sprintf("Uuid upgrade for record %s failed", $record['record_id']));
        }

        $sql = 'UPDATE record SET uuid = :uuid, sha256 = :sha256 WHERE record_id = :record_id';

        $params = [
            ':uuid'      => $uuid,
            'sha256'     => $sha256,
            ':record_id' => $record['record_id'],
        ];
        $stmt = $databox->get_connection()->prepare($sql);
        $stmt->execute($params);
        $stmt->closeCursor();
    }
238497
protected base_resource[] get_nitro_bulk_response(nitro_service service, String response) throws Exception
	{
		ns_responses result = (ns_responses) service.get_payload_formatter().string_to_resource(ns_responses.class, response);
		if(result.errorcode != 0)
		{
			if (result.errorcode == SESSION_NOT_EXISTS)
				service.clear_session();
			throw new nitro_exception(result.message, result.errorcode, (base_response [])result.ns_response_array);
		}
		ns[] result_ns = new ns[result.ns_response_array.length];
		
		for(int i = 0; i < result.ns_response_array.length; i++)
		{
			result_ns[i] = result.ns_response_array[i].ns[0];
		}
		
		return result_ns;
	}
1251390
protected base_resource[] get_nitro_bulk_response(nitro_service service, String response) throws Exception
	{
		host_device_responses result = (host_device_responses) service.get_payload_formatter().string_to_resource(host_device_responses.class, response);
		if(result.errorcode != 0)
		{
			if (result.errorcode == SESSION_NOT_EXISTS)
				service.clear_session();
			throw new nitro_exception(result.message, result.errorcode, (base_response [])result.host_device_response_array);
		}
		host_device[] result_host_device = new host_device[result.host_device_response_array.length];
		
		for(int i = 0; i < result.host_device_response_array.length; i++)
		{
			result_host_device[i] = result.host_device_response_array[i].host_device[0];
		}
		
		return result_host_device;
	}
258330
def run_bulk(t, first, last, incr = 1)
                retry_until { DRMAA.run_bulk_jobs(t.ptr, first, last, incr) }
            end