/// <summary> /// 根据id查询单条数据(知道具体索引) /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TPrimaryKeyType"></typeparam> /// <param name="id"></param> /// <param name="indexName"></param> /// <param name="routing"></param> /// <returns></returns> public async Task <T> GetAsync <T, TPrimaryKeyType>(QueryModel <TPrimaryKeyType> queryModel) where T : class { string indexName = queryModel.IndexName?.ToLower(); if (!string.IsNullOrEmpty(indexName)) { GetDescriptor <T> descriptor = new GetDescriptor <T>(indexName, queryModel.Id.ToString());; if (!string.IsNullOrEmpty(queryModel.Routing)) { descriptor.Routing(queryModel.Routing); } var response = await client.GetAsync <T>(descriptor).ConfigureAwait(false); if (response.Found) { return(response.Source); } return(default(T)); } else { //不知道indexName 另外一种方式查询 return(await GetAsync <T, TPrimaryKeyType>(queryModel.Id, queryModel.Routing)); } }