示例#1
0
        private void TestCreateCompletelyNewIndex(ITraceProvider trace)
        {
            var parentDocument = ParentDocument();

            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ChildDocumentLevelOne),
                                                                               new ElasticsearchMappingChildDocumentForParent());
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ChildDocumentLevelTwo),
                                                                               new ElasticsearchMappingChildDocumentForParent());
            using (
                var context = new ElasticsearchContext(ConnectionString,
                                                       new ElasticsearchSerializerConfiguration(
                                                           _elasticsearchMappingResolver,
                                                           SaveChildObjectsAsWellAsParent,
                                                           ProcessChildDocumentsAsSeparateChildIndex)))
            {
                context.TraceProvider = trace;
                context.AddUpdateDocument(parentDocument, parentDocument.Id);

                // Save to Elasticsearch
                var ret = context.SaveChangesAndInitMappings();
                Assert.AreEqual(ret.Status, HttpStatusCode.OK);

                context.GetDocument <ParentDocument>(parentDocument.Id);
            }
        }
        public void Setup()
        {
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(object), new GlobalElasticsearchMapping());
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                var doc1 = new IndexOne
                {
                    Id           = 1,
                    RandomNumber = 49.3
                };
                var doc2 = new IndexOne
                {
                    Id           = 2,
                    RandomNumber = 49.3
                };
                var doc3 = new IndexTwo
                {
                    Id          = 1,
                    Description = "nice day"
                };

                context.IndexCreate <IndexOne>();
                context.IndexCreate <IndexTwo>();
                Thread.Sleep(1200);
                context.AddUpdateDocument(doc1, doc1.Id);
                context.AddUpdateDocument(doc2, doc2.Id);
                context.AddUpdateDocument(doc3, doc3.Id);
                context.SaveChanges();
                Thread.Sleep(1200);
            }
        }
 public PersonCitySearchProvider()
 {
     _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(PersonCityMappingDto), new PersonCityMapping());
     _context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver))
     {
         TraceProvider = new ConsoleTraceProvider()
     };
 }
 public ElasticsearchProvider()
 {
     _elasticsearchMappingResolver = new ElasticsearchMappingResolver();
     _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Address), new ElasticsearchMappingAddress());
     _elasticsearchContext = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, true, true));
     _elasticsearchContext.TraceProvider = new ConsoleTraceProvider();
     _entityFrameworkContext             = new EfModel();
 }
        private static void Main(string[] args)
        {
            // Define the mapping for the type so that all use the same index as the parent
            ElasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(LeagueCup),
                                                                              MappingUtils.GetElasticsearchMapping("leagues"));
            ElasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Team),
                                                                              MappingUtils.GetElasticsearchMapping("leagues"));
            ElasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Player),
                                                                              MappingUtils.GetElasticsearchMapping("leagues"));
            ElasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(object),
                                                                              new GlobalLeaguesElasticsearchMapping());

            CreateIndexWithRouting();
            Console.ReadLine();

            var leagueAndRoutingId = CreateNewLeague();

            Console.ReadLine();

            var teamId = AddTeamToCup(leagueAndRoutingId);

            Console.ReadLine();

            AddPlayerToTeam(teamId, leagueAndRoutingId);
            Console.ReadLine();

            var player = GetPlayer(3, leagueAndRoutingId, teamId);

            Console.WriteLine("Found player: " + player.Name);
            Console.ReadLine();

            GetAllForRoute(leagueAndRoutingId);
            Console.ReadLine();

            var globalSearch = new GlobalSearch(ConnectionString);

            globalSearch.GetAllForRouteFilterForPlayersAndTeams(leagueAndRoutingId);
            Console.ReadLine();

            globalSearch.RunGlobalSearch();
            Console.ReadLine();
        }
示例#6
0
        private void CreateIndex()
        {
            var doc = new MappingChildParentRoutingTestsLevel1
            {
                MappingChildParentRoutingTestsLevel1Id = 1,
                Level2 = new MappingChildParentRoutingTestsLevel2()
                {
                    MappingChildParentRoutingTestsLevel2Id = 2,
                    Level3 = new MappingChildParentRoutingTestsLevel3()
                    {
                        MappingChildParentRoutingTestsLevel3Id = 3
                    }
                }
            };

            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(MappingChildParentRoutingTestsLevel1),
                                                                               MappingUtils.GetElasticsearchMapping <MappingChildParentRoutingTestsLevel1>(new IndexTypeDescription("masterindex", "level1")));
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(MappingChildParentRoutingTestsLevel2),
                                                                               MappingUtils.GetElasticsearchMapping <MappingChildParentRoutingTestsLevel2>(new IndexTypeDescription("masterindex", "level2")));
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(MappingChildParentRoutingTestsLevel3),
                                                                               MappingUtils.GetElasticsearchMapping <MappingChildParentRoutingTestsLevel3>(new IndexTypeDescription("masterindex", "level3")));

            using (var context = new ElasticsearchContext(ConnectionString,
                                                          new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, true, true, true)))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(doc, doc.MappingChildParentRoutingTestsLevel1Id);

                var ret = context.SaveChangesAndInitMappings();
                // Save to Elasticsearch
                Assert.AreEqual(ret.Status, HttpStatusCode.OK);
            }
        }
示例#7
0
        public void TestDefaultContextAdd100Entities()
        {
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(SkillTestEntity), new SkillTestEntityElasticsearchMapping());

            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                for (int i = 0; i < 100; i++)
                {
                    context.AddUpdateDocument(_entitiesForTests[i], i);
                }

                // Save to Elasticsearch
                var ret = context.SaveChangesAsync();
                Assert.Equal(ret.Result.Status, HttpStatusCode.OK);
            }
        }
        public void TestFixtureSetUp()
        {
            var existsDtoForTests = new ExistsDtoForTests {
                Id = 1, Description = "Test index for exist tests"
            };

            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ExistsDtoForTestsTypeNot), new IndexMapping("existsdtofortestss"));

            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AddUpdateDocument(existsDtoForTests, existsDtoForTests.Id);
                context.SaveChanges();

                var result = context.AliasCreateForIndex("existsaliastest", "existsdtofortestss");
                Assert.IsTrue(result);
            }
        }
示例#9
0
        public void Setup()
        {
            var doc1 = new TestObjParentSep
            {
                Id           = 1,
                Info         = "yes this is great",
                ChildObjects = new List <TestObjChildSep>
                {
                    new TestObjChildSep
                    {
                        Id      = 1,
                        Details = "my child"
                    }
                }
            };

            var doc2 = new TestObjParentSep
            {
                Id           = 2,
                Info         = "yes this is great two child",
                ChildObjects = new List <TestObjChildSep>
                {
                    new TestObjChildSep
                    {
                        Id      = 1,
                        Details = "my child"
                    }
                }
            };

            var doc3 = new TestObjParentSep
            {
                Id           = 3,
                Info         = "yes this is great three",
                ChildObjects = new List <TestObjChildSep>
                {
                    new TestObjChildSep
                    {
                        Id      = 3,
                        Details = "my child three"
                    },
                    new TestObjChildSep
                    {
                        Id      = 4,
                        Details = "my child four"
                    }
                }
            };

            ElasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(TestObjChildSep),
                                                                              MappingUtils.GetElasticsearchMapping <TestObjChildSep>("testobjparentseps", "testobjchildsep"));

            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(ElasticsearchMappingResolver, true, true)))
            {
                context.IndexCreate <TestObjParentSep>();
                Thread.Sleep(1200);
                context.AddUpdateDocument(doc1, doc1.Id);
                context.AddUpdateDocument(doc2, doc2.Id);
                context.AddUpdateDocument(doc3, doc3.Id);
                context.SaveChanges();
                Thread.Sleep(1200);
            }
        }
示例#10
0
 public ElasticsearchCrudProvider()
 {
     // You don't need to create this Resolver everytime a new context is created...
     _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Animal), new AnimalToLowerExampleElasticsearchMapping());
     _elasticsearchContext = new ElasticsearchContext("http://localhost:9200/", new ElasticsearchSerializerConfiguration(new ElasticsearchMappingResolver(), true, false));
 }
 public CreateIndexPersonV1()
 {
     _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Person), MappingUtils.GetElasticsearchMapping("persons_v1"));
 }