我正在嘗試在 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()));
}
uj5u.com熱心網友回復:
的簽名
public async Task<T> AddData<T>(T requestObject, string index) where T : class
需要回傳 requestObject 型別,但回傳 NESTIndexResponse型別的任務。
我會質疑IElasticSearchClient以IStorageClient. 它看起來像的具體實作IStorageClient直接使用NEST客戶端就足夠了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/398108.html
