Browse Source

fix bulk removing items from elasticsearch index (#1374)

pull/1376/head
Jason Dove 2 years ago committed by GitHub
parent
commit
d951035183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      ErsatzTV.Infrastructure/Search/ElasticSearchIndex.cs

13
ErsatzTV.Infrastructure/Search/ElasticSearchIndex.cs

@ -41,7 +41,7 @@ public class ElasticSearchIndex : ISearchIndex @@ -41,7 +41,7 @@ public class ElasticSearchIndex : ISearchIndex
public async Task<bool> 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 @@ -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 @@ -159,7 +160,7 @@ public class ElasticSearchIndex : ISearchIndex
var totalCount = 0;
Query parsedQuery = LuceneSearchIndex.ParseQuery(query);
SearchResponse<MinimalElasticSearchItem> response = await _client.SearchAsync<MinimalElasticSearchItem>(
s => s.Index(IndexName)
.Sort(ss => ss.Field(f => f.SortTitle, fs => fs.Order(SortOrder.Asc)))
@ -188,6 +189,12 @@ public class ElasticSearchIndex : ISearchIndex @@ -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<CreateIndexResponse> CreateIndex() =>
await _client.Indices.CreateAsync<ElasticSearchItem>(
IndexName,

Loading…
Cancel
Save