当前位置: 首页>>代码示例>>C#>>正文


C# ElasticsearchContext.SaveChangesAndInitMappings方法代码示例

本文整理汇总了C#中ElasticsearchContext.SaveChangesAndInitMappings方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticsearchContext.SaveChangesAndInitMappings方法的具体用法?C# ElasticsearchContext.SaveChangesAndInitMappings怎么用?C# ElasticsearchContext.SaveChangesAndInitMappings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ElasticsearchContext的用法示例。


在下文中一共展示了ElasticsearchContext.SaveChangesAndInitMappings方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveToElasticsearchStateProvinceIfitDoesNotExist

		public void SaveToElasticsearchStateProvinceIfitDoesNotExist()
		{
			IElasticsearchMappingResolver elasticsearchMappingResolver = new ElasticsearchMappingResolver();
			using (var elasticSearchContext = new ElasticsearchContext("http://localhost:9200/", new ElasticsearchSerializerConfiguration(elasticsearchMappingResolver, true, true)))
			{
				if (!elasticSearchContext.IndexTypeExists<StateProvince>())
				{
					elasticSearchContext.TraceProvider = new ConsoleTraceProvider();
					using (var databaseEfModel = new EfModel())
					{
						int pointer = 0;
						const int interval = 20;
						bool firstRun = true;
						int length = databaseEfModel.StateProvince.Count();

						while (pointer < length)
						{
							_stopwatch.Start();
							var collection =
								databaseEfModel.StateProvince.OrderBy(t => t.StateProvinceID)
									.Skip(pointer)
									.Take(interval)
									.ToList<StateProvince>();
							_stopwatch.Stop();
							Console.WriteLine("Time taken for select {0} Address: {1}", interval, _stopwatch.Elapsed);
							_stopwatch.Reset();

							_stopwatch.Start();
							foreach (var item in collection)
							{
								var ee = item.CountryRegion.Name;
								elasticSearchContext.AddUpdateDocument(item, item.StateProvinceID);
							}

							if (firstRun)
							{
								elasticSearchContext.SaveChangesAndInitMappings();
								firstRun = false;
							}
							else
							{
								elasticSearchContext.SaveChanges();
							}

							_stopwatch.Stop();
							Console.WriteLine("Time taken to insert {0} Address documents: {1}", interval, _stopwatch.Elapsed);
							_stopwatch.Reset();
							pointer = pointer + interval;
							Console.WriteLine("Transferred: {0} items", pointer);
						}
					}
				}
			}
		}
开发者ID:emretiryaki,项目名称:WebSearchWithElasticsearchEntityFrameworkAsPrimary,代码行数:54,代码来源:InitializeSearchEngine.cs

示例2: TestCreateCompletelyNewIndexExpectException

        public void TestCreateCompletelyNewIndexExpectException()
        {
            var parentDocument = GetParentDocumentEx();

            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ChildDocumentLevelOneEx),
                new ElasticsearchMappingChildDocumentForParentEx());
            _elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(ChildDocumentLevelTwoEx),
                new ElasticsearchMappingChildDocumentForParentEx());

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

                // Save to Elasticsearch
                context.SaveChangesAndInitMappings();
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:18,代码来源:DocumentsWithChildDocumentsTestNotAllowed.cs

示例3: CreateIndexList

        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);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:39,代码来源:MappingChildParentRoutingTests.cs

示例4: TestCreateCompletelyNewIndex

        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);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:25,代码来源:OneToNEntitiesSaveWithChildDocumentsTest.cs

示例5: CreateNewIndexAndMappingForNestedChild

        public void CreateNewIndexAndMappingForNestedChild()
        {
            var mappingTestsParent = new MappingTestsParent
            {
                Calls = 3,
                MappingTestsParentId = 2,
                MappingTestsItem = new MappingTestsChild
                {
                    Description = "Hello nested",
                    MappingTestsChildId = 5
                }
            };

            using (
                var context = new ElasticsearchContext(ConnectionString,
                    new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(mappingTestsParent, mappingTestsParent.MappingTestsParentId);
                context.SaveChangesAndInitMappings();

                Thread.Sleep(1500);
                var doc = context.GetDocument<MappingTestsParent>(mappingTestsParent.MappingTestsParentId);

                Assert.IsNotNull(doc);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:27,代码来源:MappingTests.cs

示例6: CreateNewIndexAndMappingWithSimpleNullListAndNullArrayList

        public void CreateNewIndexAndMappingWithSimpleNullListAndNullArrayList()
        {
            var mappingTestsParent = new MappingTestsParentWithSimpleNullAndNullArrayList
            {
                Calls = 3,
                MappingTestsParentId = 2,
                Call2s="test"
            };

            using (
                var context = new ElasticsearchContext(ConnectionString,
                    new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(mappingTestsParent, mappingTestsParent.MappingTestsParentId);
                context.SaveChangesAndInitMappings();

                Thread.Sleep(1500);
                var doc = context.GetDocument<MappingTestsParentWithSimpleNullAndNullArrayList>(mappingTestsParent.MappingTestsParentId);

                Assert.IsNotNull(doc);

                context.IndexClose("mappingtestsparentwithsimplenullandnullarraylists");
                context.IndexOpen("mappingtestsparentwithsimplenullandnullarraylists");
                var result = context.IndexOptimize("mappingtestsparentwithsimplenullandnullarraylists", new OptimizeParameters{NumberOfShards=3, Flush=true});

                Assert.GreaterOrEqual(result.PayloadResult.Shards.Successful, 1);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:29,代码来源:MappingTests.cs

示例7: CreateNewIndexAndMappingWithSimpleList

        public void CreateNewIndexAndMappingWithSimpleList()
        {
            var mappingTestsParent = new MappingTestsParentWithSimpleList
            {
                Calls = 3,
                MappingTestsParentId = 2,
                Call2s="test",
                MappingTestsItemIntList = new List<int> { 2, 7, 44, 176},
                MappingTestsItemShortArray =  new short[] { 4,7,89,9}
            };

            using (
                var context = new ElasticsearchContext(ConnectionString,
                    new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(mappingTestsParent, mappingTestsParent.MappingTestsParentId);
                context.SaveChangesAndInitMappings();

                Thread.Sleep(1500);
                var doc = context.GetDocument<MappingTestsParentWithSimpleList>(mappingTestsParent.MappingTestsParentId);

                Assert.IsNotNull(doc);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:25,代码来源:MappingTests.cs


注:本文中的ElasticsearchContext.SaveChangesAndInitMappings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。