This is our code for indexing ```export const bul...
# community-help
d
This is our code for indexing
Copy code
export const bulkIndexToTypesense = async ({
  transformedSpaces,
}: { transformedSpaces: SearchSpacesHit[] }) => {
  const spaceDocuments: SearchSpacesHit[] = transformedSpaces;
  const indexName =
    Config.STAGE === "prod" ? IndexNames.onde_sites : IndexNames.onde_sites_dev;

  <http://logger.info|logger.info>(
    spaceDocuments.map((e) => e.id),
    "Processing spaces",
  );

  const client = getAdminClient(Config.TYPESENSE_ADMIN_API_KEY);
  try {
    const res = await client
      .collections<SearchSpacesHit & { embedding?: number[] }>(indexName)
      .documents()
      .import(spaceDocuments, { action: "upsert" });
    return { res, error: null };
  } catch (err) {
    if (err instanceof ImportError) {
      logger.error(err, "Error indexing to Typesense");
      return {
        error: err.importResults.filter((e) => !e.success),
        res: null,
      };
    }
    return { error: err, res: null };
  }
};