fix bulk removing items from elasticsearch index (#1374)

This commit is contained in:
Jason Dove
2023-08-12 08:51:12 -05:00
committed by GitHub
parent 097c60169c
commit d951035183
@@ -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
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<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
// 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,