From bfe399d1a24e2975fb3f3c6fe4c18c566e53063a Mon Sep 17 00:00:00 2001 From: Salih Date: Mon, 6 May 2024 12:03:11 +0300 Subject: [PATCH] Update ElasticDocumentFullSearch.cs --- .../Elastic/ElasticDocumentFullSearch.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 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 1bf5cb873f..c9a926d10d 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 @@ -59,10 +59,26 @@ namespace Volo.Docs.Documents.FullSearch.Elastic { var client = _clientProvider.GetClient(); - var existsResponse = await client.DocumentExistsAsync(DocumentPath.Id(NormalizeField(document.Id)), x => x.Index(_options.IndexName), cancellationToken); - if (existsResponse.Exists) + // exist by name, project id, language code and version + var existResponse = await client.SearchAsync(s => s + .Query(q => q + .Bool(b => b + .Must(m => m + .Term(t => t.ProjectId, NormalizeField(document.ProjectId)) + && m.Term(t => t.LanguageCode, NormalizeField(document.LanguageCode)) + && m.Term(t => t.Version, NormalizeField(document.Version)) + && m.Term(t => t.Name, document.Name) + ) + ) + ), cancellationToken); + + HandleError(existResponse); + + if (existResponse.Documents.Count != 0) { - await DeleteAsync(document.Id, cancellationToken); + // delete many + var ids = existResponse.Documents.Select(x => x.Id).ToList(); + HandleError(await client.DeleteManyAsync(ids, _options.IndexName, cancellationToken)); } var esDocument = new EsDocument