本文整理汇总了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"));
}
}
示例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);
}
}
示例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);
}
}