public async Task DeleteAllAsync() { await _elasticClient.DeleteByQueryAsync <GlobalSearchModel>(del => del .Index(indexGlobalSearch).Query(q => q.QueryString(qs => qs.Query("*")))); await _elasticClient.DeleteByQueryAsync <PhotoArchive>(del => del .Index(indexPhotoArchive).Query(q => q.QueryString(qs => qs.Query("*")))); await _elasticClient.DeleteByQueryAsync <PageNews>(del => del .Index(indexPageNews).Query(q => q.QueryString(qs => qs.Query("*")))); }
public async Task DeleteOrphanedEventsByStackAsync(JobContext context) { // get approximate number of unique stack ids var stackCardinality = await _elasticClient.SearchAsync <PersistentEvent>(s => s.Aggregations(a => a .Cardinality("cardinality_stack_id", c => c.Field(f => f.StackId).PrecisionThreshold(40000)))); var uniqueStackIdCount = stackCardinality.Aggregations.Cardinality("cardinality_stack_id")?.Value; if (!uniqueStackIdCount.HasValue || uniqueStackIdCount.Value <= 0) { return; } // break into batches of 500 const int batchSize = 500; int buckets = (int)uniqueStackIdCount.Value / batchSize; buckets = Math.Max(1, buckets); int totalOrphanedEventCount = 0; int totalStackIds = 0; for (int batchNumber = 0; batchNumber < buckets; batchNumber++) { await RenewLockAsync(context); var stackIdTerms = await _elasticClient.SearchAsync <PersistentEvent>(s => s.Aggregations(a => a .Terms("terms_stack_id", c => c.Field(f => f.StackId).Include(batchNumber, buckets).Size(batchSize * 2)))); var stackIds = stackIdTerms.Aggregations.Terms("terms_stack_id").Buckets.Select(b => b.Key).ToArray(); if (stackIds.Length == 0) { continue; } totalStackIds += stackIds.Length; var stacks = await _elasticClient.MultiGetAsync(r => r.SourceEnabled(false).GetMany <Stack>(stackIds)); var missingStackIds = stacks.Hits.Where(h => !h.Found).Select(h => h.Id).ToArray(); if (missingStackIds.Length == 0) { _logger.LogInformation("{BatchNumber}/{BatchCount}: Did not find any missing stacks out of {StackIdCount}", batchNumber, buckets, stackIds.Length); continue; } totalOrphanedEventCount += missingStackIds.Length; _logger.LogInformation("{BatchNumber}/{BatchCount}: Found {OrphanedEventCount} orphaned events from missing stacks {MissingStackIds} out of {StackIdCount}", batchNumber, buckets, missingStackIds.Length, missingStackIds, stackIds.Length); await _elasticClient.DeleteByQueryAsync <PersistentEvent>(r => r.Query(q => q.Terms(t => t.Field(f => f.StackId).Terms(missingStackIds)))); } _logger.LogInformation("Found {OrphanedEventCount} orphaned events from missing stacks out of {StackIdCount}", totalOrphanedEventCount, totalStackIds); }
public async Task DeleteSchemaRecordsForOwnerAsync(string ownerId) { var deleteResponse = await _client.DeleteByQueryAsync <SchemaInfo>(s => s.Query(q => QueryByOwnerId(q, ownerId))); if (!deleteResponse.IsValid) { throw new SchemaStoreException( $"Failed to delete schema record for all schemas owned by {ownerId}"); } await _client.RefreshAsync(Indices.Index <SchemaInfo>()); }
public async Task ReIndex() { await elasticClient.DeleteByQueryAsync <ProductViewModel>(q => q.Index(defaultIndex).MatchAll()); var products = productRepository.GetAll().ToArray(); foreach (var product in products) { await elasticClient.IndexAsync(product, d => d.Index(defaultIndex).Id(product.ProductCode)); } }
public async Task <BaseResponse> DeleteLocation(string locationID) { var location = GetLocationByID(locationID); try { var response = await _elasticClient.DeleteByQueryAsync <Location>(s => s .Query(q => q.Term(f => f.ID.Suffix("keyword"), locationID) ) ); if (!response.IsValid) { return(new ErrorResponse(ConstMessages.QueryFailedCode, ConstMessages.QueryFailedMsg)); } else { _webhookSender.WebhookStorage(Resources.Delete, location); return(new SuccessResponse(ConstMessages.DeleteSuccess)); } } catch (Exception ex) { return(new ErrorResponse(ConstMessages.UnidentifiedErrorCode, ex.ToString())); } }
public async Task <int> ReIndex() { await _elasticClient.DeleteByQueryAsync <StudentDataTransfer>(q => q.MatchAll()); var allStudents = await _context.Set <Student>().Select(e => new StudentDataTransfer { FirstName = e.FirstName, LastName = e.LastName, GraduationYear = e.GraduationYear, Phone = e.Phone, StudentId = e.StudentId, UniversityName = e.UniversityName, }).ToArrayAsync(); var res = await _elasticClient.IndexManyAsync(allStudents); if (res.Errors) { foreach (var itemWithError in res.ItemsWithErrors) { _logger.LogError(itemWithError.Error.ToString(), itemWithError.Id); } return(-1); } return(allStudents.Count()); }
private static IEnumerable <Func <object> > DocumentCommandsAsync(IElasticClient elastic) { return(new List <Func <object> > { () => elastic.BulkAsync( new BulkRequest("test_index") { Operations = new List <IBulkOperation> { new BulkCreateOperation <Post>(new Post { Id = 1, Title = "BulkCreateOperation" }) } }), () => elastic.CreateAsync(new CreateRequest <Post>(new Post { Id = 2, Title = "CreateRequest" }, "test_index")), () => elastic.CreateDocumentAsync(new Post { Id = 3, Title = "CreateDocument" }), () => elastic.CountAsync <Post>(), () => elastic.SearchAsync <Post>(s => s.MatchAll()), () => elastic.DeleteByQueryAsync(new DeleteByQueryRequest("test_index") { Size = 0 }) }); }
/// <summary> /// Deletes an article by its id. /// </summary> /// <param name="client">The client to use.</param> /// <param name="index">The index to use.</param> /// <param name="articleId">The article id to delete.</param> private static void DeleteByIdAsync(IElasticClient client, string index, string articleId) { client.DeleteByQueryAsync <Article>(descriptor => descriptor.Index(index) .Refresh() .Query(q => q.MatchPhrase(m => m .Field(f => f.Id) .Query(articleId)))); }
public async Task ReIndex(List <TDocument> documents) { await _elasticClient.DeleteByQueryAsync <TDocument>(q => q.MatchAll()); foreach (var doc in documents) { await _elasticClient.IndexDocumentAsync(doc); } }
public Task DeleteExternalPoisBySource(string source) { return(_elasticClient.DeleteByQueryAsync <Feature>(d => d.Index(EXTERNAL_POIS) .Query(q => q.Term(t => t.Field($"{PROPERTIES}.{FeatureAttributes.POI_SOURCE}").Value(source.ToLower())) ) )); }
/// <summary> /// 通过条件删除 /// </summary> public static async Task <DeleteByQueryResponse> DeleteByQueryAsync_ <T>(this IElasticClient client, string indexName, QueryContainer where) where T : class, IESIndex { var query = new DeleteByQueryRequest <T>(indexName) { Query = where }; var response = await client.DeleteByQueryAsync(query); return(response); }
public async Task <IActionResult> ReIndex() { await _elasticClient.DeleteByQueryAsync <AutoPostSearchDTO>(q => q.MatchAll()); IEnumerable <AutoPost> allPosts = await _postService.Get <AutoPost>(); IEnumerable <AutoPostSearchDTO> postsToIndex = _mapper.Map <IEnumerable <AutoPost>, IEnumerable <AutoPostSearchDTO> >(allPosts); await _elasticClient.IndexManyAsync(postsToIndex); return(Ok($"{postsToIndex.Count()} post(s) reindexed")); }
public async Task <bool> DeleteJobsForOwnerAsync(string ownerId) { var deleteResponse = await _client.DeleteByQueryAsync <JobInfo>(s => s.Query(q => QueryByOwnerId(ownerId))); if (!deleteResponse.IsValid) { throw new JobStoreException( $"Failed to delete all jobs owned by {ownerId}"); } return(true); }
/// <summary> /// 通过条件删除 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="client"></param> /// <param name="indexName"></param> /// <param name="where"></param> /// <returns></returns> public static async Task DeleteByQueryAsync_ <T>(this IElasticClient client, string indexName, QueryContainer where) where T : class, IElasticSearchIndex { var query = new DeleteByQueryRequest <T>(indexName) { Query = where }; var response = await client.DeleteByQueryAsync(query); response.ThrowIfException(); }
public async Task <DeleteByQueryResponse> RemoveOldMessages(int days) { var response = await elasticClient.DeleteByQueryAsync <ChatMessage>(_ => _.Query(q => q .DateRange(r => r .Field(f => f.PostedTime) .LessThanOrEquals(DateTime.UtcNow.AddDays(-days)) ) )); return(response); }
public Task DeleteAllAsync( CancellationToken cancellationToken) { var readModelDescription = _readModelDescriptionProvider.GetReadModelDescription <TReadModel>(); _log.Information($"Deleting ALL '{typeof(TReadModel).PrettyPrint()}' read models from index '{readModelDescription.IndexName}'"); return(_elasticClient.DeleteByQueryAsync <TReadModel>(d => d .Index(readModelDescription.IndexName.Value) .Type <TReadModel>() .Query(q => q.MatchAll()))); }
public async Task <IActionResult> ReIndex() { await _elasticClient.DeleteByQueryAsync <Product>(q => q.MatchAll()); var allProducts = (await _productService.GetProducts(int.MaxValue)).ToArray(); foreach (var product in allProducts) { await _elasticClient.IndexDocumentAsync(product); } return(Ok($"{allProducts.Length} product(s) reindexed")); }
public static Task <IDeleteByQueryResponse> DeleteByQueryAsync <TDocument>( this IElasticClient client, Func <DeleteByQueryDescriptor <TDocument>, DeleteByQueryDescriptor <TDocument> > selector, CancellationToken cancellationToken = default(CancellationToken), string indexSuffix = null) where TDocument : class { var index = GetIndex <TDocument>(indexSuffix); return(client.DeleteByQueryAsync <TDocument>( s => selector(s.Index(index)), cancellationToken)); }
public async Task <IActionResult> ReIndex() { await elasticClient.DeleteByQueryAsync <News>(q => q.MatchAll()); var allNews = await context.News.ToListAsync(); foreach (var news in allNews) { await elasticClient.IndexDocumentAsync(news); } return(Ok($"{allNews.Count} news reindexed")); }
public async Task <bool> Remove(Guid entryId) { var request = new DeleteByQueryRequest <T>(_Index) { Query = new TermQuery() { Field = "_id", Value = entryId.ToString(), IsStrict = true } }; var response = await _Client.DeleteByQueryAsync(request); return(response.Took > 0); }
public async Task <int> ReindexAll() { await _elasticClient.DeleteByQueryAsync <SearchGoods>(q => q.MatchAll()); var allGoods = await FindAll(); foreach (var item in allGoods) { // 키워드 검색대상 추가 item.terms = $"{item.nameKr} {item.category1} {item.category2} {item.category3} {item.terms}"; await _elasticClient.IndexDocumentAsync(item); } return(allGoods.Count); }
public async Task RemoveDocumentsFromFolder(FolderIdentity folderId, CancellationToken cancellationToken) { if (folderId == null) { throw new ArgumentNullException(nameof(folderId)); } var response = await elasticClient.DeleteByQueryAsync <DocumentInfoModel>(dbqd => dbqd .Index(options.IndexName) .Query(qcd => qcd .Term("parentFoldersPath", folderId.ToString())), CancellationToken.None); CheckResponse(response, $"Error occured during removing items from folder {folderId}"); }
public async Task <DeleteByQueryResponse> DeleteByQuery <T>(Expression <Func <T, bool> > expression, string index = "") where T : class, new() { var indexName = index.GetIndex <T>(); var request = new DeleteByQueryRequest <T>(indexName); var build = new QueryBuilder <T>(); request.Query = build.GetQueryContainer(expression); var response = await _elasticClient.DeleteByQueryAsync(request); if (!response.IsValid) { throw new Exception("删除失败:" + response.OriginalException.Message); } return(response); }
public async Task <bool> DeleteDatasetsForOwnerAsync(string ownerId) { if (ownerId == null) { throw new ArgumentNullException(nameof(ownerId)); } var deleteResponse = await _client.DeleteByQueryAsync <DatasetInfo>(s => s.Query(q => QueryHelper.FilterByOwnerId(ownerId))); if (!deleteResponse.IsValid) { throw new DatasetStoreException( $"Failed to delete all datasets owned by {ownerId}"); } await _client.RefreshAsync(Indices.Index <DatasetInfo>()); return(true); }
public async Task <IActionResult> DelDoc([FromForm] int id) { //判断文档是否存在,这里是根据索引名字(数据库),索引type(表),和该文档的id来判断的(主键) IExistsResponse existsResponse = await _esClient.DocumentExistsAsync(new DocumentExistsRequest("users", "appuser", id)); if (existsResponse.Exists) { //删除对应id的文档 var res = await _esClient.DeleteByQueryAsync <AppUser>(d => { return(d.Index("users").Type("appuser").Query(q => q.Term(tm => tm.Field(new Field("id")).Value(id)))); }); if (res.IsValid) { return(Ok()); } return(BadRequest()); } return(NoContent()); }
public async Task <IActionResult> Delete(string id, [FromServices] IElasticClient elasticClient) { var result = await elasticClient.GetAsync <Log>(id); if (result.Source == null) { return(NotFound()); } var request = new DeleteByQueryRequest <Log> { Query = new QueryContainer(new TermQuery { Field = "id", Value = id }) }; await elasticClient.DeleteByQueryAsync(request); return(Ok()); }
protected override Task <IDeleteResponse> ExecuteCoreAsync(IElasticClient client, string index) { return(client.DeleteByQueryAsync <T>(desc => BuildQuery(desc).Index(index))); }
public Task DeleteAllActivitiesFromRepoAsync() { return(_client.DeleteByQueryAsync <Activity>(del => del .Query(q => q.QueryString(qs => qs.Query("*"))))); }
protected override async Task <IDeleteByQueryResponse> ExecuteCoreAsync(IElasticClient client, string index) { return(await client.DeleteByQueryAsync <T>(desc => BuildQuery(desc).Index(index)).ConfigureAwait(false)); }
public async Task DeleteAllAsync() { await _elasticClient.DeleteByQueryAsync <T>(del => del.Query(q => q.QueryString(qs => qs.Query("*")))); }