Table of Contents

Interface IElasticRepositoryBase<TDocument>

Namespace
Excalibur.Data.ElasticSearch
Assembly
Excalibur.Data.ElasticSearch.dll

Provides base repository functionality for interacting with Elasticsearch for a specific document type.

public interface IElasticRepositoryBase<TDocument> where TDocument : class

Type Parameters

TDocument

The type of the document to manage in Elasticsearch.

Methods

AddOrUpdateAsync(string, TDocument, CancellationToken)

Adds or updates a document in the Elasticsearch index.

Task<bool> AddOrUpdateAsync(string documentId, TDocument document, CancellationToken cancellationToken)

Parameters

documentId string

The unique identifier for the document.

document TDocument

The document to be added or updated.

cancellationToken CancellationToken

The cancellation token to cancel the operation if required.

Returns

Task<bool>

A Task<TResult> indicating whether the operation succeeded.

BulkAddOrUpdateAsync(IEnumerable<TDocument>, Func<TDocument, string>, CancellationToken)

Performs a bulk operation to add or update multiple documents in the Elasticsearch index. Documents are uniquely identified by an ID provided by the idSelector function.

Task<bool> BulkAddOrUpdateAsync(IEnumerable<TDocument> documents, Func<TDocument, string> idSelector, CancellationToken cancellationToken)

Parameters

documents IEnumerable<TDocument>

The collection of documents to add or update.

idSelector Func<TDocument, string>

A function used to select the unique identifier (Elasticsearch document _id) for each document. This identifier ensures documents are correctly created or updated without duplication.

cancellationToken CancellationToken

The cancellation token to cancel the operation if required.

Returns

Task<bool>

A Task<TResult> indicating whether the bulk operation succeeded.

GetByIdAsync(string, CancellationToken)

Retrieves a document from Elasticsearch by its ID.

Task<TDocument?> GetByIdAsync(string documentId, CancellationToken cancellationToken)

Parameters

documentId string

The unique identifier of the document.

cancellationToken CancellationToken

The cancellation token to cancel the operation if required.

Returns

Task<TDocument>

A Task<TResult> containing the document if found, or null if not found.

RemoveAsync(string, CancellationToken)

Removes a document from the Elasticsearch index.

Task<bool> RemoveAsync(string documentId, CancellationToken cancellationToken)

Parameters

documentId string

The unique identifier of the document to remove.

cancellationToken CancellationToken

The cancellation token to cancel the operation if required.

Returns

Task<bool>

A Task<TResult> indicating whether the operation succeeded.

UpdateAsync(string, Dictionary<string, object>, CancellationToken)

Updates specific fields of a document in the Elasticsearch index.

Task<bool> UpdateAsync(string documentId, Dictionary<string, object> updatedFields, CancellationToken cancellationToken)

Parameters

documentId string

The unique identifier of the document to update.

updatedFields Dictionary<string, object>

A dictionary containing the fields to update and their new values.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the operation to complete.

Returns

Task<bool>

A Task<TResult> that resolves to true if the update operation succeeded, otherwise an exception is thrown.

Exceptions

ArgumentException

Thrown if documentId is null , empty, or whitespace.

ArgumentNullException

Thrown if updatedFields is null .

ElasticsearchUpdateException

Thrown if the update operation fails. Includes details of the Elasticsearch API response.