public void MultipleLayerClass_Test() { var typeMapping = new TypeMapping <Multiple1LayerClass>(); var mappings1 = new KeyValuePair <Expression <Func <Multiple1LayerClass, object> >, FieldTypes>(ic => ic.Obj, FieldTypes.Object); var mappings2 = new KeyValuePair <Expression <Func <Multiple1LayerClass, object> >, FieldTypes>(ic => ic.Nested, FieldTypes.Nested); typeMapping.AddMapping(mappings1, mappings2); typeMapping.AddNestedMapping(mlc => mlc.Nested, new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.Word, FieldTypes.Keyword), new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.Value, FieldTypes.Double), new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.DateTime, FieldTypes.Date)); typeMapping.AddObjectMapping(mlc => mlc.Obj, new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.Word, FieldTypes.Keyword), new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.Value, FieldTypes.Double), new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.DateTime, FieldTypes.Date)); var mlTm = typeof(Multiple1LayerClass).GetTypeMapping <Multiple1LayerClass>(); var json1 = JsonConvert.SerializeObject(new { mappings = typeMapping }); var json2 = JsonConvert.SerializeObject(new { mappings = mlTm }); Assert.AreEqual(json1, json2); }
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 void TypeMappingJson_1() { var typeMapping = new TypeMapping <IndexedClass>(); var mappings = new KeyValuePair <Expression <Func <IndexedClass, object> >, FieldTypes>(ic => ic.Objects, FieldTypes.Nested); typeMapping.AddMapping(mappings); typeMapping.AddNestedMapping(ic => ic.Objects, new KeyValuePair <Expression <Func <IndexedClass2, object> >, FieldTypes>(ic => ic.BString, FieldTypes.Keyword)); var json = JsonConvert.SerializeObject(new { mappings = typeMapping }); Assert.AreEqual("{\"mappings\":{\"h73.Elastic.TypeMappingTests.IndexedClass\":{\"properties\":{\"Objects\":{\"properties\":{\"BString\":{\"type\":\"keyword\"}},\"type\":\"nested\"}}}}}", json); }
public void MultipleOneLayerClass_Test() { var typeMapping = new TypeMapping <MultipleOneLayerClass>(); var mappings1 = new KeyValuePair <Expression <Func <MultipleOneLayerClass, object> >, FieldTypes>(ic => ic.Word, FieldTypes.Keyword); var mappings2 = new KeyValuePair <Expression <Func <MultipleOneLayerClass, object> >, FieldTypes>(ic => ic.Value, FieldTypes.Double); var mappings3 = new KeyValuePair <Expression <Func <MultipleOneLayerClass, object> >, FieldTypes>(ic => ic.DateTime, FieldTypes.Date); typeMapping.AddMapping(mappings1, mappings2, mappings3); var mlTm = typeof(MultipleOneLayerClass).GetTypeMapping <MultipleOneLayerClass>(); var json1 = JsonConvert.SerializeObject(new { mappings = typeMapping }); var json2 = JsonConvert.SerializeObject(new { mappings = mlTm }); Assert.AreEqual(json1, json2); }
public void KeyWordClass_Test() { var typeMapping = new TypeMapping <KeyWordClass>(); var mappings = new KeyValuePair <Expression <Func <KeyWordClass, object> >, FieldTypes>( ic => ic.Word, FieldTypes.Keyword ); typeMapping.AddMapping(mappings); var kwTm = typeof(KeyWordClass).GetTypeMapping <KeyWordClass>(); var json1 = JsonConvert.SerializeObject(new { mappings = typeMapping }); var json2 = JsonConvert.SerializeObject(new { mappings = kwTm }); Assert.AreEqual(json1, json2); }