From 9ac0cb04d89b8fec2f0ff0ad4c2098ba5f6fc59c Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 3 Mar 2021 10:33:35 +0800 Subject: [PATCH] Use Index API to add or update documents --- .../Elastic/ElasticDocumentFullSearch.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs index 8e0a51324a..7160ca405b 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs @@ -60,11 +60,6 @@ namespace Volo.Docs.Documents.FullSearch.Elastic var client = _clientProvider.GetClient(); - var existsResponse = await client.DocumentExistsAsync(DocumentPath.Id(document.Id), - x => x.Index(_options.IndexName), cancellationToken); - - HandleError(existsResponse); - var esDocument = new EsDocument { Id = NormalizeField(document.Id), @@ -76,17 +71,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic 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.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) @@ -94,7 +79,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic ValidateElasticSearchEnabled(); HandleError(await _clientProvider.GetClient() - .DeleteAsync(DocumentPath.Id(id), x => x.Index(_options.IndexName), cancellationToken)); + .DeleteAsync(DocumentPath.Id( NormalizeField(id)), x => x.Index(_options.IndexName), cancellationToken)); } public virtual async Task DeleteAllAsync(CancellationToken cancellationToken = default)