> ## Documentation Index
> Fetch the complete documentation index at: https://www.algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CSV connector

> Use the CSV connector to index data from a hosted CSV file.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

export const Index = () => <Tooltip tip="An Algolia index is a searchable dataset that consists of records and configuration settings. These settings define how the records are searched and ranked.">
    index
  </Tooltip>;

Use the CSV connector to index <Records /> from a hosted CSV file without writing an indexing script.
In this quickstart, you create a source for a public product dataset, use an Algolia <Index /> destination,
and an on-demand synchronization task.

## Before you begin

If you don't have an Algolia account, [create one](https://www.algolia.com/users/sign_up) for free.

## Index a sample dataset with the CSV connector

Create a source, destination, transformation, and synchronization task for the sample product dataset.

* The source tells the connector where to fetch the CSV file.
* The destination tells the connector which Algolia index to write to.
* The transformation changes records before the connector indexes them.
* The task controls when the connector runs.

<Steps>
  <Step title="Choose the CSV connector">
    Go to the Algolia dashboard and select your Algolia application.
    Open the [**Connectors**](https://dashboard.algolia.com/connectors) page.

    Find **CSV**, then select **Connect**.
  </Step>

  <Step title="Configure the CSV source">
    Under **Configure your data source**, select **Create a new source**.

    Under **Is your data source protected?**, select **None**.

    In **URL**, enter:

    ```txt theme={"system"}
     https://raw.githubusercontent.com/algolia/quickstarts/main/sample-data/apparel.csv
    ```

    For **HTTP Method**, select **GET**.
  </Step>

  <Step title="Configure column types">
    In **Unique column identifier**, enter `objectID`.

    Under **Column type mapping**, add these columns and select the corresponding type:

    | Column name  | Type        |
    | ------------ | ----------- |
    | `price`      | **integer** |
    | `taxable`    | **boolean** |
    | `units_sold` | **integer** |
    | `weight`     | **float**   |
  </Step>

  <Step title="Create the CSV source">
    In **Connector name**, enter `Quickstart products CSV source`, then select **Create source**.
  </Step>

  <Step title="Transform the records" id="transform">
    This transformation adds a `price_range` attribute to each record.
    After the connector indexes your records, you can display `price_range` or configure it as a facet.

    Select **Transform using the code editor** and replace the placeholder **Transformation code** with this function:

    ```js JavaScript icon=code expandable theme={"system"}
    async function transform(record, helper) {
        const price = Number(record.price);
        if (!Number.isFinite(price)) {
            return record;
        }
        if (price < 25) {
            record.price_range = "Under $25";
        } else if (price < 50) {
            record.price_range = "$25 to $49";
        } else if (price < 100) {
            record.price_range = "$50 to $99";
        } else {
            record.price_range = "$100 and up";
        }
        return record;
    }
    ```

    Select **Save**.
  </Step>

  <Step title="Choose the destination index">
    Under **Configure your destination**, select **Create a new destination**.

    Under **Search**, enter `quickstart-products` as the index name.

    <Warning>
      If you enter the name of an existing index, the connector overwrites the records and settings in that index.
    </Warning>
  </Step>

  <Step title="Create the destination">
    Under **Index credentials**, select **Create one for me**.

    To use an existing API key, choose one with the `addObject`, `deleteIndex`, and `editSettings` [ACLs](/doc/guides/security/api-keys#access-control-list-acl).

    In **Name**, enter `CSV quickstart products destination`, then select **Create destination**.
  </Step>

  <Step title="Create an on-demand synchronization task">
    Under **Configure your task**, select **On demand** and **Full reindexing**.

    Select **Create task**, then **Run** and wait for the task to finish.
  </Step>

  <Step title="Verify the indexed records">
    When the task completes, open the [`quickstart-products` index in the Algolia dashboard](https://dashboard.algolia.com/explorer/browse/quickstart-products).
    The index contains product records with attributes such as `title`, `description`, `product_type`, `price`, `price_range`, and `showcase_image`.
  </Step>
</Steps>

<Info>
  You can use this index as the data source for
  [Build your first search experience](/doc/guides/get-started/quickstart).

  Before you build the UI,
  [configure `product_type` as an attribute for faceting](/doc/guides/managing-results/refine-results/faceting/how-to/declaring-attributes-for-faceting-with-dashboard)
  in the `quickstart-products` index.
</Info>

## Index your own CSV data

To index your own records, update the connector source URL to point to a CSV file you host.
After you update the source, [run the connector task](https://dashboard.algolia.com/connectors/tasks) again to index your records.

### Source file format

The first row of your CSV file must contain the column names.
Each remaining row represents one record.

For example:

```csv CSV icon=braces theme={"system"}
id,title,description,product_type,price
product-1,Product name,"A short, searchable description",Product type,49.99
```

Each record needs a unique `objectID` attribute.
In the source configuration, use **Unique property identifier** to set this attribute.
Choose a column whose values are unique for every row (`id` in this example).

Enclose fields that contain commas, double quotation marks, or line breaks in double quotation marks.
For more information, see [Common Format and MIME Type for Comma-Separated Values (CSV) Files
](https://www.rfc-editor.org/rfc/rfc4180.html#section-2).

### Source file location

Update the connector source URL to point to your hosted file.
The source URL can use `http`, `https`, `ftp`, `ftps`, or `sftp`.

For `http` or `https` sources, choose the request method your server expects:

* **GET** if your server returns the file from a standard request.
* **POST** if your server requires a POST request.

### Source authentication

Select the authentication method for your file:

* **None** if the file is public.
* **Basic Auth** if the file requires a username and password.

### Transformations

Use transformations to add computed attributes or change values before the connector indexes your records.
To use a transformed attribute for search, faceting, or ranking,
update the relevant [index settings](/doc/api-reference/settings-api-parameters),
such as `searchableAttributes`, `attributesForFaceting`, or `customRanking`.

<Note>
  Test transformations with repeated task runs.
  Transformations that read from and write to the same attribute,
  or extract a value and then delete the source attribute,
  can produce different results when the task runs again.
</Note>

### Synchronization schedule

After you create a task,
you can [edit it in the Algolia dashboard](https://dashboard.algolia.com/connectors/tasks) to choose when the connector runs:

* **On demand**. Run the connector manually.
* **Scheduled**. Select a predefined schedule or enter a custom [cron expression](https://crontab.guru/).

### Indexing strategy

You can choose how the connector updates your index.
For information about full reindexing, full record updates, and partial record updates,
see [Data synchronization strategies](/doc/guides/sending-and-managing-data/send-and-update-your-data/in-depth/the-different-synchronization-strategies).

## Limitations

This connector is subject to the following limitations:

* [Connectors limits](/doc/guides/scaling/algolia-service-limits/#connectors-limits)
* [Transformation limits](/doc/guides/scaling/algolia-service-limits/#data-transformation-and-fetch-limits)

## See also

* [Prepare your records for indexing](/doc/guides/sending-and-managing-data/prepare-your-data)
* [Transform your data with code](/doc/guides/sending-and-managing-data/send-and-update-your-data/how-to/transform-your-data-with-code)
