public ElasticsearchContextWarmer(ITraceProvider traceProvider, CancellationTokenSource cancellationTokenSource, ElasticsearchSerializerConfiguration elasticsearchSerializerConfiguration, HttpClient client, string connectionString) { _traceProvider = traceProvider; _cancellationTokenSource = cancellationTokenSource; _elasticsearchSerializerConfiguration = elasticsearchSerializerConfiguration; _client = client; _connectionString = connectionString; }
public ElasticsearchSerializer(ITraceProvider traceProvider, ElasticsearchSerializerConfiguration elasticsearchSerializerConfiguration, bool saveChangesAndInitMappingsForChildDocuments) { _elasticsearchSerializerConfiguration = elasticsearchSerializerConfiguration; _saveChangesAndInitMappingsForChildDocuments = saveChangesAndInitMappingsForChildDocuments; _traceProvider = traceProvider; _indexMappings = new IndexMappings(_traceProvider, _elasticsearchSerializerConfiguration); _elasticSerializationResult.IndexMappings = _indexMappings; }
public ElasticsearchContextExists(ITraceProvider traceProvider, CancellationTokenSource cancellationTokenSource, ElasticsearchSerializerConfiguration elasticsearchSerializerConfiguration, HttpClient client, string connectionString) { _traceProvider = traceProvider; _elasticsearchSerializerConfiguration = elasticsearchSerializerConfiguration; _connectionString = connectionString; ExistsHeadRequest = new Exists(_traceProvider, cancellationTokenSource, client); }
public ElasticsearchContextAddDeleteUpdate(ITraceProvider traceProvider, CancellationTokenSource cancellationTokenSource, ElasticsearchSerializerConfiguration elasticsearchSerializerConfiguration, HttpClient client, string connectionString) { _traceProvider = traceProvider; _cancellationTokenSource = cancellationTokenSource; _elasticsearchSerializerConfiguration = elasticsearchSerializerConfiguration; _client = client; _connectionString = connectionString; _elasticsearchUrlBatch = new Uri(new Uri(connectionString), BatchOperationPath); }
public void CreateNewIndexAndMappingForNestedChildInTwoStepsWithRouting() { const string index = "newindextestmappingtwostep"; IElasticsearchMappingResolver elasticsearchMappingResolver; var mappingTestsParent = SetupIndexMappingTests(index, out elasticsearchMappingResolver); var routing = new RoutingDefinition { RoutingId = "coolrouting" }; var config = new ElasticsearchSerializerConfiguration(elasticsearchMappingResolver, true, false, true); using (var context = new ElasticsearchContext(ConnectionString, config)) { context.AllowDeleteForIndex = true; context.TraceProvider = new ConsoleTraceProvider(); context.IndexCreate(index); Thread.Sleep(1500); Assert.True(context.IndexExists <MappingTestsParent>()); context.IndexCreateTypeMapping <MappingTestsParent>(new MappingDefinition { Index = index, RoutingDefinition = routing }); Thread.Sleep(1500); context.AddUpdateDocument(mappingTestsParent, mappingTestsParent.MappingTestsParentId, routing); context.SaveChanges(); Thread.Sleep(1500); var doc = context.GetDocument <MappingTestsParent>(mappingTestsParent.MappingTestsParentId, routing); Thread.Sleep(1500); Assert.NotNull(doc); context.DeleteIndex(index); Thread.Sleep(1500); Assert.False(context.IndexTypeExists <MappingTestsParent>()); if (context.IndexExists <MappingTestsParent>()) { context.DeleteIndex <MappingTestsParent>(); } } }
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); } }
public IndexMappings(ITraceProvider traceProvider, ElasticsearchSerializerConfiguration elasticsearchSerializerConfiguration) { _elasticsearchSerializerConfiguration = elasticsearchSerializerConfiguration; _traceProvider = traceProvider; }
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); } }
public void CreateNewIndexAndMappingForNestedChildInTwoStepsWithRouting() { const string index = "newindextestmappingtwostep"; IElasticsearchMappingResolver elasticsearchMappingResolver; var mappingTestsParent = SetupIndexMappingTests(index, out elasticsearchMappingResolver); var routing = new RoutingDefinition {RoutingId = "coolrouting"}; var config = new ElasticsearchSerializerConfiguration(elasticsearchMappingResolver,true,false,true); using (var context = new ElasticsearchContext(ConnectionString, config)) { context.AllowDeleteForIndex = true; context.TraceProvider = new ConsoleTraceProvider(); context.IndexCreate(index); Thread.Sleep(1500); Assert.IsTrue(context.IndexExists<MappingTestsParent>()); context.IndexCreateTypeMapping<MappingTestsParent>(new MappingDefinition { Index = index, RoutingDefinition = routing }); Thread.Sleep(1500); context.AddUpdateDocument(mappingTestsParent, mappingTestsParent.MappingTestsParentId, routing); context.SaveChanges(); Thread.Sleep(1500); var doc = context.GetDocument<MappingTestsParent>(mappingTestsParent.MappingTestsParentId, routing); Thread.Sleep(1500); Assert.IsNotNull(doc); context.DeleteIndexType<MappingTestsParent>(); Thread.Sleep(1500); Assert.IsFalse(context.IndexTypeExists<MappingTestsParent>()); if (context.IndexExists<MappingTestsParent>()) { context.DeleteIndex<MappingTestsParent>(); } } }