> ## 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.

# Elasticsearch connector

> Use the Elasticsearch connector to sync data from an Elasticsearch index to an Algolia index.

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 Elasticsearch connector to index <Records /> from Elasticsearch 7 or later without writing an indexing script.
In this quickstart, you connect an existing Elasticsearch index,
use an Algolia <Index /> destination,
transform the records,
and create an on-demand synchronization task.

## Before you begin

Make sure you have:

* **An Algolia account**.
  [Create one for free](https://www.algolia.com/users/sign_up) if you don't already have one.
* **An Elasticsearch 7 or later deployment containing the sample data in an index named `apparel`**.
  Download the [Algolia apparel sample data](https://raw.githubusercontent.com/algolia/quickstarts/main/sample-data/apparel.ndjson) and add it to the index:
  * For Kibana, follow Elastic's [file upload instructions](https://www.elastic.co/docs/manage-data/ingest/upload-data-files).
  * For other ingestion methods, see [Ingest: Bring your data to Elastic](https://www.elastic.co/docs/manage-data/ingest).

## Set up the Elasticsearch connector

Create a source, destination, transformation, and synchronization task for the sample Elasticsearch index.
The source identifies the Elasticsearch deployment.
The destination identifies the Algolia index.
The transformation enriches the records.
The task identifies the source Elasticsearch index and determines when the connector runs.

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

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

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

    Enter the following details:

    | Field                     | Value                                                                   |
    | ------------------------- | ----------------------------------------------------------------------- |
    | **Server Endpoint**       | The Elasticsearch endpoint URL                                          |
    | **Authentication method** | **Api Key/Secret**                                                      |
    | **API Key ID**            | The ID for an Elasticsearch API key that can access the `apparel` index |
    | **API Key Secret**        | The secret for that API key                                             |

    In **Connector name**,
    enter `Quickstart products Elasticsearch 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 Algolia 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" id="destination">
    Under **Index credentials**, select **Create one for me**.

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

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

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

    Select **Full reindexing**.

    Under **Which table do you want to sync?**,
    select `apparel` as the source Elasticsearch index and
    select the `objectID` field as the **ObjectID** unique identifier.

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

  <Step title="Verify the indexed records">
    Open the
    [`quickstart-products` index in the Algolia dashboard](https://dashboard.algolia.com/explorer/browse/quickstart-products).

    The index contains the imported 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 Elasticsearch data

To index your own data,
configure the connector with your Elasticsearch server,
choose an authentication method and destination,
and create a synchronization task for the Elasticsearch indices you want to import.

### Configure the connector for your data

Use a populated Elasticsearch index that the Algolia connector can reach.
If you restrict inbound access to your Elasticsearch server,
allow the [Algolia connector IP addresses](/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors#allow-algolia-ip-addresses).

Follow the quickstart steps to create the [source](#source), [destination](#destination), and [task](#task).
Replace the sample endpoint, credentials, source index, and destination index with your own values.

Review or remove the sample transformation so that it matches your record structure.

When you configure the task, select the field to use as the **ObjectID**.
The field must be present in every source document, and its value must be unique and stable.

### Elasticsearch authentication

To create an API key and secret,
use [Kibana](https://www.elastic.co/docs/deploy-manage/api-keys/elasticsearch-api-keys) or
the [Elasticsearch API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-create-api-key).

Elasticsearch API keys include an ID and secret.
The Algolia connector requires these values separately.
If Elasticsearch gives you only an encoded credential,
decode it locally to recover the ID and secret.
For more information,
see [Elasticsearch API keys](https://www.elastic.co/docs/deploy-manage/api-keys/elasticsearch-api-keys).

When you [configure the Elasticsearch source](#source),
choose one of these authentication methods:

* **None**: the connector reads your data without authentication.
* **Api key/Secret**: enter the decoded API key ID and API key secret.
* **Username/Password**: enter the username and password the connector should use.

For **Api key/Secret** or **Username/Password** authentication,
grant read-only access to the Elasticsearch indices you want to import.
Use the following privileges:

* **Cluster**: `monitor`
* **Indices**: `read`, `view_index_metadata`, and `monitor`

Scope the index privileges to the relevant index names or patterns.

For **Username/Password** authentication,
choose a user whose roles grant the same access.

<Info>
  The connector reads from Elasticsearch and writes to the Algolia destination.
  It doesn't need permission to create Elasticsearch indices or documents.
</Info>

### 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).

<Warning>
  Schedule full reindexing tasks only as often as necessary.
  Each run reads all documents from the selected Elasticsearch indices
  and rewrites the destination,
  which increases the workload on Elasticsearch and the number of Algolia indexing operations.
</Warning>

## 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

* [Connector overview](/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors)
* [JSON connector](/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/json)
* [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)
