Example #1
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);
            }
        }
        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);
            }
        }