Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Index API to add or update documents #7919

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public virtual async Task AddOrUpdateAsync(Document document, CancellationToken

var client = _clientProvider.GetClient();

var existsResponse = await client.DocumentExistsAsync(DocumentPath<EsDocument>.Id(document.Id),
x => x.Index(_options.IndexName), cancellationToken);

HandleError(existsResponse);

var esDocument = new EsDocument
{
Id = NormalizeField(document.Id),
Expand All @@ -76,25 +71,15 @@ public virtual async Task AddOrUpdateAsync(Document document, CancellationToken
Version = NormalizeField(document.Version)
};

if (!existsResponse.Exists)
{
HandleError(await client.IndexAsync(esDocument,
x => x.Id(document.Id).Index(_options.IndexName), cancellationToken));
}
else
{
HandleError(await client.UpdateAsync(DocumentPath<EsDocument>.Id(document.Id),
x => x.Doc(esDocument).Index(_options.IndexName), cancellationToken));
}

await client.IndexAsync(esDocument , x=>x.Index(_options.IndexName), cancellationToken);
}

public virtual async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default)
{
ValidateElasticSearchEnabled();

HandleError(await _clientProvider.GetClient()
.DeleteAsync(DocumentPath<Document>.Id(id), x => x.Index(_options.IndexName), cancellationToken));
.DeleteAsync(DocumentPath<Document>.Id( NormalizeField(id)), x => x.Index(_options.IndexName), cancellationToken));
}

public virtual async Task DeleteAllAsync(CancellationToken cancellationToken = default)
Expand Down