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