Skip to content

Commit

Permalink
Add CLR error message from ElasticSearch (#46)
Browse files Browse the repository at this point in the history
* Add CLR error message from ElasticSearch
* Fix commented smells
  • Loading branch information
dvs39 authored Nov 21, 2022
1 parent c4d5ae4 commit cff9b8d
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ElasticSearchProvider : ISearchProvider, ISupportIndexSwap, ISuppor
public const string NGramFilterName = "custom_ngram";
public const string EdgeNGramFilterName = "custom_edge_ngram";

private const string _exceptionTitle = "Elasticsearch Server";

private readonly ConcurrentDictionary<string, Properties<IProperties>> _mappings = new ConcurrentDictionary<string, Properties<IProperties>>();
private readonly SearchOptions _searchOptions;

Expand Down Expand Up @@ -278,15 +280,25 @@ protected virtual async Task<IndexingResult> InternalIndexAsync(string documentT
var bulkResponse = await Client.BulkAsync(bulkDefinition);
await Client.Indices.RefreshAsync(indexName);

var result = new IndexingResult
var result = new IndexingResult();
result.Items = new List<IndexingResultItem>();

if (!bulkResponse.IsValid)
{
Items = bulkResponse.Items.Select(i => new IndexingResultItem
result.Items.Add(new IndexingResultItem
{
Id = i.Id,
Succeeded = i.IsValid,
ErrorMessage = i.Error?.Reason
}).ToArray()
};
Id = _exceptionTitle,
ErrorMessage = bulkResponse.OriginalException?.Message,
Succeeded = false
});
}

result.Items.AddRange(bulkResponse.Items.Select(i => new IndexingResultItem
{
Id = i.Id,
Succeeded = i.IsValid,
ErrorMessage = i.Error?.Reason
}));

return result;
}
Expand Down

0 comments on commit cff9b8d

Please sign in to comment.