我正在使用client.Get<MyDocument>(getRequest)語法從 Elasticsearch 檢索文檔,但是我檢索的文檔IGetResponse基本上沒用。它不包含我想要的文檔字段,基本上只告訴我.Get成功(并包括我試圖獲取的文檔的 ID)這是我的代碼:TypeName typeName = TypeName.From<MyDocument>();GetRequest request = new GetRequest(Index, typeName, new Id("R" + id));// I can't get any of the fields I want from this object:IGetResponse<MyDocument> result = Client.Get<MyDocument>(request);我的問題是我需要以某種方式將 the 轉換IGetResponse<MyDocument>為 aMyDocument嗎?我在這里遺漏了一些步驟嗎?編輯: PS:result.Found是true所以它肯定在獲得成功文件
2 回答

MYYA
TA貢獻1868條經驗 獲得超4個贊
從文檔:
Get() 調用返回一個 IGetResponse,其中包含請求的文檔以及從 Elasticsearch 返回的其他元數據。
response.Source 保存文檔。

繁星點點滴滴
TA貢獻1803條經驗 獲得超3個贊
想通了:IGetResponse<MyDocument>我想要的屬性是Source. 它是實際的文檔對象。
例如:
IGetResponse<MyDocument> result = Client.Get<MyDocument>(request);
if (result.Found)
{
MyDocument myDocument = result.Source;
}
- 2 回答
- 0 關注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消