public async Task <int> CreateAsync(IList <T> items, Refresh refresh = Refresh.WaitFor) { if (!items.HasItems()) { throw new ArgumentException(string.Format(Utils.ARGUMENT_EMPTY_LIST_MESSAGE, nameof(items)), nameof(items)); } var descriptor = new BulkDescriptor(); foreach (var item in items) { if (string.IsNullOrWhiteSpace(item.Id)) { descriptor.Index <T>(x => x .Document(item)); } else { descriptor.Create <T>(x => x .Document(item)); } } descriptor.Refresh(refresh); var response = await _client.BulkAsync(descriptor); return(!response.IsValid ? 0 : response.Items.Count); }
public void InsertTransactions(IEnumerable <Transaction> transactions, ElasticClient client) { var descriptor = new BulkDescriptor(); foreach (var transaction in transactions) { descriptor.Create <Transaction>(op => op.Document(transaction)); } var result = client.Bulk(descriptor); }
public void InsertCards(IEnumerable <Card> cards, ElasticClient client) { var descriptor = new BulkDescriptor(); foreach (var card in cards) { descriptor.Create <Card>(op => op.Document(card)); } var result = client.Bulk(descriptor); }
private async Task AddRequestInfoAsync(IEnumerable <IRequestInfo> requests, CancellationToken token) { BulkDescriptor Descriptor = new BulkDescriptor(GetIndexName <RequestInfo>()); foreach (var item in requests) { Descriptor.Create <IRequestInfo>(op => op.Document(item)); } await Client.BulkAsync(Descriptor).ConfigureAwait(false); }
public BulkDescriptor Create <T>(Func <BulkCreateDescriptor <T>, IBulkCreateOperation <T> > bulkCreateSelector) where T : class { _bulkDescriptor.Create(bulkCreateSelector); _count++; if (HaveReachedBatchLimit(_count)) { _tasks.Add(_client.BulkAsync(_bulkDescriptor)); _bulkDescriptor = CreateBulkDescriptor(_indexName); _count = 0; } return(_bulkDescriptor); }
public async Task AddRequestInfoAsync(Dictionary <IRequestInfo, IRequestDetail> list, CancellationToken token) { BulkDescriptor requestDescriptor = new BulkDescriptor(GetIndexName <RequestInfo>()); foreach (var item in list.Select(x => x.Key)) { requestDescriptor.Create <IRequestInfo>(op => op.Document(item)); } await Client.BulkAsync(requestDescriptor); BulkDescriptor detailDescriptor = new BulkDescriptor(GetIndexName <RequestDetail>()); foreach (var item in list.Select(x => x.Value)) { detailDescriptor.Create <IRequestDetail>(op => op.Document(item)); } await Client.BulkAsync(detailDescriptor); }