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


C# ElasticsearchContext.Alias方法代码示例

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


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

示例1: CreateAliasForIndex2

        public void CreateAliasForIndex2()
        {
            var indexAliasDtoTest = new IndexAliasDtoTest { Id = 1, Description = "Test index for aliases" };

            var aliasParameters = new AliasParameters
            {
                Actions = new List<AliasBaseParameters>
                {
                    new AliasAddParameters("test2", "indexaliasdtotests"),
                    new AliasAddParameters("test3", "indexaliasdtotests")
                }
            };

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

                var result = context.Alias(aliasParameters.ToString());
                Assert.IsTrue(result);

                Assert.IsTrue(context.AliasExists("test2"));
                Assert.IsTrue(context.AliasExists("test3"));

            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:26,代码来源:AliasElasticsearchCrudTests.cs

示例2: CreateAliasForIndex3

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

示例3: RenameAliasForIndex

        public void RenameAliasForIndex()
        {
            var indexAliasDtoTest = new IndexAliasDtoTest { Id = 1, Description = "Test index for aliases" };

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

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

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


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