public async Task <bool> DeleteUserSettingsAsync(string userId) { var response = await _client.DeleteAsync <UserSettings>(userId); await _client.RefreshAsync(Indices.Index <UserSettings>()); return(response.IsValid); }
/// <summary> ///The delete API allows to delete a typed JSON document from a specific index based on its id. /// <para> </para>>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete.html /// </summary> /// <typeparam name="T">The type used to infer the default index and typename</typeparam> /// <param name="client"></param> /// <param name="index">The name of the index as string</param> /// <param name="type">The type name of the document you wish to delete</param> /// <param name="id">The id as string of the document you want to delete</param> /// <param name="selector">An optional descriptor to further describe the delete operation</param> public static Task <IDeleteResponse> DeleteAsync(this IElasticClient client, string index, string type, string id, Func <DeleteDescriptor <object>, DeleteDescriptor <object> > selector = null) { selector = selector ?? (s => s); return(client.DeleteAsync <object>(s => selector(s.Index(index).Type(type).Id(id)))); }
public override async Task TeardownAsync(IElasticClient client, ColoredConsoleWriter output) { var deleteResponse = await client.DeleteAsync<Developer>(_developer, d => d.Index<Developer>()).ConfigureAwait(false); if (!deleteResponse.IsValid) output.WriteOrange($"error with id {deleteResponse.Id}. message: {deleteResponse.CallDetails.OriginalException}"); }
private async Task <Response> DeleteEntityFromPathAsync <TEntity>(DocumentPath <TEntity> documentPath) where TEntity : class { var result = new Response(); var indexName = ElasticSearchExtensions.GetIndexNameFrom <TEntity>(); var existsResponse = await _elasticClient.Indices.ExistsAsync(indexName) .ConfigureAwait(false); if (!existsResponse.Exists) { throw new InvalidOperationException($"Index {indexName} does not exist"); } var documentExistsResponse = await _elasticClient.DocumentExistsAsync(documentPath, d => d.Index(indexName)) .ConfigureAwait(false); if (!documentExistsResponse.Exists) { return(result); } var deleteResponse = await _elasticClient.DeleteAsync(documentPath, d => d.Index(indexName)) .ConfigureAwait(false); if (deleteResponse.IsValid) { return(result); } result.IsOk = false; result.ErrorMessage = deleteResponse.OriginalException.Message; result.Exception = deleteResponse.OriginalException; return(result); }
public async Task <DataAccessResponse <string> > Remove(string id) { DataAccessResponse <string> response = new DataAccessResponse <string>(); if (id == null) { return(response.NotFound()); } IDeleteResponse deleteResponse = await _esClient.DeleteAsync <Friend>(id); if (deleteResponse.Result == Result.NotFound) { return(response.NotFound()); } if (!deleteResponse.IsValid) { return(response.InternalServerError()); } if (deleteResponse.Id == null) { return(response.InternalServerError()); } return(response.NoContent(deleteResponse.Id)); }
public async Task Consume(ConsumeContext <DeleteEntityCategories> context) { var result = _elasticClient.Search <dynamic>(s => s .Index("categories") .Type("category") .Query(q => q.QueryString(qs => qs.Query(context.Message.EntityId.ToString())))); foreach (var hit in result.Hits) { JObject hitObject = JsonConvert.DeserializeObject <JObject>(hit.Source.ToString()); IEnumerable <string> categoriesIds = hitObject.Value <JArray>("CategoriesIds").Select(x => x.ToString()); categoriesIds = categoriesIds.Where(x => !context.Message.CategoriesIds.Select(z => z.ToString()).Contains(x)); if (categoriesIds.Any()) { var indexDocument = new { CategoriesIds = categoriesIds.Distinct() }; await _elasticClient.UpdateAsync <dynamic>(hit.Id, i => i.Doc(indexDocument).Index("categories").Type("category")); } else { await _elasticClient.DeleteAsync(new DeleteRequest("categories", "category", hit.Id)); } } }
/// <summary> ///The delete API allows to delete a typed JSON document from a specific index based on its id. /// <para> </para>>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete.html /// </summary> /// <typeparam name="T">The type used to infer the default index and typename</typeparam> /// <param name="client"></param> /// <param name="obj">The object used to infer the id</param> /// <param name="selector">An optional descriptor to further describe the delete operation</param> public static Task <IDeleteResponse> DeleteAsync <T>(this IElasticClient client, T obj, Func <DeleteDescriptor <T>, DeleteDescriptor <T> > selector = null) where T : class { obj.ThrowIfNull("obj"); var id = client.Infer.Id(obj); selector = selector ?? (s => s); return(client.DeleteAsync <T>(s => selector(s.Id(id)))); }
public async Task <DeleteResult> RemoveMovie(string id) { await _elasticClient.DeleteAsync <Movie>(id); //Cheesy shit cause I can't figure out how to make sure the move that was just deleted doesn't show on the index page when it reloads Thread.Sleep(2000); return(await _context.Movies.DeleteOneAsync(Builders <Movie> .Filter.Eq("Id", id))); }
public async Task DeleteAsync(Product product) { await _elasticClient.DeleteAsync <Product>(product); if (_cache.Contains(product)) { _cache.Remove(product); } }
public async Task RemoveItem <T>(long itemId) where T : class, IEntity { var itemresponse = await _elasticClient.DeleteAsync(new DeleteRequest(_indexName, typeof(T), itemId)); await _elasticClient.RefreshAsync(new RefreshRequest(_indexName)); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(itemresponse.DebugInformation); }
public async Task RemoveBook(Guid id) { var response = await _client.DeleteAsync <Book>(id, i => i.Index(IndexName)); if (!response.IsValid) { throw response.OriginalException; } }
public override async Task TeardownAsync(IElasticClient client, ColoredConsoleWriter output) { var deleteResponse = await client.DeleteAsync <Developer>(_developer, d => d.Index <Developer>()).ConfigureAwait(false); if (!deleteResponse.IsValid) { output.WriteOrange($"error with id {deleteResponse.Id}. message: {deleteResponse.ApiCall.OriginalException}"); } }
public async Task DeleteAsync(Address address) { await _elasticClient.DeleteAsync <Address>(address); if (_cache.Contains(address)) { _cache.Remove(address); } }
/// <summary> /// Delete Document /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="indexName"></param> /// <param name="model"></param> /// <returns></returns> public virtual async Task DeleteAsync <T, TKey>(string indexName, T model) where T : class { var response = await _esClient.DeleteAsync(new DeleteRequest(indexName, new Id(model))); if (response.ServerError == null) { return; } throw new Exception($"Delete Document at index {indexName} :{response.ServerError.Error.Reason}"); }
public async Task <bool> DeleteAsync(int Id) { bool result = true; var response = await elasticClient.DeleteAsync <CatalogItem>(Id); if (!response.IsValid) { result = false; } return(result); }
public async Task RemoveDocument <T>(int id) where T : class { var isIndexExist = await IsIndexExists(Indexes.Entities); if (!isIndexExist) { await CreateIndex(Indexes.Entities); } await _elasticClient.DeleteAsync <T>(id, i => i.Index(Indexes.Entities)); }
public async Task Deletar(Schools schools) { string filePath = Path.GetDirectoryName("data"); if (File.Exists(filePath)) { File.Delete(filePath); } await _elasticClient.DeleteAsync <Schools>(schools); }
private async Task CommitDeleteAsync <TEntity>(TEntity entity, IDocumentInfo docInfo, object id) where TEntity : class { await _elasticClient.DeleteAsync(DocumentPath <TEntity> .Id(Convert.ToString(id)), d => d.Index(docInfo.Index) .Type(docInfo.Type)); if (docInfo.RefeshAfterDeleted) { await _elasticClient.RefreshAsync(docInfo.Index); } }
public async Task <DeleteResponse> DeleteAsync(string documentId, CancellationToken cancellationToken) { var deleteResponse = await client.DeleteAsync <ElasticsearchDocument>(documentId, x => x.Index(indexName), cancellationToken); if (logger.IsDebugEnabled()) { logger.LogDebug($"DeleteResponse DebugInformation: {deleteResponse.DebugInformation}"); } return(deleteResponse); }
public async Task <bool> DeleteOwnerSettingsAsync(string ownerId) { if (ownerId == null) { throw new ArgumentNullException(nameof(ownerId)); } var response = await _client.DeleteAsync <OwnerSettings>(ownerId); await _client.RefreshAsync(Indices.Index <OwnerSettings>()); return(response.IsValid); }
public static async Task <IDeleteResponse> DeleteAsync <T>( this IElasticClient client, string id, string routing = null, string indexName = null) where T : class { indexName = indexName ?? client.ConnectionSettings.DefaultIndex; routing = routing ?? id; return(await client.DeleteAsync <T>(id, deleteDescriptor => deleteDescriptor.Routing(routing).Index(indexName))); }
public async Task RemoveAsync(string key, CancellationToken token = default(CancellationToken)) { if (key == null) { throw new ArgumentNullException(nameof(key)); } token.ThrowIfCancellationRequested(); await _client.DeleteAsync <CacheItem>(key); ScanForExpiredItemsIfRequired(); }
public async Task <bool> DeleteAsync(string key, CancellationToken cancellationToken = default) { if (key == null) { throw new ArgumentNullException(nameof(key)); } var result = await ElasticClient.DeleteAsync <T>(key, d => d.Index(Mapping.Index), cancellationToken); return(result.IsValid); }
public async Task DeleteAsync( string id, CancellationToken cancellationToken) { var readModelDescription = _readModelDescriptionProvider.GetReadModelDescription <TReadModel>(); await _elasticClient.DeleteAsync( new DocumentPath <TReadModel>(id), d => d .Index(readModelDescription.IndexName.Value) .RequestConfiguration(c => c .AllowedStatusCodes((int)HttpStatusCode.NotFound)), cancellationToken) .ConfigureAwait(false); }
public async Task DeletePost(Post post) { string filePath = GetFilePath(post); if (File.Exists(filePath)) { File.Delete(filePath); } await _elasticClient.DeleteAsync <Post>(post); if (_cache.Contains(post)) { _cache.Remove(post); } }
public async Task <DeleteAuthorQueryResult> Handle(DeleteAuthorQuery request, CancellationToken cancellationToken) { var response = await _elasticClient.DeleteAsync <Author>(new DocumentPath <Author>(new Id(request.DocumentId)) .Index(Constants.Constants.IndexNameAuthor)); switch (response.Result) { case Result.Deleted: return(new DeleteAuthorQueryResult(QueryResult.Success)); case Result.NotFound: return(new DeleteAuthorQueryResult(QueryResult.NotFound)); default: return(new DeleteAuthorQueryResult(QueryResult.Failure)); } }
public async Task <TEntity> Delete(TEntity entity, CancellationToken cancellationToken = default) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var result = entity.Id switch { string stringId => await elasticClient.DeleteAsync <TEntity>(stringId, ct : cancellationToken), long longId => await elasticClient.DeleteAsync <TEntity>(longId, ct : cancellationToken), int intId => await elasticClient.DeleteAsync <TEntity>(intId, ct : cancellationToken), Guid guidId => await elasticClient.DeleteAsync <TEntity>(guidId, ct : cancellationToken), _ => throw new ArgumentOutOfRangeException(nameof(entity.Id), $"{nameof(entity.Id)} has to be of type string, int, long or Guid") }; return(entity); }
public async Task <BookModelExtended> DeleteBook(int id) { var book = await context.Books.FindAsync(id); if (book == null) { throw new EntityNotFoundException($"Could not delete a book. Book with id {id} doesn't exist."); } var deletedBook = await GetExtendedBookModel(book); context.Books.Remove(book); await context.SaveChangesAsync(); await elasticClient.DeleteAsync <Book>(book); return(deletedBook); }
public async Task <bool> DeleteRepoSettingsAsync(string ownerId, string repositoryId) { if (ownerId == null) { throw new ArgumentNullException(nameof(ownerId)); } if (repositoryId == null) { throw new ArgumentNullException(nameof(repositoryId)); } var documentId = $"{ownerId}/{repositoryId}"; var response = await _client.DeleteAsync <RepoSettings>(documentId); await _client.RefreshAsync(Indices.Index <RepoSettings>()); return(response.IsValid); }
public async Task <IActionResult> DeleteByID() { try { var companyData = new Company() { Name = "Test dummy" }; var indexResponse = await _elasticClient.IndexAsync(companyData, i => i.Index(IndexName)); var queryResponse = await _elasticClient.DeleteAsync(new Nest.DeleteRequest(IndexName, indexResponse.Id)); if (queryResponse.IsValid) { return(Ok(queryResponse.Result)); } return(BadRequest(queryResponse.ServerError.Error)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Delete(int employeeId) { try { // Search for the document using the employeeId field. var searchResponse = await _elasticClient.SearchAsync <Employee>(s => s .Index(_appConfig.Elasticsearch.IndexName) .From(0) .Size(10) .Query(q => q .Match(m => m .Field(f => f.EmployeeId) .Query(employeeId.ToString()) ) ) ); // If found, delete the document if (searchResponse.Hits.Count() > 0) { var deleteRequest = new DeleteRequest(_appConfig.Elasticsearch.IndexName, searchResponse.Hits.FirstOrDefault().Id); await _elasticClient.DeleteAsync(deleteRequest); return(NoContent()); } else { // If not found, indicate as such return(NotFound()); } } catch (Exception ex) { _logger.LogError(1, ex, "Unable to delete document with employeeId: " + employeeId); return(StatusCode(StatusCodes.Status500InternalServerError)); } }