Skip to content

Commit

Permalink
Merge pull request #19 from Klantinteractie-Servicesysteem/752-index-…
Browse files Browse the repository at this point in the history
…opschonen

fix: check for errors on ElasticsearchClient
  • Loading branch information
felixcicatt authored Jul 25, 2024
2 parents 571bdbe + 883145c commit fa22617
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Kiss.Elastic.Sync/ElasticBulkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ public ElasticBulkClient(Uri baseUri, string username, string password, int scro
{
var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
};
// skip checking the certificate because we run Elastic internally, with a local certificate
handler.ServerCertificateCustomValidationCallback = (a, b, c, d) => true;
_httpClient = new HttpClient(handler);
_httpClient.BaseAddress = baseUri;
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Helpers.EncodeCredential(username, password));
var clientSettings = new ElasticsearchClientSettings(baseUri)
.Authentication(new BasicAuthentication(username, password));
.Authentication(new BasicAuthentication(username, password))
// skip checking the certificate because we run Elastic internally, with a local certificate
.ServerCertificateValidationCallback((a, b, c, d) => true);

_elasticsearchClient = new ElasticsearchClient(clientSettings);
_scrollPageSize = scrollPageSize;
}
Expand Down Expand Up @@ -185,6 +185,11 @@ private async Task<HashSet<string>> GetExistingIds(string indexName, Cancellatio
.Scroll(scrollDuration),
token);

if (!searchResponse.IsSuccess())
{
throw new Exception("search failed: " + searchResponse.ToString());
}

var scrollId = searchResponse.ScrollId;
var hits = searchResponse.Hits;

Expand All @@ -200,7 +205,12 @@ private async Task<HashSet<string>> GetExistingIds(string indexName, Cancellatio
ScrollId = scrollId,
Scroll = scrollDuration,
}, token);


if (!scrollResponse.IsSuccess())
{
throw new Exception("scroll failed: " + scrollResponse.ToString());
}

scrollId = scrollResponse.ScrollId;
hits = scrollResponse.Hits;
}
Expand Down

0 comments on commit fa22617

Please sign in to comment.