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


C# ElasticsearchContext.DeleteDocument方法代码示例

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


在下文中一共展示了ElasticsearchContext.DeleteDocument方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestDefaultContextDeleteEntity

        public void TestDefaultContextDeleteEntity()
        {
            const int entityId = 35;
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(_entitiesForTests[entityId], entityId);

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

                // Get the entity
                var entityResult = context.GetDocumentAsync<SkillTestEntity>(entityId);
                Assert.AreEqual(entityResult.Result.Status, HttpStatusCode.OK);
                Assert.AreEqual(entityResult.Result.PayloadResult.Id, entityId);
                Assert.IsNotNull(entityResult.Result.PayloadResult);

                // Delete the entity
                context.DeleteDocument<SkillTestEntity>(entityId);
                var result = context.SaveChanges();
                Assert.AreEqual(result.Status, HttpStatusCode.OK);
                Assert.AreEqual(entityResult.Result.Status, HttpStatusCode.OK);
                Assert.AreEqual(entityResult.Result.PayloadResult.Id, entityId);
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:26,代码来源:DefaultElasticsearchCRUDTests.cs

示例3: TestDefaultContextDeleteEntityWhichDoesNotExist

        public void TestDefaultContextDeleteEntityWhichDoesNotExist()
        {
            using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                // Delete the entity
                context.DeleteDocument<SkillTestEntity>(6433);
                context.DeleteDocument<SkillTestEntity>(22222);

                var task = Task.Run(() => context.SaveChangesAsync());

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

                    ae.Handle(x =>
                    {
                        if (x is ElasticsearchCrudException) // This is what we expect.
                        {
                            throw x;
                        }
                        return false; // stop.
                    });
                }
            }
        }
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:29,代码来源:DefaultElasticsearchCRUDTests.cs

示例4: TestAddUpdateWithExistingMappingsTest

        public void TestAddUpdateWithExistingMappingsTest()
        {
            var parentDocument2 = ParentDocument2();

            using (var context = new ElasticsearchContext(ConnectionString,
                new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent,
                    ProcessChildDocumentsAsSeparateChildIndex, UserDefinedRouting)))
            {
                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(parentDocument2, parentDocument2.Id);

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

                Thread.Sleep(1500);

                var roundTripResult = context.GetDocument<ParentDocumentUserDefinedRouting>(parentDocument2.Id);
                var roundTripResultChildDocumentLevelOne =
                    context.GetDocument<ChildDocumentLevelOneUserDefinedRouting>(parentDocument2.ChildDocumentLevelOne.First().Id,
                        new RoutingDefinition {ParentId = parentDocument2.Id, RoutingId = parentDocument2.Id});

                var roundTripResultChildDocumentLevelTwo =
                    context.GetDocument<ChildDocumentLevelTwoUserDefinedRouting>(
                        parentDocument2.ChildDocumentLevelOne.First().ChildDocumentLevelTwo.Id,
                        new RoutingDefinition
                        {
                            ParentId = parentDocument2.ChildDocumentLevelOne.First().Id,
                            RoutingId = parentDocument2.Id
                        });

                Assert.AreEqual(parentDocument2.Id, roundTripResult.Id);
                Assert.AreEqual(parentDocument2.ChildDocumentLevelOne.First().Id, roundTripResultChildDocumentLevelOne.Id);
                Assert.AreEqual(parentDocument2.ChildDocumentLevelOne.First().ChildDocumentLevelTwo.Id,
                    roundTripResultChildDocumentLevelTwo.Id);

                var childDocs =
                    context.Search<ChildDocumentLevelTwoUserDefinedRouting>(
                        BuildSearchForChildDocumentsWithIdAndParentType(parentDocument2.ChildDocumentLevelOne.FirstOrDefault().Id,
                            "childdocumentleveloneuserdefinedrouting"));
                var childDocs2 =
                    context.Search<ChildDocumentLevelOneUserDefinedRouting>(
                        BuildSearchForChildDocumentsWithIdAndParentType(parentDocument2.Id, "parentdocumentuserdefinedrouting"));
                var childDocs3 =
                    context.Search<ChildDocumentLevelTwoUserDefinedRouting>(BuildSearchForChildDocumentsWithIdAndParentType(22,
                        "childdocumentleveloneuserdefinedrouting"));

                Assert.AreEqual(1, childDocs.PayloadResult.Hits.Total);
                Assert.AreEqual(2, childDocs2.PayloadResult.Hits.Total);
                Assert.AreEqual(4, childDocs3.PayloadResult.Hits.Total);

                context.DeleteDocument<ChildDocumentLevelTwoUserDefinedRouting>(73, new RoutingDefinition { ParentId = 22, RoutingId = 7 });
                context.DeleteDocument<ChildDocumentLevelTwoUserDefinedRouting>(72);
                context.SaveChanges();

                Thread.Sleep(1000);

                childDocs3 =
                    context.Search<ChildDocumentLevelTwoUserDefinedRouting>(BuildSearchForChildDocumentsWithIdAndParentType(22,
                        "childdocumentleveloneuserdefinedrouting"));

                Assert.AreEqual(2, childDocs3.PayloadResult.Hits.Total);

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


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