public IIndexer <TSource> CreateIndexer <TSource, TSearchDocument>( string indexName, Func <TSource, TSearchDocument> mapper, int documentsPerBatch) where TSource : class where TSearchDocument : class, IHasId { var indexer = new ElasticIndexer <TSource, TSearchDocument>(indexName, _elasticClient, mapper, documentsPerBatch); _indexers.Add(indexer); return(indexer); }
public void TestInitialize1() { var faker = new Faker(); var itemCountGenerator = new RandomGenerator(); var customers = Builder <Customer> .CreateListOfSize(1000) .All() .With(c => c.FirstName = faker.Name.FirstName()) .With(c => c.LastName = faker.Name.LastName()) .With(c => c.TelephoneNumber = faker.Phone.PhoneNumber()) .With(c => c.Id = Guid.NewGuid().ToString()) .With(c => c.Created = faker.Date.Past()) .With(c => c.Age = itemCountGenerator.Next(1, 200)) .Random(70) .With(c => c.EmailAddress = faker.Internet.Email()) .Build(); customers.ForEach(c => { c.Products = Builder <Product> .CreateListOfSize(itemCountGenerator.Next(1, 200)) .All() .With(oi => oi.Description = faker.Lorem.Sentence(itemCountGenerator.Next(3, 10))) .With(oi => oi.Id = Guid.NewGuid().ToString()) .With(oi => oi.Name = faker.Hacker.Noun()) .With(oi => oi.Price = faker.Finance.Amount()) .Build().ToList(); }); var configuration = IntegrationTestHelper.GetApplicationConfiguration(); _client = new ElasticClient(configuration.Protocol, configuration.Host, configuration.Port, true, configuration.Username, configuration.Password, "test"); var indexer = new ElasticIndexer <Customer>(_client); var tmap = new TypeMapping <Customer>(); tmap.AddMapping( new KeyValuePair <Expression <Func <Customer, object> >, FieldTypes>(customer => customer.Products, FieldTypes.Nested), new KeyValuePair <Expression <Func <Customer, object> >, FieldTypes>(customer => customer.FirstName, FieldTypes.Keyword), new KeyValuePair <Expression <Func <Customer, object> >, FieldTypes>(customer => customer.LastName, FieldTypes.Keyword)); indexer.DeleteIndex(ServerHelpers.CreateIndexName <Customer>("test")); indexer.CreateIndex(tmap); indexer.IndexBulk(customers, customer => customer.Id, 100); Thread.Sleep(3000); }
public async Task MapsSourceToSearchDocument() { var mockElasticClient = new MockElasticClient(); var mappedSearchDocument = new SearchDocument(); var indexer = new ElasticIndexer <Source, SearchDocument>("my-index", mockElasticClient.ElasticClient, (tfr) => mappedSearchDocument); var source = new Source(); await indexer.IndexAsync(source); Assert.Single(mockElasticClient.BulkRequests); var indexedDoc = mockElasticClient.GetFirstBulkOperation().GetBody() as SearchDocument; Assert.Same(mappedSearchDocument, indexedDoc); }