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


C# ElasticsearchContext.AliasReplaceIndex方法代码示例

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


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

示例1: ReplaceIndexForAlias

        public void ReplaceIndexForAlias()
        {
            var indexAliasDtoTest = new IndexAliasDtoTest { Id = 1, Description = "Test index for aliases" };
            var indexAliasDtoTestTwo = new IndexAliasDtoTestTwo { Id = 1, Description = "Test Doc Type Two index for aliases" };

            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AddUpdateDocument(indexAliasDtoTest, indexAliasDtoTest.Id);
                context.AddUpdateDocument(indexAliasDtoTestTwo, indexAliasDtoTestTwo.Id);
                context.SaveChanges();

                var resultCreate = context.AliasCreateForIndex("test", "indexaliasdtotests");
                Assert.IsTrue(resultCreate);

                var result = context.AliasReplaceIndex("test", "indexaliasdtotests", "indexaliasdtotesttwos");
                Assert.IsTrue(result);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:18,代码来源:AliasElasticsearchCrudTests.cs

示例2: ReindexTest

        public void ReindexTest()
        {
            var indexAliasDtoTestV1 = new IndexAliasDtoTestThree { Id = 1, Description = "V1" };
            var indexAliasDtoTestV2 = new IndexAliasDtoTestThree { Id = 2, Description = "V2" };

            IElasticsearchMappingResolver elasticsearchMappingResolverDirectIndex = new ElasticsearchMappingResolver();
            IElasticsearchMappingResolver elasticsearchMappingResolverDirectIndexV1 = new ElasticsearchMappingResolver();
            var mappingV1 = new IndexAliasDtoTestThreeMappingV1();

            IElasticsearchMappingResolver elasticsearchMappingResolverDirectIndexV2 = new ElasticsearchMappingResolver();
            var mappingV2 = new IndexAliasDtoTestThreeMappingV2();

            elasticsearchMappingResolverDirectIndexV1.AddElasticSearchMappingForEntityType(typeof(IndexAliasDtoTestThree), mappingV1);
            elasticsearchMappingResolverDirectIndexV2.AddElasticSearchMappingForEntityType(typeof(IndexAliasDtoTestThree), mappingV2);

            // Step 1 create index V1 and add alias
            using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndexV1))
            {
                // create the index
                context.AddUpdateDocument(indexAliasDtoTestV1, indexAliasDtoTestV1.Id);
                context.SaveChanges();

                var resultCreate = context.AliasCreateForIndex("indexaliasdtotestthrees", "indexaliasdtotestthree_v1");
                Assert.IsTrue(resultCreate);
            }

            // Step 2 create index V2 and replace alias
            using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndexV2))
            {
                // create the index
                context.AddUpdateDocument(indexAliasDtoTestV2, indexAliasDtoTestV2.Id);
                context.SaveChanges();

                var result = context.AliasReplaceIndex("indexaliasdtotestthrees", "indexaliasdtotestthree_v1", "indexaliasdtotestthree_v2");
                Assert.IsTrue(result);
            }

            Task.Run(() =>
            {
                using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndex))
                {
                    while (true)
                    {
                        Thread.Sleep(1000);
                        var itemOk = context.SearchById<IndexAliasDtoTestThree>(2);
                        if (itemOk != null)
                        {
                            _resetEvent.Set();
                        }

                    }
                }
            // ReSharper disable once FunctionNeverReturns
            });

            WaitForDataOrFail();

            // delete index v1
            using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndexV1))
            {
                context.AllowDeleteForIndex = true;
                var thirdDelete = context.DeleteIndexAsync<IndexAliasDtoTestThree>();
                thirdDelete.Wait();
            }

            // delete index v2
            using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndexV2))
            {
                context.AllowDeleteForIndex = true;
                var thirdDelete = context.DeleteIndexAsync<IndexAliasDtoTestThree>();
                thirdDelete.Wait();
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:73,代码来源:AliasElasticsearchCrudTests.cs


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