|
4 | 4 | using System.Threading; |
5 | 5 | using System.Threading.Tasks; |
6 | 6 | using Bing.Elasticsearch.Internals; |
| 7 | +using Bing.Elasticsearch.Mapping; |
7 | 8 | using Bing.Elasticsearch.Options; |
8 | 9 | using Bing.Elasticsearch.Provider; |
9 | 10 | using Bing.Elasticsearch.Repositories; |
@@ -39,16 +40,23 @@ public class ElasticsearchContext : IElasticsearchContext |
39 | 40 | /// </summary> |
40 | 41 | private readonly ElasticsearchOptions _options; |
41 | 42 |
|
| 43 | + /// <summary> |
| 44 | + /// ES映射工厂 |
| 45 | + /// </summary> |
| 46 | + private readonly IElasticMappingFactory _mappingFactory; |
| 47 | + |
42 | 48 | /// <summary> |
43 | 49 | /// 初始化一个<see cref="ElasticsearchContext"/>类型的实例 |
44 | 50 | /// </summary> |
45 | 51 | /// <param name="provider">ES客户端提供程序</param> |
46 | 52 | /// <param name="resolver">索引名称解析器</param> |
| 53 | + /// <param name="mappingFactory">ES映射工厂</param> |
47 | 54 | /// <param name="options">ES选项配置</param> |
48 | | - public ElasticsearchContext(IElasticClientProvider provider, IIndexNameResolver resolver, IOptions<ElasticsearchOptions> options) |
| 55 | + public ElasticsearchContext(IElasticClientProvider provider, IIndexNameResolver resolver, IElasticMappingFactory mappingFactory, IOptions<ElasticsearchOptions> options) |
49 | 56 | { |
50 | 57 | _provider = provider; |
51 | 58 | _resolver = resolver; |
| 59 | + _mappingFactory = mappingFactory; |
52 | 60 | _client = provider.GetClient(); |
53 | 61 | _options = options.Value; |
54 | 62 | } |
@@ -117,7 +125,8 @@ public async Task<CreateIndexResponse> CreateIndexAsync(string index, string ali |
117 | 125 | /// <param name="cancellationToken">取消令牌</param> |
118 | 126 | public async Task CreateIndexAsync<TDocument>(string index, string alias = null, CancellationToken cancellationToken = default) where TDocument : class |
119 | 127 | { |
120 | | - await _client.CreateIndexAsync<TDocument>(index, _options.NumberOfShards, _options.NumberOfReplicas, cancellationToken); |
| 128 | + //await _client.CreateIndexAsync<TDocument>(index, _options.NumberOfShards, _options.NumberOfReplicas, cancellationToken); |
| 129 | + await _client.CreateIndexAsync<TDocument>(_mappingFactory, index, cancellationToken); |
121 | 130 | if (alias.IsEmpty() == false) |
122 | 131 | await _client.Indices.PutAliasAsync(index, alias, ct: cancellationToken); |
123 | 132 | } |
|
0 commit comments