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

# Save records

> Adds multiple records to an index.

Based on the [Batch operations on one index](/doc/rest-api/search/batch) API operation.

This helper method creates a batch write request with the `addObject` action and automatically sends records in batches of 1,000.

This method is subject to [indexing rate limits](https://support.algolia.com/hc/en-us/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).

## Usage

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.SaveObjectsAsync(
    "INDEX_NAME",
    new List<Object>
    {
      new Dictionary<string, string>
      {
        { "objectID", "1" },
        { "visibility", "public" },
        { "name", "Hot 100 Billboard Charts" },
        { "playlistId", "d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f" },
        { "createdAt", "1500240452" },
      },
    },
    false,
    1000,
    new RequestOptionBuilder().AddExtraHeader("X-Algolia-User-ID", "*").Build()
  );
  ```

  ```go Go theme={"system"}
  response, err := client.SaveObjects(
    "INDEX_NAME",
    []map[string]any{
      {
        "objectID":   "1",
        "visibility": "public",
        "name":       "Hot 100 Billboard Charts",
        "playlistId": "d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f",
        "createdAt":  "1500240452",
      },
    },
    search.WithWaitForTasks(false),
    search.WithBatchSize(1000),
    search.WithHeaderParam("X-Algolia-User-ID", "*"),
  )
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  List response = client.saveObjects(
    "INDEX_NAME",
    Arrays.asList(
      new HashMap() {
        {
          put("objectID", "1");
          put("visibility", "public");
          put("name", "Hot 100 Billboard Charts");
          put("playlistId", "d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f");
          put("createdAt", "1500240452");
        }
      }
    ),
    false,
    1000,
    new RequestOptions().addExtraHeader("X-Algolia-User-ID", "*")
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.saveObjects(
    {
      indexName: 'playlists',
      objects: [
        {
          objectID: '1',
          visibility: 'public',
          name: 'Hot 100 Billboard Charts',
          playlistId: 'd3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f',
          createdAt: '1500240452',
        },
      ],
      waitForTasks: false,
      batchSize: 1000,
    },
    {
      headers: { 'X-Algolia-User-ID': '*' },
    },
  );
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.saveObjects(
      indexName = "INDEX_NAME",
      objects =
        listOf(
          buildJsonObject {
            put("objectID", JsonPrimitive("1"))
            put("visibility", JsonPrimitive("public"))
            put("name", JsonPrimitive("Hot 100 Billboard Charts"))
            put("playlistId", JsonPrimitive("d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f"))
            put("createdAt", JsonPrimitive("1500240452"))
          }
        ),
      waitForTasks = false,
      batchSize = 1000,
      requestOptions = RequestOptions(headers = buildMap { put("X-Algolia-User-ID", "*") }),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->saveObjects(
      'INDEX_NAME',
      [
          ['objectID' => '1',
              'visibility' => 'public',
              'name' => 'Hot 100 Billboard Charts',
              'playlistId' => 'd3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f',
              'createdAt' => '1500240452',
          ],
      ],
      false,
      1000,
      [
          'headers' => [
              'X-Algolia-User-ID' => '*',
          ],
      ]
  );
  ```

  ```python Python theme={"system"}
  response = client.save_objects(
      index_name="INDEX_NAME",
      objects=[
          {
              "objectID": "1",
              "visibility": "public",
              "name": "Hot 100 Billboard Charts",
              "playlistId": "d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f",
              "createdAt": "1500240452",
          },
      ],
      wait_for_tasks=False,
      batch_size=1000,
      request_options={
          "headers": loads("""{"X-Algolia-User-ID":"*"}"""),
      },
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.save_objects(
    "INDEX_NAME",
    [
      {
        objectID: "1",
        visibility: "public",
        name: "Hot 100 Billboard Charts",
        playlistId: "d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f",
        createdAt: "1500240452"
      }
    ],
    false,
    1000,
    {:header_params => {"X-Algolia-User-ID" => "*"}}
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.saveObjects(
      indexName = "INDEX_NAME",
      objects = Seq(
        JObject(
          List(
            JField("objectID", JString("1")),
            JField("visibility", JString("public")),
            JField("name", JString("Hot 100 Billboard Charts")),
            JField("playlistId", JString("d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f")),
            JField("createdAt", JString("1500240452"))
          )
        )
      ),
      waitForTasks = false,
      batchSize = 1000,
      requestOptions = Some(
        RequestOptions
          .builder()
          .withHeader("X-Algolia-User-ID", "*")
          .build()
      )
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response = try await client.saveObjects(
      indexName: "INDEX_NAME",
      objects: [[
          "objectID": "1",
          "visibility": "public",
          "name": "Hot 100 Billboard Charts",
          "playlistId": "d3e8e8f3-0a4f-4b7d-9b6b-7e8f4e8e3a0f",
          "createdAt": "1500240452",
      ]],
      waitForTasks: false,
      batchSize: 1000,
      requestOptions: RequestOptions(
          headers: ["X-Algolia-User-ID": "*"]
      )
  )
  ```
</CodeGroup>

## Parameters

<Tabs>
  <Tab title="C#">
    <ParamField body="indexName" type="string" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="IEnumerable<T>" required>
      Records to add.
    </ParamField>

    <ParamField body="T" type="type parameter" required>
      The model of your index's records.
    </ParamField>

    <ParamField body="waitForTasks" type="bool" default={false}>
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batchSize" type="int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Go">
    <ParamField body="indexName" type="string" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="[]map[string]any" required>
      Records to add.
    </ParamField>

    <ParamField body="opts..." type="ChunkedBatchOption">
      Functional options to provide extra arguments.

      <Expandable title="available functions">
        <ParamField body="search.WithWaitForTasks" type="function">
          **Signature:** `func(waitForTasks bool) chunkedBatchOption`

          Whether to wait until all batch requests are done.
        </ParamField>

        <ParamField body="search.WithBatchSize" type="function">
          **Signature:** `func(batchSize int) chunkedBatchOption`

          Number of records to process in one batch.
        </ParamField>

        <ParamField body="search.WithHeaderParam" type="function">
          **Signature:** `func(key string, value string) requestOption`

          Sets extra header parameters for this request.
        </ParamField>

        <ParamField body="search.WithQueryParam" type="function">
          **Signature:** `func(key string, value string) requestOption`

          Sets extra query parameters for this request.
        </ParamField>
      </Expandable>
    </ParamField>
  </Tab>

  <Tab title="Java">
    <ParamField body="indexName" type="String" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="Iterable<T>" required>
      Records to add.
    </ParamField>

    <ParamField body="T" type="Type parameter" required>
      The model of your index's records.
    </ParamField>

    <ParamField body="waitForTasks" type="boolean" default={false}>
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batchSize" type="int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="JavaScript">
    <ParamField body="indexName" type="string" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="Record<string,unknown>[]" required>
      Records to add.
    </ParamField>

    <ParamField body="waitForTasks" type="boolean" default={false}>
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batchSize" type="number" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Kotlin">
    <ParamField body="indexName" type="String" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="List<JsonObject>" required>
      Records to add.
    </ParamField>

    <ParamField body="waitForTasks" type="Boolean" default={false}>
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batchSize" type="Int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="PHP">
    <ParamField body="indexName" type="string" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="array" required>
      Records to add.
    </ParamField>

    <ParamField body="waitForTasks" type="bool" default={false}>
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batchSize" type="int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="requestOptions" type="array">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Python">
    <ParamField body="index_name" type="str" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="list[dict]" required>
      Records to add.
    </ParamField>

    <ParamField body="wait_for_tasks" type="bool" default="False">
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batch_size" type="int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="request_options" type="dict | RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Ruby">
    <ParamField body="index_name" type="String" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="Array[Hash]" required>
      Records to add.
    </ParamField>

    <ParamField body="waitForTasks" type="Boolean" default={false}>
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batchSize" type="Integer" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="requestOptions" type="Hash">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Scala">
    <ParamField body="indexName" type="String" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="Seq[Any]" required>
      Records to add.
    </ParamField>

    <ParamField body="waitForTasks" type="Boolean" default={false}>
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batchSize" type="Int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="requestOptions" type="Option[RequestOptions]">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Swift">
    <ParamField body="indexName" type="String" required>
      Name of the index to which to add records.
    </ParamField>

    <ParamField body="objects" type="[Encodable]" required>
      Records to add.
    </ParamField>

    <ParamField body="waitForTasks" type="Bool" default={false}>
      Whether to wait until all batch requests are done.
    </ParamField>

    <ParamField body="batchSize" type="Int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>
</Tabs>
