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


C# ElasticsearchContext.DeleteIndexAsync方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            IElasticsearchMappingResolver elasticsearchMappingResolver = new ElasticsearchMappingResolver();
            // You only require a mapping if the default settings are not good enough
            //elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Skill), new SkillElasticsearchMapping());

            using (var elasticSearchContext = new ElasticsearchContext("http://localhost:9200/", elasticsearchMappingResolver))
            {
                elasticSearchContext.TraceProvider = new TraceProvider("tracingExample");
                elasticSearchContext.AddUpdateDocument(TestData.SkillEf, TestData.SkillEf.Id);
                elasticSearchContext.AddUpdateDocument(TestData.SkillOrm, TestData.SkillOrm.Id);
                elasticSearchContext.AddUpdateDocument(TestData.SkillSQLServer, TestData.SkillSQLServer.Id);
                elasticSearchContext.AddUpdateDocument(TestData.SkillGermanWithFunnyLetters, TestData.SkillGermanWithFunnyLetters.Id);
                elasticSearchContext.AddUpdateDocument(TestData.SkillLevel, TestData.SkillLevel.Id);

                var addEntitiesResult = elasticSearchContext.SaveChanges();

                Console.WriteLine(addEntitiesResult.PayloadResult);
                Console.WriteLine(addEntitiesResult.Status);
                Console.WriteLine(addEntitiesResult.Description);
            }

            using (var elasticSearchContext = new ElasticsearchContext("http://localhost:9200/", elasticsearchMappingResolver))
            {
                elasticSearchContext.TraceProvider = new TraceProvider("tracingExample");
                // get a entity and update it, then delete an entity
                Skill singleEntityWithId = elasticSearchContext.GetDocument<Skill>("11");
                singleEntityWithId.Updated = DateTime.UtcNow;
                elasticSearchContext.AddUpdateDocument(TestData.SkillOrm, TestData.SkillOrm.Id);
                elasticSearchContext.DeleteDocument<Skill>(TestData.SkillEf.Id);
                elasticSearchContext.SaveChanges();

                elasticSearchContext.AddUpdateDocument(TestData.SkillEf, TestData.SkillEf.Id);
                var nextResult = elasticSearchContext.SaveChanges();

                Console.WriteLine(nextResult.PayloadResult);
                Console.WriteLine(nextResult.Status);
                Console.WriteLine(nextResult.Description);
            }

            using (var elasticSearchContext = new ElasticsearchContext("http://localhost:9200/", elasticsearchMappingResolver))
            {
                elasticSearchContext.TraceProvider = new TraceProvider("tracingExample");
                // deleting indexes are usually not required...
                elasticSearchContext.AllowDeleteForIndex = true;
                var result = elasticSearchContext.DeleteIndexAsync<SkillLevel>();
                result.Wait();
                var result1 = elasticSearchContext.DeleteIndexAsync<Skill>();
                result1.Wait();
                //var result = elasticSearchContext.DeleteIndex<Skill>();
                elasticSearchContext.SaveChanges();
                //Console.WriteLine(result.Result.PayloadResult);
                //Console.WriteLine(result.Result.Status);
                //Console.WriteLine(result.Result.Description);
                //Console.ReadLine();
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:57,代码来源:Program.cs

示例2: TearDown

        public void TearDown()
        {
            _entitiesForTests = null;

            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AllowDeleteForIndex = true;
                var entityResult = context.DeleteIndexAsync<SkillTestEntity>();

                entityResult.Wait();
                var secondDelete = context.DeleteIndexAsync<SkillTestEntityTwo>();
                secondDelete.Wait();

                var thirdDelete = context.DeleteIndexAsync<TestJsonIgnore>();
                thirdDelete.Wait();
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:17,代码来源:DefaultElasticsearchCRUDTests.cs

示例3: TearDown

 public void TearDown()
 {
     using (var context = new ElasticsearchContext(ConnectionString, ElasticsearchMappingResolver))
     {
         context.AllowDeleteForIndex = true;
         var entityResult = context.DeleteIndexAsync<SearchTest>(); entityResult.Wait();
     }
 }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:8,代码来源:SetupSearch.cs

示例4: FixtureTearDown

 public void FixtureTearDown()
 {
     using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
     {
         context.AllowDeleteForIndex = true;
         if (context.IndexExists<IndexOne>())
         {
             context.DeleteIndex<IndexOne>();
         }
         if (context.IndexExists<IndexTwo>())
         {
             var entityResult2 = context.DeleteIndexAsync<IndexTwo>();
             entityResult2.Wait();
         }
     }
 }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:16,代码来源:GlobalApiTestsSearchCountTests.cs

示例5: TearDown

        public void TearDown()
        {
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AllowDeleteForIndex = true;
                var entityResult = context.DeleteIndexAsync<IndexAliasDtoTest>();
                entityResult.Wait();

                var secondDelete = context.DeleteIndexAsync<IndexAliasDtoTestTwo>();
                secondDelete.Wait();
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:12,代码来源:AliasElasticsearchCrudTests.cs

示例6: 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

示例7: TearDown

        public void TearDown()
        {
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AllowDeleteForIndex = true;
                var entityResult1 = context.DeleteIndexAsync<SkillTestEntityTwo>();entityResult1.Wait();
                var entityResult2 = context.DeleteIndexAsync<SkillParentCollection>(); entityResult2.Wait();
                var entityResult3 = context.DeleteIndexAsync<SkillParentArray>(); entityResult3.Wait();
                var entityResult4 = context.DeleteIndexAsync<SkillChild>(); entityResult4.Wait();
                var entityResult5 = context.DeleteIndexAsync<SkillTestEntity>(); entityResult5.Wait();
                var entityResult6 = context.DeleteIndexAsync<SkillWithIntArray>(); entityResult6.Wait();
                var entityResult7 = context.DeleteIndexAsync<SkillWithIntCollection>(); entityResult7.Wait();
                var entityResult8 = context.DeleteIndexAsync<SkillWithSingleChild>(); entityResult8.Wait();
                var entityResult9 = context.DeleteIndexAsync<SkillSingleChildElement>(); entityResult9.Wait();
                var entityResult10 = context.DeleteIndexAsync<SkillWithIntCollection>(); entityResult10.Wait();
                var entityResult11 = context.DeleteIndexAsync<SkillWithStringLongAndDoubleArray>(); entityResult11.Wait();
                var entityResult12 = context.DeleteIndexAsync<SkillWithStringLongAndDoubleCollection>(); entityResult12.Wait();
                var entityResult13 = context.DeleteIndexAsync<SkillDocumentHastSet>(); entityResult13.Wait();

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

示例8: TearDownFixture

        public void TearDownFixture()
        {
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AllowDeleteForIndex = true;

                if (context.IndexExists<FastestAnimal>())
                {
                    var entityResult1 = context.DeleteIndexAsync<FastestAnimal>();
                    entityResult1.Wait();
                }

                if (context.IndexExists<FastestAnimalPostings>())
                {
                    var entityResult2 = context.DeleteIndexAsync<FastestAnimalPostings>();
                    entityResult2.Wait();
                }

                if (context.IndexExists<FastestAnimalFastVectorHighlighter>())
                {
                    var entityResult3 = context.DeleteIndexAsync<FastestAnimalFastVectorHighlighter>();
                    entityResult3.Wait();
                }
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:25,代码来源:SearchHighlightAndRescoreTests.cs

示例9: TestTearDown

        public void TestTearDown()
        {
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.AllowDeleteForIndex = true;
                var entityResult = context.DeleteIndexAsync<GeoPointDto>();
                var entityResult1 = context.DeleteIndexAsync<GeoShapePointDto>();
                var entityResult2 = context.DeleteIndexAsync<GeoShapeLineStringDto>();
                var entityResult3 = context.DeleteIndexAsync<GeoShapePolygonDto>();
                var entityResult4 = context.DeleteIndexAsync<GeoShapeMultiPointDto>();
                var entityResult5 = context.DeleteIndexAsync<GeoShapeMultiLineStringDto>();
                var entityResult6 = context.DeleteIndexAsync<GeoShapeMultiPolygonDto>();
                var entityResult7 = context.DeleteIndexAsync<GeoShapeGeometryCollectionDto>();
                var entityResult8 = context.DeleteIndexAsync<GeoShapeEnvelopeDto>();
                var entityResult9 = context.DeleteIndexAsync<GeoShapeCircleDto>();

                entityResult.Wait();
                entityResult1.Wait();
                entityResult2.Wait();
                entityResult3.Wait();
                entityResult4.Wait();
                entityResult5.Wait();
                entityResult6.Wait();
                entityResult7.Wait();
                entityResult8.Wait();
                entityResult9.Wait();
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:28,代码来源:GeoPointAndGeoShapeTests.cs

示例10: TestDefaultContextDeleteIndexNotFound

 public void TestDefaultContextDeleteIndexNotFound()
 {
     using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
     {
         context.TraceProvider = new ConsoleTraceProvider();
         context.AllowDeleteForIndex = true;
         var entityResult = context.DeleteIndexAsync<SkillTestEntityNoIndex>();
         entityResult.Wait();
         Assert.AreEqual(entityResult.Result.Status, HttpStatusCode.NotFound);
     }
 }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:11,代码来源:DefaultElasticsearchCRUDTests.cs

示例11: TestDefaultContextDeleteIndexNotActivated

        public void TestDefaultContextDeleteIndexNotActivated()
        {
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                var entityResult = context.DeleteIndexAsync<SkillTestEntity>();

                try
                {
                    entityResult.Wait();
                }
                catch (AggregateException ae)
                {

                    ae.Handle(x =>
                    {
                        if (x is ElasticsearchCrudException) // This is what we expect.
                        {
                            throw x;
                        }
                        return false; // stop.
                    });
                }

                Assert.AreEqual(entityResult.Result.Status, HttpStatusCode.OK);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:27,代码来源:DefaultElasticsearchCRUDTests.cs

示例12: TestDefaultContextDeleteIndex

        public void TestDefaultContextDeleteIndex()
        {
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                for (int i = 0; i < 100; i++)
                {
                    context.AddUpdateDocument(_entitiesForTests[i], i);
                }

                // Save to Elasticsearch
                var ret = context.SaveChangesAsync();
                Assert.AreEqual(ret.Result.Status, HttpStatusCode.OK);
            }

            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.AllowDeleteForIndex = true;
                var entityResult = context.DeleteIndexAsync<SkillTestEntityNoIndex>();
                entityResult.Wait();
                Assert.AreEqual(entityResult.Result.Status, HttpStatusCode.NotFound);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:24,代码来源:DefaultElasticsearchCRUDTests.cs

示例13: FixtureTearDown

 public void FixtureTearDown()
 {
     using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
     {
         if (context.IndexExists<MappingTestsParent>())
         {
             context.AllowDeleteForIndex = true;
             context.DeleteIndex<MappingTestsParent>();
         }
         if (context.IndexExists<MappingTestsParentWithList>())
         {
             context.AllowDeleteForIndex = true;
             var entityResult2 = context.DeleteIndexAsync<MappingTestsParentWithList>();
             entityResult2.Wait();
         }
         if (context.IndexExists<MappingTestsParentWithArray>())
         {
             context.AllowDeleteForIndex = true;
             var entityResult3 = context.DeleteIndexAsync<MappingTestsParentWithArray>();
             entityResult3.Wait();
         }
         if (context.IndexExists<MappingTestsParentWithSimpleList>())
         {
             context.AllowDeleteForIndex = true;
             var entityResult4 = context.DeleteIndexAsync<MappingTestsParentWithSimpleList>();
             entityResult4.Wait();
         }
         if (context.IndexExists<MappingTestsParentNull>())
         {
             context.AllowDeleteForIndex = true;
             var entityResult5 = context.DeleteIndexAsync<MappingTestsParentNull>();
             entityResult5.Wait();
         }
         if (context.IndexExists<MappingTestsParentWithListNull>())
         {
             context.AllowDeleteForIndex = true;
             var entityResult6 = context.DeleteIndexAsync<MappingTestsParentWithListNull>();
             entityResult6.Wait();
         }
         if (context.IndexExists<MappingTestsParentWithArrayNull>())
         {
             context.AllowDeleteForIndex = true;
             var entityResult7 = context.DeleteIndexAsync<MappingTestsParentWithArrayNull>();
             entityResult7.Wait();
         }
         if (context.IndexExists<MappingTestsParentWithSimpleNullAndNullArrayList>())
         {
             context.AllowDeleteForIndex = true;
             var entityResult8 = context.DeleteIndexAsync<MappingTestsParentWithSimpleNullAndNullArrayList>();
             entityResult8.Wait();
         }
     }
 }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:53,代码来源:MappingTests.cs

示例14: FixtureTearDown

 public void FixtureTearDown()
 {
     using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
     {
         context.AllowDeleteForIndex = true;
         var entityResult = context.DeleteIndexAsync<ParentDocumentUserDefinedRouting>();
         entityResult.Wait();
     }
 }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:9,代码来源:OneToNEntitiesSaveWithChildDocumentsTestWithRouting.cs


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