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
TDocumentThe 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
documentIdstringThe unique identifier for the document.
documentTDocumentThe document to be added or updated.
cancellationTokenCancellationTokenThe 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
documentsIEnumerable<TDocument>The collection of documents to add or update.
idSelectorFunc<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.
cancellationTokenCancellationTokenThe 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
documentIdstringThe unique identifier of the document.
cancellationTokenCancellationTokenThe cancellation token to cancel the operation if required.
Returns
- Task<TDocument>
A Task<TResult> containing the document if found, or
nullif not found.
RemoveAsync(string, CancellationToken)
Removes a document from the Elasticsearch index.
Task<bool> RemoveAsync(string documentId, CancellationToken cancellationToken)
Parameters
documentIdstringThe unique identifier of the document to remove.
cancellationTokenCancellationTokenThe 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
documentIdstringThe unique identifier of the document to update.
updatedFieldsDictionary<string, object>A dictionary containing the fields to update and their new values.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the operation to complete.
Returns
- Task<bool>
A Task<TResult> that resolves to
trueif the update operation succeeded, otherwise an exception is thrown.
Exceptions
- ArgumentException
Thrown if
documentIdisnull, empty, or whitespace.- ArgumentNullException
Thrown if
updatedFieldsisnull.- ElasticsearchUpdateException
Thrown if the update operation fails. Includes details of the Elasticsearch API response.