Exemple #1
0
        public void AddSimpleTestData()
        {
            client.DeleteIndex(x => x.Index<Car>());
            client.CreateIndex(c => c.Index<Car>().AddMapping<Car>(x => x
            .Properties(prop => prop.String(str => str.Name(s => s.EngineType).Index(FieldIndexOption.NotAnalyzed)))));

            for (int i = 0; i < 10; i++)
            {
                var car = new Car
                {
                    Timestamp = new DateTime(2010, i + 1, 1),
                    Name = "Car" + i,
                    Price = 10,
                    Sold = i % 2 == 0 ? true : false,
                    CarType = "Type" + i % 3,
                    Length = i,
                    EngineType = i % 2 == 0 ? EngineType.Diesel : EngineType.Standard,
                    Weight = 5,
                    ConditionalRanking = i%2 ==0 ? null : (int?)i,
                    Description = "Desc" + i,
                };

                var json = Encoding.UTF8.GetString(client.Serializer.Serialize(car));
                Console.WriteLine(json);
                client.Index(car);
            }
            client.Flush(x => x.Index<Car>());
        }
Exemple #2
0
        private void AddSimpleTestData()
        {
            client.DeleteIndex(x => x.Index<Car>());
            client.CreateIndex(c => c.Index<Car>().AddMapping<Car>(x => x
            .Properties(prop => prop.String(str => str.Name(s => s.EngineType).Index(FieldIndexOption.NotAnalyzed)))));
            client.DeleteIndex(x => x.Index<User>());
            client.CreateIndex(c => c.Index<User>().AddMapping<User>(x => x
            .Properties(prop => prop.String(str => str.Name(s => s.Email).Index(FieldIndexOption.NotAnalyzed)))));

            for (int i = 0; i < 10; i++)
            {
                var car = new Car
                {
                    Timestamp = new DateTime(2010,(i%12)+1,1),
                    Name = "Car" + i,
                    Price = 10,
                    Sold = i % 2 == 0,
                    CarType = "Type" + i%2,
                    Emissions = i+1
                };
                client.Index(car);
            }

            for (int i = 0; i < 10; i++)
            {
                var user = new User
                {
                    Email = "Email@email"+i%2+".com",
                    Name = "name"+i%3,
                    Age = i+1,
                    Enabled = i%2 == 0,
                    Active = i % 2 == 0,
                    Type = i % 2 == 0 ? UserType.Admin : UserType.Standard,
                    CreationTime = DateTime.Now
                };
                client.Index<User>(user);
            }
            client.Flush(x => x.Index<User>());
            client.Flush(x => x.Index<Car>());
        }
Exemple #3
0
 private void AddSimpleTestData()
 {
     client.DeleteIndex(x => x.Index<Car>());
     for (int i = 0; i < 10; i++)
     {
         var car = new Car
         {
             Timestamp = new DateTime(2010,i+1,1),
             Name = "Car" + i,
             Price = 10,
             Sold = i % 2 == 0 ? true : false,
             CarType = "Type" + i%3,
             Length = i*2,
             Weight = i
         };
         client.Index(car);
     }
     client.Flush(x => x.Index<Car>());
 }
Exemple #4
0
        public void Guid_Filter_Test()
        {
            var indexName = "cars3";
            client.DeleteIndex(indexName);
            var createIndexResult = client.CreateIndex(indexName, i => i.AddMapping<Car>(x => x
            .Properties(prop => prop.String(str => str.Name(s => s.Guid).Index(FieldIndexOption.NotAnalyzed)))));
            Check.That(createIndexResult.Acknowledged).IsTrue();
            for (int i = 0; i < 10; i++)
            {
                var car = new Car
                {
                    Timestamp = new DateTime(2010, (i % 12) + 1, 1),
                    Name = "Car" + i,
                    Price = 10,
                    Sold = i % 2 == 0,
                    CarType = "Type" + i % 2,
                    Emissions = i + 1
                };

                if (i == 1)
                {
                    car.Guid = "17c175f0-15ae-4f94-8d34-66574d7784d4";
                }

                client.Index(car, ind => ind.Index(indexName));
            }
            client.Flush(x => x.Index(indexName));

            var sc = new SearchDescriptor<Car>().Index(indexName).FilteredOn(x => x.Guid == "17c175f0-15ae-4f94-8d34-66574d7784d4");
            var result = client.Search<Car>(sc);
            Check.That(result.Documents).HasSize(1);
        }