Where you get your documents from can depend based on the version of Nest you are using. From the Nest 1.0 Breaking Changes page:
DocumentsWithMetaData
When you do a search with NEST 0.12 you'd get back a
QueryResponse<T>
with two ways to loop over your results..Documents
is anIEnumerable<T>
and.DocumentsWithMetaData
is andIEnumerable<IHit<T>>
depending on your needs one of them might be easier to use.Starting from NEST 1.0
.DocumentsWithMetaData
is now called simply.Hits
.
So given your code example:
NEST 0.12
result.Documents
result.DocumentsWithMetaData
NEST 1.0
result.Hits
The biggest difference with the 0.12 properties is that .Documents
are just a collection of the results from the search, mapped directly to your type OpinionDocumentIndexRecord
. While .DocumentsWithMetaData
have additional Elasticsearch properties like Highlights, Fields, Explanation, Type, available along with the Source property being your OpinionDocumentIndexRecord
. Which you need or want will most likely depend upon your specific application/business needs.
So if you are using Nest 0.12.0 and want a solution that will easily port to Nest 1.0.0, I would recommend using .DocumentsWithMetaData
and then you can just change to .Hits
when you upgrade the Nest Client.
If you truly only care about the OpinionDocumentIndexRecord
regardless of what property you access off of the results, then you can use one of the folllowing:
var myData = new List<OpinionDocumentIndexRecord>();
foreach (var hit in results.DocumentsWithMetaData)
//foreach (var hit in results.Hits) //for Nest 1.0
{
myData.Add(hit.Source);
}
return myData;
Hope this helps.