public static void HowToScrollIndex(IElasticClient client) { var res = client.Search <ProductListEsIndexModelExample>(s => s .From(0) .Size(1) .MatchAll() .Scroll(new Time(TimeSpan.FromSeconds(4))) ); res.ThrowIfException(); if (!ValidateHelper.IsPlumpString(res.ScrollId)) { throw new Exception("未能拿到游标地址"); } while (true) { res = client.Scroll <ProductListEsIndexModelExample>("4s", res.ScrollId); if (!res.Documents.Any()) { break; } foreach (var doc in res.Documents) { //do something client.Delete(new DeleteRequest("index", "typename", "ukey")); client.Delete(DocumentPath <ProductListEsIndexModelExample> .Id("ukey").Index("index")); } } }
public void DeleteClient(string handle) { var deletedObjects = _client.Search <ServiceModel>(index => index .Type <ServiceModel>() .Query(filter => filter.Term(e => e.Handle, handle)) ); var deleteResults = deletedObjects.Hits.Select(hit => _client.Delete(new DocumentPath <ServiceModel>(hit.Id) .Type(hit.Type), item => item.Refresh(new Refresh())) ); var deleteCount = deleteResults.Count(arg => arg.ApiCall.Success); Console.WriteLine($"Deleted {deleteCount} matching clients"); }
public IDeleteResponse Delete(TIdentifier id) { var response = _client.Delete <TEntity> (new DocumentPath <TEntity>(id.ToString()), g => g.Index(GetIndex <TEntity>()).Refresh(_refresh)); return(response); }
/// <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 IDeleteResponse Delete <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.Delete <T>(s => selector(s.Id(id)))); }
public void Handle(Destroyed e) { var index = _elastic.Get <Responses.Index>(e.AccountId); _elastic.Delete <Responses.Index>(e.AccountId); _manager.Publish(index.Source, ChangeType.DELETE); }
public override void RemoveServer(string serverId) { if (serverId == null) { throw new ArgumentNullException(nameof(serverId)); } _elasticClient.Delete <Model.Server>(serverId).ThrowIfInvalid(); }
public void Deleted(OrderItemModel item) { var deleteResponse = _elasticClient.Delete <OrderItemModel>(item.NodeId); if (deleteResponse.ApiCall == null || !deleteResponse.ApiCall.Success) { throw new OrderItemSearchIndexingException("Failed to delete order item. Reason: " + deleteResponse.DebugInformation + "; Data:" + JsonConvert.SerializeObject(item)); } }
public void Delete(string indexName, int id) { DocumentPath <TestModel5> deletePath = new DocumentPath <TestModel5>(id); var response = _client.Delete(deletePath, s => s.Index(indexName)); // _client.Delete(deletePath, s => s.Index(indexName).Type(typeof(TestModel5))); //_client.Delete(deletePath, s => s.Index(indexName).Type("TestModel5")); //IDeleteRequest request = new DeleteRequest(indexName, typeof(TestModel5), id); //_client.Delete(request); }
public static DeleteResponse DeleteDocument(this IElasticClient elasticClient , long id , string indexName ) { DeleteRequest request = new DeleteRequest(indexName, id); DeleteResponse response = elasticClient.Delete(request); return(response); }
public ElasticSearchResponse Delete <T>(string id, string indexName = null) where T : class { indexName = indexName ?? GetTypeIndexName(typeof(T)); _logger.LogDebug("Removing document from index [" + indexName + "] with Id [" + id + "]"); var deleteResponse = _client.Delete <T>(id, s => s .Index(indexName) ); return(ConstructResponse(deleteResponse, $"Error removing document from index [{indexName}] with id {id}\n")); }
protected virtual void RemoveCore(IElasticClient client, TUmbracoEntity entity, string indexName = null) { var idValue = IdFor(entity); var documentPath = DocumentPath <TUmbracoDocument> .Id(idValue); if (client.DocumentExists(documentPath, d => d.Index(indexName)).Exists) { client.Delete(documentPath, d => d.Index(indexName)); } }
public void Remove(string key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } _client.Delete <CacheItem>(key); ScanForExpiredItemsIfRequired(); }
public ResponseResult DeleteEmployee(int id) { ResponseResult response = new ResponseResult { Message = "something wrong happen" }; var deleteResponse = _IElasticClient.Delete <Employee>(id); response.Message = deleteResponse.Result.ToString(); return(response); }
/// <summary> /// 同步器 /// </summary> /// <param name="msg"></param> /// <param name="log"></param> /// <param name="config"></param> /// <returns></returns> public bool SyncData(DataChangeMsg msg, ILog log, IndexSyncConfig config) { string msgstr = JsonConvert.SerializeObject(msg); try { string indexName = config.IndexName.ToLower(); if (msg.Type == "D") { //删除 log.Info("开始删除数据:" + msgstr); //var path = new DocumentPath<TEs>(msg.PkValue); var path = GetDocumentPath(msg, log); EsClient.Delete(path, n => n.Index(indexName)); log.Info("删除数据完成:" + msgstr); return(true); } //获取新数据 log.Info("开始获取新数据:" + msgstr); //var infos = DataTrackDl.GetDataChangeMsgs<TSql>(msg); var infos = GetAllList(msg, log); //转换es数据 var esInfos = TSqltoTEs(infos, log); //同步 log.Info("开始同步数据:" + msgstr); if (infos != null && infos.Count > 0) { //同步到es var result = EsClient.IndexMany(esInfos, indexName); if (result.ServerError != null) { log.Error("索引失败:" + result.ServerError.Error.Reason); return(false); } log.Info("同步数据完成:" + msgstr); } return(true); } catch (Exception ex) { log.Error("同步数据失败:" + msgstr, ex); } return(false); }
public DeleteResponse Delete <T>(string indexName, int id) where T : class { try { DocumentPath <T> deletePath = new DocumentPath <T>(id); var response = elasticClient.Delete(deletePath, s => s.Index(indexName.ToLower())); return(response); } catch (ElasticsearchClientException ex) { if (ex.Response.HttpStatusCode == 404) { //404 } throw; } }
public bool Excluir(string id) { bool status; var response = _elasticClient.Delete <Cliente>(id, d => d .Index(nameof(Cliente).ToLower())); if (response.IsValid) { status = true; } else { status = false; } return(status); }
private void Flush(object source, ElapsedEventArgs ea) { // TODO use a sync object to avoid concurrency instead of copy the list and clear... if (_toBeAdded.Any()) { var docs = _toBeAdded.ToList(); _toBeAdded.Clear(); var waitHandle = new CountdownEvent(1); var bulkAll = _elasticClient.BulkAll(docs, b => b .Index(_indexName) /* index */ .Type <ZeroTask>() .BackOffRetries(2) .BackOffTime("30s") .RefreshOnCompleted(true) .MaxDegreeOfParallelism(4) .Size(1000) ); bulkAll.Subscribe(new BulkAllObserver( //onNext: (b) => { Console.Write("."); }, onError: (e) => throw new Exception("There is a problem with ElasticSearch", e), onCompleted: () => waitHandle.Signal() )); waitHandle.Wait(); } if (!_toBeDeleted.Any()) { return; } var toBeDeleted = _toBeDeleted.ToList(); _toBeDeleted.Clear(); foreach (var id in toBeDeleted) { _elasticClient.Delete <T>(id, d => d.Index(_indexName)); } }
private static void TestIndex(IElasticClient elastic) { var blogPost = new BlogPost { Id = Guid.NewGuid(), Title = "First blog post", Body = "This is very long blog post!" }; var firstId = blogPost.Id; var indexResult = elastic.Index(blogPost, p => p .Id(blogPost.Id.ToString()) .Refresh(new Refresh())); Console.WriteLine(indexResult.ApiCall.Success); var resDel = elastic.Delete <BlogPost>(firstId.ToString()); Console.WriteLine(resDel.ApiCall.Success); }
public void Delete(InformationBase item) { //Honor the control flags if (item.IsDeleted == false) { return; } //First remove the item from other item's attachments var attachedTo = _elasticClient.Search <dynamic>(s => s .Query(q => q .Term(t => t.Field("Attachments").Value(item.ItemId)))); foreach (InformationBase detach in attachedTo.Documents) { _attachmentProcessor.Detach(detach, item); Save(detach); } //Second remove the item from the index _elasticClient.Delete <dynamic>(item.ItemId); }
// // GET: /Index/Delete public ActionResult Delete(string id) { var post = _elasticClient.Get <Post>(id); if (post == null) { throw new HttpException(404, "Post not found"); } var result = _elasticClient.Delete(post, new DeleteParameters { Refresh = true }); if (!result.ConnectionStatus.Success) { throw new HttpException(500, string.Format("Failed to delete post bacause of '{0}'.", result.ConnectionStatus.Result)); } return(RedirectToAction("Index", "Home")); }
public void Delete(string indexName, int id) { try { DocumentPath <TestModel2> deletePath = new DocumentPath <TestModel2>(id); var response = _client.Delete(deletePath, s => s.Index(indexName)); // _client.Delete(deletePath, s => s.Index(indexName).Type(typeof(TestModel2))); //_client.Delete(deletePath, s => s.Index(indexName).Type("TestModel2")); //IDeleteRequest request = new DeleteRequest(indexName, typeof(TestModel2), id); //_client.Delete(request); } catch (ElasticsearchClientException ex) { if (ex.Response.HttpStatusCode == 404) { //404 } throw; } }
/// <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="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 IDeleteResponse Delete <T>(this IElasticClient client, string id, Func <DeleteDescriptor <T>, DeleteDescriptor <T> > selector = null) where T : class { selector = selector ?? (s => s); return(client.Delete <T>(s => selector(s.Id(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="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 IDeleteResponse Delete(this IElasticClient client, string index, string type, string id, Func <DeleteDescriptor <object>, DeleteDescriptor <object> > selector = null) { selector = selector ?? (s => s); return(client.Delete <object>(s => selector(s.Index(index).Type(type).Id(id)))); }
protected override IDeleteResponse ExecuteCore(IElasticClient client, string index) { var id = DocumentPath <T> .Id(_id); return(client.Delete <T>(id, descriptor => BuildQueryCore(descriptor).Index(index))); }
protected void DeleteById_(string id_, string indexName) { var response = elasticClient.Delete <TModel>(id_, dd => dd.Index(indexName)); ElasticResponseValidator.Validate(response); }
public static IDeleteResponse Delete <T>(this IElasticClient client, Guid?id, Func <DeleteDescriptor <T>, DeleteDescriptor <T> > selector = null) where T : class { return(client.Delete(id.ToString(), selector)); }
/// <summary> /// 删除文档 /// </summary> public static void DeleteDoc_ <T>(this IElasticClient client, string indexName, string uid) where T : class, IElasticSearchIndex { var delete_response = client.Delete(client.ID <T>(indexName, uid)); delete_response.ThrowIfException(); }
protected override IDeleteResponse ExecuteCore(IElasticClient client, string index) { return(client.Delete <T>(descriptor => descriptor.IdFrom(_document).Index(index))); }
private static void TestIndex(IElasticClient elastic) { var blogPost = new BlogPost { Id = Guid.NewGuid(), Title = "First blog post", Body = "This is very long blog post!" }; var firstId = blogPost.Id; var indexResult = elastic.Index(blogPost, p => p .Id(blogPost.Id.ToString()) .Refresh()); Console.WriteLine(indexResult.ApiCall.Success); var resDel = elastic.Delete<BlogPost>(firstId.ToString()); Console.WriteLine(resDel.ApiCall.Success); }
public void Handle(Destroyed e) { _elastic.Delete <Responses.Index>(e.CountryId); }
public void ElasticSearch_CheckConnection() { var responseDelete = _esClient.DeleteIndex(IndexName); if (!_esClient.IndexExists(IndexName).Exists) { // Create a customize Startswith ICreateIndexRequest Config(CreateIndexDescriptor r) => r.Settings(s => s.NumberOfShards(1) .NumberOfReplicas(5) .Analysis(al => al.Analyzers(a => a.Custom("analyzer_startswith", c => c.Tokenizer("keyword").Filters("lowercase"))))) .Mappings(m => m.Map <Person>(t => t.AutoMap())); var responseCreate = _esClient.CreateIndex(IndexName, Config); //esClient.Map<Person>(m => //{ // var putMappingDescriptor = m.Index(Indices.Index("person")).AutoMap(); // return putMappingDescriptor; //}); } var person = new Person { Id = 1, FirstName = "Võ Kế", LastName = "Nghiệp" }; var repInsertDoc = _esClient.Index(person, s => s.Index <Person>()); person = new Person { Id = 2, FirstName = "Võ Trọng", LastName = "Nghĩa" }; repInsertDoc = _esClient.Index(person, s => s.Index <Person>()); person = new Person { Id = 3, FirstName = "Võ Trắc", LastName = "Nghị" }; repInsertDoc = _esClient.Index(person, s => s.Index <Person>()); person = new Person { Id = 4, FirstName = "Võ Nguyên", LastName = "Khang" }; repInsertDoc = _esClient.Index(person, s => s.Index <Person>()); person = new Person { Id = 5, FirstName = "Delete", LastName = "Delete" }; repInsertDoc = _esClient.Index(person, s => s.Index <Person>()); var repDeleteDoc = _esClient.Delete <Person>(5); person = new Person { Id = 6, FirstName = "Update", LastName = "Update" }; repInsertDoc = _esClient.Index(person, s => s.Index <Person>()); person = new Person { Id = 6, FirstName = "Update 1", LastName = "Update 1" }; repInsertDoc = _esClient.Index(person, s => s.Index <Person>()); var repGetDoc = _esClient.Get <Person>(6); //esClient.DeleteIndex("people"); //Assert.AreEqual(repInsertDoc.Result, Result.Updated); var repUpdateDoc = _esClient.Update <Person, Person>(new Person { Id = 6, FirstName = "Update 1" }, p => p.Doc(new Person { FirstName = "Update 2" })); Assert.AreEqual(repUpdateDoc.Version, 3); }