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); } }
private static MappingTestsParent SetupIndexMappingTests(string index, out IElasticsearchMappingResolver elasticsearchMappingResolver) { var mappingTestsParent = new MappingTestsParent { Calls = 3, MappingTestsParentId = 2, MappingTestsItem = new MappingTestsChild { Description = "Hello nested", MappingTestsChildId = 5 } }; elasticsearchMappingResolver = new ElasticsearchMappingResolver(); elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(MappingTestsParent), MappingUtils.GetElasticsearchMapping(index)); return(mappingTestsParent); }
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(); }
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); } }
public void CreateAliasForIndex3() { var indexAliasDtoTest3 = new IndexAliasDtoTest { Id = 3, Description = "no" }; var indexAliasDtoTest4 = new IndexAliasDtoTest { Id = 4, Description = "boo" }; var indexAliasDtoTest5 = new IndexAliasDtoTest { Id = 5, Description = "boo" }; var aliasParameters = new AliasParameters { Actions = new List <AliasBaseParameters> { new AliasAddParameters("test4", "indexaliasdtotests") { Routing = "newroute", Filter = new TermFilter("description", "boo") // "{ \"term\" : { \"description\" : \"boo\" } }" } } }; const bool userDefinedRouting = true; var elasticsearchSerializerConfiguration = new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, true, false, userDefinedRouting); using (var context = new ElasticsearchContext(ConnectionString, elasticsearchSerializerConfiguration)) { context.AddUpdateDocument(indexAliasDtoTest3, indexAliasDtoTest3.Id, new RoutingDefinition { RoutingId = "newroute" }); context.AddUpdateDocument(indexAliasDtoTest4, indexAliasDtoTest4.Id, new RoutingDefinition { RoutingId = "newroute" }); context.AddUpdateDocument(indexAliasDtoTest5, indexAliasDtoTest5.Id, new RoutingDefinition { RoutingId = "newroute" }); context.SaveChanges(); var result = context.Alias(aliasParameters.ToString()); Assert.IsTrue(result); Assert.IsTrue(context.AliasExists("test4")); // using the index var doc3 = context.GetDocument <IndexAliasDtoTest>(3, new RoutingDefinition { RoutingId = "newroute" }); Assert.IsTrue(doc3.Id == 3); var doc4 = context.GetDocument <IndexAliasDtoTest>(4, new RoutingDefinition { RoutingId = "newroute" }); Assert.IsTrue(doc4.Id == 4); } IElasticsearchMappingResolver elasticsearchMappingResolver = new ElasticsearchMappingResolver(); elasticsearchMappingResolver.AddElasticSearchMappingForEntityType( typeof(IndexAliasDtoTest), MappingUtils.GetElasticsearchMapping <IndexAliasDtoTest>("test4", "indexaliasdtotest") ); using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolver)) { // using the alias var xx = context.GetDocument <IndexAliasDtoTest>(4); Assert.IsTrue(xx.Id == 4); // should not be found due to filter var result = context.SearchById <IndexAliasDtoTest>(3); Assert.IsNull(result); } }
/// <summary> /// Reindex constructor. The class reuires a index and a type for the old index and also the new index. The old index can then be converteds or reindexed to the new index. /// </summary> /// <param name="oldIndexTypeDescription">index and index type parameters for the old index</param> /// <param name="newIndexTypeDescription">index and index type parameters for the new index</param> /// <param name="connectionString">Elasticsearch connection string</param> public ElasticsearchCrudReindex(IndexTypeDescription oldIndexTypeDescription, IndexTypeDescription newIndexTypeDescription, string connectionString) { _oldIndexTypeDescription = oldIndexTypeDescription; _newIndexTypeDescription = newIndexTypeDescription; IElasticsearchMappingResolver elasticsearchMappingResolver = new ElasticsearchMappingResolver(); elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(TNew), MappingUtils.GetElasticsearchMapping <TNew>(newIndexTypeDescription)); elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(TOld), MappingUtils.GetElasticsearchMapping <TOld>(oldIndexTypeDescription)); _context = new ElasticsearchContext(connectionString, elasticsearchMappingResolver); }
public CreateIndexPersonV1() { _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Person), MappingUtils.GetElasticsearchMapping("persons_v1")); }