【发布时间】:2022-01-23 03:45:20
【问题描述】:
我正在尝试在 NEST Elastic 搜索客户端上创建一个抽象层,因为我不希望业务逻辑依赖于客户端,因此我可以在必要时更改客户端。但是响应类型应该是什么?我无法使用通用类型,因为它给了我一个错误:
public class StorageClient : IStorageClient
{
private readonly IElasticSearchClient _elasticSearchClient;
public StorageClient(IElasticSearchClient elasticSearchClient)
{
_elasticSearchClient = elasticSearchClient;
}
public async Task<T> AddData<T>(T requestObject, string index) where T : class
{
var response = await _elasticSearchClient.addIndex(requestObject, index);
return response; I get an error here that cannot convert the NEST index response to type T
}
}
这里是弹性搜索客户端
public async Task<IndexResponse> addIndex<T>(T document, string index) where T : class
{
_client = CreateElasticClient();
return await _client.IndexAsync(elasticValues, idx => idx.Index(index.ToLower()));
}
【问题讨论】:
标签: c# .net elasticsearch