public BulkOperationsResponse Delete(IOpenSearchableElasticType type, IOpenSearchResultCollection results) { BulkRequest bulkRequest = new BulkRequest() { Refresh = true, Consistency = Consistency.One, Index = type.Index, Type = type.Type, Operations = new List<IBulkOperation>() }; foreach (var doc in results.Items) { var bulkDeleteOperation = new BulkDeleteOperation<IElasticItem>(doc.Identifier); bulkDeleteOperation.Type = type.Type.Name; var bulkOp = bulkDeleteOperation; bulkRequest.Operations.Add(bulkOp); } var response = client.Bulk(bulkRequest); BulkOperationsResponse ingestionResponse = new BulkOperationsResponse(); foreach (var item in response.Items) { if (!item.IsValid) { ingestionResponse.Errors++; } else { ingestionResponse.Deleted++; } } return ingestionResponse; }
public BulkOperationsResponse Delete(IOpenSearchableElasticType type, IOpenSearchResultCollection results) { BulkRequest bulkRequest = new BulkRequest() { Refresh = true, Consistency = Consistency.One, Index = type.Index, Type = type.Type, Operations = new List <IBulkOperation>() }; foreach (var doc in results.Items) { var bulkDeleteOperation = new BulkDeleteOperation <IElasticItem>(doc.Identifier); bulkDeleteOperation.Type = type.Type.Name; var bulkOp = bulkDeleteOperation; bulkRequest.Operations.Add(bulkOp); } var response = client.Bulk(bulkRequest); BulkOperationsResponse ingestionResponse = new BulkOperationsResponse(); foreach (var item in response.Items) { if (!item.IsValid) { ingestionResponse.Errors++; } else { ingestionResponse.Deleted++; } } return(ingestionResponse); }
public BulkOperationsResponse Ingest(IOpenSearchableElasticType type, IOpenSearchResultCollection results) { OpenSearchFactory.RemoveLinksByRel(ref results, "self"); OpenSearchFactory.RemoveLinksByRel(ref results, "search"); IElasticCollection docs = type.FromOpenSearchResultCollection(results); BulkRequest bulkRequest = new BulkRequest() { Refresh = true, Consistency = Consistency.One, Index = type.Index, Type = type.Type, Operations = new List<IBulkOperation>() }; RootObjectMapping currentMapping = null; try { var mappingResponse = client.GetMapping<IElasticType>(g => g.Index(type.Index.Name).Type(type.Type.Name)); currentMapping = mappingResponse.Mapping; } catch (Exception) { } var rootObjectMapping = type.GetRootMapping(); if (!rootObjectMapping.Equals(currentMapping)) { client.Map<IElasticType>(m => m.Index(type.Index.Name).Type(type.Type.Name)); } foreach (var doc in docs.ElasticItems) { var bulkIndexOperation = new BulkIndexOperation<IElasticItem>(doc); bulkIndexOperation.Id = ((IOpenSearchResultItem)doc).Identifier; bulkIndexOperation.Type = type.Type.Name; var bulkOp = bulkIndexOperation; bulkRequest.Operations.Add(bulkOp); } var response = client.Bulk(bulkRequest); BulkOperationsResponse ingestionResponse = new BulkOperationsResponse(); foreach (var item in response.Items) { if (!item.IsValid) { ingestionResponse.Errors++; continue; } if (item.Version == "1") ingestionResponse.Added++; else ingestionResponse.Updated++; } return ingestionResponse; }
public BulkOperationsResponse Ingest(IOpenSearchableElasticType type, IOpenSearchResultCollection results) { OpenSearchFactory.RemoveLinksByRel(ref results, "self"); OpenSearchFactory.RemoveLinksByRel(ref results, "search"); IElasticCollection docs = type.FromOpenSearchResultCollection(results); BulkRequest bulkRequest = new BulkRequest() { Refresh = true, Consistency = Consistency.One, Index = type.Index, Type = type.Type, Operations = new List <IBulkOperation>() }; RootObjectMapping currentMapping = null; try { var mappingResponse = client.GetMapping <IElasticType>(g => g.Index(type.Index.Name).Type(type.Type.Name)); currentMapping = mappingResponse.Mapping; } catch (Exception) { } var rootObjectMapping = type.GetRootMapping(); if (!rootObjectMapping.Equals(currentMapping)) { client.Map <IElasticType>(m => m.Index(type.Index.Name).Type(type.Type.Name)); } foreach (var doc in docs.ElasticItems) { var bulkIndexOperation = new BulkIndexOperation <IElasticItem>(doc); bulkIndexOperation.Id = ((IOpenSearchResultItem)doc).Identifier; bulkIndexOperation.Type = type.Type.Name; var bulkOp = bulkIndexOperation; bulkRequest.Operations.Add(bulkOp); } var response = client.Bulk(bulkRequest); BulkOperationsResponse ingestionResponse = new BulkOperationsResponse(); foreach (var item in response.Items) { if (!item.IsValid) { ingestionResponse.Errors++; continue; } if (item.Version == "1") { ingestionResponse.Added++; } else { ingestionResponse.Updated++; } } return(ingestionResponse); }