Browse Source

Merge pull request #7919 from abpframework/liangshiwei/docs

Use Index API to add or update documents
pull/7921/head
maliming 5 years ago
committed by GitHub
parent
commit
56ebdd12da
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs

19
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<EsDocument>.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<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)
@ -94,7 +79,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic
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)

Loading…
Cancel
Save