Esempio n. 1
0
 private static IEnumerable <Func <object> > DocumentCommands(IElasticClient elastic)
 {
     return(new List <Func <object> >
     {
         () => elastic.Bulk(
             new BulkRequest("test_index")
         {
             Operations = new List <IBulkOperation>
             {
                 new BulkCreateOperation <Post>(new Post {
                     Id = 1, Title = "BulkCreateOperation"
                 })
             }
         }),
         () => elastic.Create(new CreateRequest <Post>(new Post {
             Id = 2, Title = "CreateRequest"
         }, "test_index")),
         () => elastic.CreateDocument(new Post {
             Id = 3, Title = "CreateDocument"
         }),
         () => elastic.Count <Post>(),
         () => elastic.Search <Post>(s => s.MatchAll()),
         () => elastic.DeleteByQuery(new DeleteByQueryRequest("test_index")
         {
             Size = 0
         })
     });
 }
Esempio n. 2
0
 public void DeleteByQuery(string indexName)
 {
     //1.x中有 2.x中需要安装插件 5.x中又回来了
     //todo:5.x 不安装插件 少了前两个参数(indexName,type)
     var response = _client.DeleteByQuery <TestModel5>(
         s => s
         .Index(indexName)
         .Query(q => q.Term(tm => tm.Field(fd => fd.State).Value(1))));
 }
Esempio n. 3
0
 public void DeleteByQuery(string indexName)
 {
     //1.x中有 2.x中需要安装插件 5.x中又回来了
     //todo:2.x 需要安装插件 前面两个参数必须传递
     _client.DeleteByQuery <TestModel2>(indexName, typeof(TestModel2),
                                        s => s
                                        //.Index(indexName)
                                        //.Type("TestModel2")
                                        .Query(q => q.Term(tm => tm.Field(fd => fd.State).Value(1))));
 }
Esempio n. 4
0
        /// <summary>
        /// 通过条件删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="client"></param>
        /// <param name="indexName"></param>
        /// <param name="where"></param>
        public static void DeleteByQuery_ <T>(this IElasticClient client, string indexName, QueryContainer where) where T : class, IElasticSearchIndex
        {
            var query = new DeleteByQueryRequest <T>(indexName)
            {
                Query = where
            };

            var response = client.DeleteByQuery(query);

            response.ThrowIfException();
        }
        public async Task Remove(Guid id)
        {
            var type  = typeof(T);
            var index = type.Name.ToLowerInvariant();

            var x2 = _cliente.DeleteByQuery <T>(i => i.Index(index)
                                                .Query(rq => rq
                                                       .QueryString(qs => qs

                                                                    .Query(id + "")))

                                                );
        }
        public void DeleteMovie(string payload)
        {
            MovieDeactivatedEvent movieDeactivatedEvent = JsonConvert.DeserializeObject <MovieDeactivatedEvent>(payload);

            _elasticClient.DeleteByQuery <Movie>(q => q
                                                 .Query(rq => rq
                                                        .Match(m => m
                                                               .Field(f => f.MovieId)
                                                               .Query(movieDeactivatedEvent.MovieId.ToString()))
                                                        )
                                                 .Index("movies")
                                                 );
        }
Esempio n. 7
0
 public void Remove(string id)
 {
     if (!string.IsNullOrEmpty(id))
     {
         _elasticClient.DeleteByQuery <Subscriber>(s => s
                                                   .Index("subscriptions")
                                                   .Query(q => q
                                                          .Bool(b => b
                                                                .Must(m => m
                                                                      .MatchPhrase(t => t
                                                                                   .Field(f => f.Id)
                                                                                   .Query(id))))));
     }
 }
Esempio n. 8
0
        protected override void OnBeforeCall(IElasticClient client)
        {
            client.IndexMany(Project.Projects, CallIsolatedValue);
            client.Indices.Refresh(CallIsolatedValue);

            var deleteByQuery = client.DeleteByQuery <Project>(u => u
                                                               .Index(CallIsolatedValue)
                                                               .Conflicts(Conflicts.Proceed)
                                                               .Query(q => q.MatchAll())
                                                               .Refresh()
                                                               .RequestsPerSecond(1)
                                                               .WaitForCompletion(false)
                                                               );

            deleteByQuery.ShouldBeValid();
            ExtendedValue(TaskIdKey, deleteByQuery.Task);
        }
Esempio n. 9
0
        public async Task AddManyAsync(GlobalSearchModel[] globalSearch)
        {
            _elasticClient.DeleteByQuery <GlobalSearchModel>(del => del
                                                             .Index(indexGlobalSearch).Query(q => q.QueryString(qs => qs.Query("*")))
                                                             );
            var result = await _elasticClient.IndexManyAsync(globalSearch, indexGlobalSearch);

            if (result.Errors)
            {
                // the response can be inspected for errors
                foreach (var itemWithError in result.ItemsWithErrors)
                {
                    _logger.LogError("Failed to index document {0}: {1}",
                                     itemWithError.Id, itemWithError.Error);
                }
                throw new Exception();
            }
        }
Esempio n. 10
0
        public virtual int PerformDelete(IElasticClient client, params Guid[] guidsToDelete)
        {
            if (guidsToDelete.Any())
            {
                var idsToDelete = guidsToDelete.Select(s => new Id(s.ToString())).ToList();

                var deleteResponse = client.DeleteByQuery(new DeleteByQueryRequest(Name)
                {
                    Query = new IdsQuery()
                    {
                        Values = idsToDelete
                    }
                });

                return((int)deleteResponse.Deleted);
            }

            return(0);
        }
 protected override IDeleteByQueryResponse ExecuteCore(IElasticClient client, string index)
 {
     return(client.DeleteByQuery <T>(desc => BuildQuery(desc).Index(index)));
 }
Esempio n. 12
0
 public void RemoveAllEvents()
 {
     _client.DeleteByQuery <PersistentEvent>(c => c.Type(typeof(PersistentEvent)).Query(q => q.MatchAll()));
 }
Esempio n. 13
0
 private static void DeleteEmployeesByQueryFavoriteNumbers(int favoriteNumber)
 {
     esClient.DeleteByQuery <Employee>(q => q.Index("employees").Type("employee").Term(e => e.FavoriteNumbers, favoriteNumber.ToString()));
     Log(string.Format("Deleted employees whose favorite numbers include {0}", favoriteNumber));
 }
Esempio n. 14
0
        private void DeleteExpiredCacheItems()
        {
            var utcNow = _systemClock.UtcNow;

            _client.DeleteByQuery <CacheItem>(q => q.Query(rq => rq.DateRange(dr => dr.LessThan(utcNow.UtcDateTime))));
        }
        public DeleteByQueryResponse DeleteByQuery <T>(string indexName, Func <TermQueryDescriptor <T>, ITermQuery> selector) where T : class
        {
            DeleteByQueryResponse deleteByQueryResponse = elasticClient.DeleteByQuery <T>(s => s.Index(indexName.ToLower()).Query(q => q.Term(selector)));

            return(deleteByQueryResponse);
        }