public IEnumerable<StandardSummary> GetAllStandards() { var take = _queryHelper.GetStandardsTotalAmount(); var searchDescriptor = GetAllStandardsSeachDescriptor(take); var results = _elasticsearchCustomClient.Search<StandardSearchResultsItem>(s => searchDescriptor); if (results.ApiCall.HttpStatusCode != 200) { throw new ApplicationException($"Failed query all standards"); } var resultList = results.Documents.Select(standardSearchResultsItem => _standardMapping.MapToStandardSummary(standardSearchResultsItem)).ToList(); return resultList; }
public IEnumerable <ProviderStandard> GetStandardsByProviderUkprn(long ukprn) { var totalTakeForStandardDocuments = _queryHelper.GetStandardsTotalAmount(); var aggregateKeyName = "levelId"; var matchedIds = _elasticsearchCustomClient.Search <ProviderStandardDto>( s => s.Index(_applicationSettings.ProviderIndexAlias) .From(0) .Query(q => + q.Term("documentType", "standardprovider") && +q.Term(t => t.Ukprn, ukprn)) .Aggregations(agg => agg .Terms(aggregateKeyName, frm => frm .Size(totalTakeForStandardDocuments) .Field(fi => fi.StandardCode)))); if (matchedIds.ApiCall.HttpStatusCode != 200) { _applicationLogger.LogWarning($"httpStatusCode was {matchedIds.ApiCall.HttpStatusCode} when querying provider standards for ukprn [{ukprn}]"); throw new ApplicationException($"Failed to query provider standards for ukprn [{ukprn}]"); } var matchingStandardIds = ExtractStandardCodesFromAggregation(matchedIds, aggregateKeyName); var providerStandards = _elasticsearchCustomClient.Search <ProviderStandard>( s => s.Index(_applicationSettings.ApprenticeshipIndexAlias) .From(0) .Take(matchingStandardIds.Count) .Query(q => + q.Term("documentType", "standarddocument") && +q.Terms(t => t.Field(f => f.StandardId).Terms(matchingStandardIds)))); if (providerStandards.ApiCall.HttpStatusCode != 200) { _applicationLogger.LogWarning($"httpStatusCode was {providerStandards.ApiCall.HttpStatusCode} when querying provider standards apprenticeship details for ukprn [{ukprn}]"); throw new ApplicationException($"Failed to query provider standards apprenticeship details for ukprn [{ukprn}]"); } return(providerStandards.Documents.Where(x => x.Published)); }