//Generator to create new employees for ES
        public static void SeedTheIndexWithNewEmployees(int numberToGenerate)
        {
            var counter = 0;
            var rnd = new Random();

            for (var i = 0; i < numberToGenerate; i++)
            {
                var description = new StringBuilder();

                for (int j = 0; j < 10; j++)
                {
                    int index = rnd.Next(ElasticSearchTestSeed.TestDescriptionSeedTags.GetUpperBound(0));
                    description.Append(ElasticSearchTestSeed.TestDescriptionSeedTags[index]);
                    if (i > 0) description.Append(" ");
                }

                var employee = new Employee
                                   {
                                       Id = Guid.NewGuid(),
                                       Name =
                                           ElasticSearchTestSeed.TestNames[rnd.Next(160)] + " " +
                                           ElasticSearchTestSeed.TestLastNames[rnd.Next(160)],
                                       DateOfBirth = DateTime.Now.AddDays(-(i - 30)),
                                       CompanyId = ElasticSearchTestSeed.CompanyIds[counter],
                                       Description = description.ToString(),
                                       FavoriteNumbers =
                                           new List<int>
                                               {
                                                   rnd.Next(1, 20),
                                                   rnd.Next(1, 20),
                                                   rnd.Next(1, 20),
                                                   rnd.Next(1, 20),
                                                   rnd.Next(1, 20)
                                               }
                                   };

                ElasticSearchClient.Index(employee, IndexName, TypeName, employee.Id.ToString(),
                                          new IndexParameters {Refresh = true});

                if (counter == 2)
                    counter = 0;
                else
                    counter++;

                EmployeeId = employee.Id;
            }

            Log(string.Format("Created {0} employees", numberToGenerate));
        }
Beispiel #2
0
        private static void IndexNewEmployees(int numEmployees)
        {
            var idCounter = 0;
              var rnd = new Random();

              for (var i = 0; i < numEmployees; i++)
              {
            var description = new StringBuilder();
            for (int c = 0; c < 10; c++)
            {
              description.Append(descWords[rnd.Next(descWords.GetUpperBound(0))]);
              description.Append(" ");
            }
            var emp = new Employee
            {
              Birthday = DateTime.Now.AddDays(i),
              CompanyId = companyIds[idCounter],
              Description = description.ToString(),
              FavoriteNumbers = new List<int> { rnd.Next(1, 20), rnd.Next(1, 20), rnd.Next(1, 20), rnd.Next(1, 20), rnd.Next(1, 20), },
              Id = Guid.NewGuid(),
              Name = names[rnd.Next(8)] + " " + names[rnd.Next(8)]
            };
            esClient.Index(emp, "employees", "employee", emp.Id.ToString(), new IndexParameters { Refresh = true });
            if (idCounter == 2) { idCounter = 0; }
            else { idCounter++; }
            employeeId = emp.Id;
              }
              Log(string.Format("Created {0} employees", numEmployees));
        }