diff --git a/ErsatzTV.Infrastructure/Search/ElasticSearchIndex.cs b/ErsatzTV.Infrastructure/Search/ElasticSearchIndex.cs index 227b03fd..15ff24a8 100644 --- a/ErsatzTV.Infrastructure/Search/ElasticSearchIndex.cs +++ b/ErsatzTV.Infrastructure/Search/ElasticSearchIndex.cs @@ -41,7 +41,7 @@ public class ElasticSearchIndex : ISearchIndex public async Task IndexExists() { - _client ??= new ElasticsearchClient(Uri); + _client ??= CreateClient(); ExistsResponse exists = await _client.Indices.ExistsAsync(IndexName); return exists.IsValidResponse; } @@ -52,7 +52,8 @@ public class ElasticSearchIndex : ISearchIndex ILocalFileSystem localFileSystem, IConfigElementRepository configElementRepository) { - _client ??= new ElasticsearchClient(Uri); + _client ??= CreateClient(); + ExistsResponse exists = await _client.Indices.ExistsAsync(IndexName); if (!exists.IsValidResponse) { @@ -159,7 +160,7 @@ public class ElasticSearchIndex : ISearchIndex var totalCount = 0; Query parsedQuery = LuceneSearchIndex.ParseQuery(query); - + SearchResponse response = await _client.SearchAsync( s => s.Index(IndexName) .Sort(ss => ss.Field(f => f.SortTitle, fs => fs.Order(SortOrder.Asc))) @@ -188,6 +189,12 @@ public class ElasticSearchIndex : ISearchIndex // do nothing } + private static ElasticsearchClient CreateClient() + { + ElasticsearchClientSettings settings = new ElasticsearchClientSettings(Uri).DefaultIndex(IndexName); + return new ElasticsearchClient(settings); + } + private async Task CreateIndex() => await _client.Indices.CreateAsync( IndexName,