Reputation: 2588
I'm retrieving a document from Elasticsearch using the client.Get<MyDocument>(getRequest)
syntax however the IGetResponse
I retrieve is basically useless. It contains no fields of the document I want and basically only tells me that the .Get
was successful (and includes the Id of the document I'm trying to get)
Here is my code:
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);
My question is do I need to cast the IGetResponse<MyDocument>
to a MyDocument
somehow? Is there some step I'm missing here?
EDIT: P.S.: result.Found
is true
so it definitely succeeds in getting the document
Upvotes: 1
Views: 183
Reputation: 1820
From the documentation:
The Get() call returns an IGetResponse that holds the requested document as well as other meta data returned from Elasticsearch.
response.Source holds the document.
Upvotes: 1
Reputation: 2588
Figured it out: the property on the IGetResponse<MyDocument>
I want is Source
. Its the actual document object.
e.g.:
IGetResponse<MyDocument> result = Client.Get<MyDocument>(request);
if (result.Found)
{
MyDocument myDocument = result.Source;
}
Upvotes: 1