public void ShouldReturnIndexNamesFromConfigurationForMappedObjectType() { var clientFactory = new ElasticsearchClientFactory(ElasticsearchConfiguration.Instance, false); clientFactory.GetIndexNameForType(typeof(ApprenticeshipSummary)).Should().Be("ApprenticeshipIndex"); clientFactory.GetIndexNameForType(typeof(TraineeshipSummary)).Should().Be("TraineeshipIndex"); clientFactory.GetIndexNameForType(typeof(TestMappingClass)).Should().Be("TestMappingClassIndex"); }
static void Main(string[] args) { var scroll = args[0]; var size = int.Parse(args[1]); Console.WriteLine("Scroll: {0}, Size {1}", scroll, size); var clientFactory = new ElasticsearchClientFactory(ElasticsearchConfiguration.Instance, false); var client = clientFactory.GetElasticClient(); Console.WriteLine("Connected. Press any key to start"); Console.ReadKey(); var indexName = clientFactory.GetIndexNameForType(typeof(Elastic.Common.Entities.Address)); var documentTypeName = clientFactory.GetDocumentNameForType(typeof(Elastic.Common.Entities.Address)); var scanResults = client.Search <Elastic.Common.Entities.Address>(s => s .Index(indexName) .Type(documentTypeName) .From(0) .Size(size) .Filter(fd => fd.Not(fd2 => fd2.Exists(fd3 => fd3.PostcodeSearch))) .SearchType(SearchType.Scan) .Scroll(scroll) ); var scrolls = 0; var totalUpdates = 0; var results = client.Scroll <Elastic.Common.Entities.Address>(GetScrollSelector(scanResults, scroll)); while (results.Hits.Any()) { var updates = 0; var descriptor = new BulkDescriptor(); foreach (var address in results.Hits) { AddPostcodeSearch(address, descriptor); updates++; totalUpdates++; } client.Bulk(descriptor); Console.WriteLine("Bulk updated {0} addresses. {1} addresses updated so far", updates, totalUpdates); results = client.Scroll <Elastic.Common.Entities.Address>(GetScrollSelector(results, scroll)); scrolls++; Console.WriteLine("Updated batch {0}", scrolls); } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public SearchResponse Search(SearchRequest request) { var searchFactorConfiguration = new SearchFactorConfiguration { DescriptionFactors = GetFactorsFromRequest(SearchFactorKeys.Description, request), EmployerFactors = GetFactorsFromRequest(SearchFactorKeys.Employer, request), JobTitleFactors = GetFactorsFromRequest(SearchFactorKeys.JobTitle, request), ProviderFactors = GetFactorsFromRequest(SearchFactorKeys.Provider, request) }; var configurationService = new VacancySearchConfigurationService( _configurationService, searchFactorConfiguration); var elasticsearchClientFactory = new ElasticsearchClientFactory( configurationService, _logService); var searchProvider = new ApprenticeshipsSearchProvider( elasticsearchClientFactory, _mapper, configurationService, _logService); var parameters = new ApprenticeshipSearchParameters { PageNumber = 1, PageSize = 50, SearchField = GetSearchFieldFromRequest(request), Keywords = request.SearchTerms, SortType = VacancySearchSortType.Relevancy }; var indexDate = new DateTime(2020, 01, 01, 12, 00, 00); var indexAlias = elasticsearchClientFactory.GetIndexNameForType(typeof(ApprenticeshipSummary)); var indexName = string.Format("{0}.{1}", indexAlias, indexDate.ToUniversalTime().ToString("yyyy-MM-dd-HH")); var vacancies = searchProvider.FindVacancies(parameters, indexName); return(new SearchResponse { Request = request, SearchResults = vacancies.Results.ToArray(), Total = vacancies.Total, SearchFactorConfiguration = configurationService.Get <SearchFactorConfiguration>(), Parameters = parameters }); }