示例#1
0
        private void CreateIndexList()
        {
            var doc = new ListMappingChildParentRoutingTestsLevel1
            {
                MappingChildParentRoutingTestsLevel1Id = 1,
                Level2 = new List <ListMappingChildParentRoutingTestsLevel2>
                {
                    new ListMappingChildParentRoutingTestsLevel2
                    {
                        MappingChildParentRoutingTestsLevel2Id = 2,
                        Level3 = new List <ListMappingChildParentRoutingTestsLevel3>
                        {
                            new ListMappingChildParentRoutingTestsLevel3
                            {
                                MappingChildParentRoutingTestsLevel3Id = 3
                            }
                        }
                    }
                }
            };

            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ListMappingChildParentRoutingTestsLevel1),
                                                                               MappingUtils.GetElasticsearchMapping("masterindexlist"));
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ListMappingChildParentRoutingTestsLevel2),
                                                                               MappingUtils.GetElasticsearchMapping("masterindexlist"));
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ListMappingChildParentRoutingTestsLevel3),
                                                                               MappingUtils.GetElasticsearchMapping("masterindexlist"));

            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 CreateIndexList()
        {
            var doc = new ListMappingChildParentRoutingTestsLevel1
            {
                MappingChildParentRoutingTestsLevel1Id = 1,
                Level2 = new List<ListMappingChildParentRoutingTestsLevel2>
                {
                    new ListMappingChildParentRoutingTestsLevel2
                    {
                        MappingChildParentRoutingTestsLevel2Id = 2,
                        Level3 = new List<ListMappingChildParentRoutingTestsLevel3>
                        {
                            new ListMappingChildParentRoutingTestsLevel3
                            {
                                MappingChildParentRoutingTestsLevel3Id = 3
                            }
                        }
                    }
                }
            };

            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ListMappingChildParentRoutingTestsLevel1),
            MappingUtils.GetElasticsearchMapping("masterindexlist"));
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ListMappingChildParentRoutingTestsLevel2),
                MappingUtils.GetElasticsearchMapping("masterindexlist"));
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ListMappingChildParentRoutingTestsLevel3),
                MappingUtils.GetElasticsearchMapping("masterindexlist"));

            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);
            }
        }