forked from oskardudycz/EventSourcing.NetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched Elastic client from NEST to Elastic.Clients.Elasticsearch
Bumped also other dependencies (OpenTelemetry, Marten, etc.)
- Loading branch information
1 parent
1abd4e2
commit 2ee4a70
Showing
101 changed files
with
185 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
using System.Collections.Concurrent; | ||
using Nest; | ||
using Elastic.Clients.Elasticsearch; | ||
|
||
namespace Core.ElasticSearch.Repository; | ||
|
||
public static class ElasticSearchRepository | ||
{ | ||
public static async Task<T?> Find<T>(this ElasticsearchClient elasticClient, string id, CancellationToken ct) | ||
where T : class => | ||
(await elasticClient.GetAsync<T>(id, cancellationToken: ct).ConfigureAwait(false))?.Source; | ||
|
||
public static class ElasticSearchRepository | ||
{ | ||
public static async Task<T?> Find<T>(this IElasticClient elasticClient, string id, CancellationToken ct) | ||
where T: class => | ||
(await elasticClient.GetAsync<T>(id, ct: ct).ConfigureAwait(false))?.Source; | ||
|
||
public static async Task Upsert<T>(this IElasticClient elasticClient, string id, T entity, CancellationToken ct) | ||
where T: class => | ||
await elasticClient.UpdateAsync<T>(id, | ||
u => u.Doc(entity).Upsert(entity).Index(ToIndexName<T>()), | ||
ct | ||
).ConfigureAwait(false); | ||
public static async Task Upsert<T>(this ElasticsearchClient elasticClient, string id, T entity, | ||
CancellationToken ct) | ||
where T : class => | ||
await elasticClient.UpdateAsync<T, object>(ToIndexName<T>(), id, | ||
u => u.Doc(entity).Upsert(entity), | ||
ct | ||
).ConfigureAwait(false); | ||
|
||
private static readonly ConcurrentDictionary<Type, string> TypeNameMap = new(); | ||
private static readonly ConcurrentDictionary<Type, string> TypeNameMap = new(); | ||
|
||
private static string ToIndexName<TIndex>() | ||
private static string ToIndexName<TIndex>() | ||
{ | ||
var indexType = typeof(TIndex); | ||
return TypeNameMap.GetOrAdd(indexType, _ => | ||
{ | ||
var indexType = typeof(TIndex); | ||
return TypeNameMap.GetOrAdd(indexType, _ => | ||
{ | ||
var modulePrefix = indexType.Namespace!.Split(".").First(); | ||
return $"{modulePrefix}-{indexType.Name}".ToLower(); | ||
}); | ||
} | ||
var modulePrefix = indexType.Namespace!.Split(".").First(); | ||
return $"{modulePrefix}-{indexType.Name}".ToLower(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.