HomeDev guideRecipesAPI Reference
Dev guideUser GuidesLegal TermsNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Retrieve documents

How to retrieve documents from the Optimizely Graph using the GraphQueryBuilder instance.

👍

Beta

The Optimizely Graph .NET Client is in beta. Contact your Customer Success Manager for information.

You can retrieve indexed documents using the GetResultAsync() or theGetResultAsync<TResult> methods in the GraphQueryBuilder class:

var queryBuilder = //A instance retrieved from config or injected

var query = queryBuilder
.ForType<MyDocument>()  
  .Fields(x=>x.Property1)  
  .Facet(x=>x.Property2)  
  .Total()  
.ToQuery()  
.BuildQueries();

var response = await query.GetResultAsync();
var content = response.GetContent<MyDocument>(); //get content of type MyDocument

var hits = content.Hits;  
var facets = content.Facets;  
var total  = content.Total;

Use:

  • GetResultAsync<TResult> – If you want to convert the response into your result object directly. You do not need to call GetContent.
  • GetResultAsync() – If you want to convert the result lazily by calling GetContent<TResult> or GetContent<TOriginalType,TDestinationType>.
  • GetRawResultAsync – If you want the raw JSON data.