Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLR error message from ElasticSearch #46

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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