saveObject method

Future<SaveObjectResponse> saveObject({
  1. required String indexName,
  2. required Object body,
  3. RequestOptions? requestOptions,
})

Adds a record to an index or replaces it. - If the record doesn't have an object ID, a new record with an auto-generated object ID is added to your index. - If a record with the specified object ID exists, the existing record is replaced. - If a record with the specified object ID doesn't exist, a new record is added to your index. - If you add a record to an index that doesn't exist yet, a new index is created. To update some attributes of a record, use the partial operation. To add, update, or replace multiple records, use the batch operation. This operation is subject to indexing rate limits.

Required API Key ACLs:

  • addObject

Parameters:

  • indexName Name of the index on which to perform the operation.
  • body The record. A schemaless object with attributes that are useful in the context of search and discovery.
  • requestOptions additional request configuration.

Implementation

Future<SaveObjectResponse> saveObject({
  required String indexName,
  required Object body,
  RequestOptions? requestOptions,
}) async {
  assert(
    indexName.isNotEmpty,
    'Parameter `indexName` is required when calling `saveObject`.',
  );
  if (body is Map) {
    assert(
      body.isNotEmpty,
      'Parameter `body` is required when calling `saveObject`.',
    );
  }
  if (body is Map) {
    assert(
      body.isNotEmpty,
      'Parameter `body ` is required when calling `saveObject`.',
    );
  }
  final request = ApiRequest(
    method: RequestMethod.post,
    path: r'/1/indexes/{indexName}'.replaceAll(
        '{' r'indexName' '}', Uri.encodeComponent(indexName.toString())),
    body: body,
  );
  final response = await _retryStrategy.execute(
    request: request,
    options: requestOptions,
  );
  return deserialize<SaveObjectResponse, SaveObjectResponse>(
    response,
    'SaveObjectResponse',
    growable: true,
  );
}