簡體   English   中英

Elasticsearch.Net和NEST,IGetResponse記錄POCO嗎?

[英]Elasticsearch.Net and NEST, IGetResponse to document POCO?

我正在使用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);

我的問題是我是否需要將IGetResponse<MyDocument>轉換為MyDocument 我在這里缺少一些步驟嗎?

編輯: PS: result.Foundtrue所以它絕對成功獲取文檔

弄清楚了:我想要的IGetResponse<MyDocument>上的屬性是Source 它是實際的文檔對象。

例如:

IGetResponse<MyDocument> result = Client.Get<MyDocument>(request);
if (result.Found)
{
    MyDocument myDocument = result.Source;
}

從文檔中:

Get()調用返回一個IGetResponse,其中包含請求的文檔以及從Elasticsearch返回的其他元數據。

response.Source保存文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM