Exemple #1
0
        public async Task Ingest(IEnumerable <Record> entries)
        {
            var activity   = new IngestActivity();
            var operations = new List <IBulkOperation>(BatchSize);

            foreach (var entry in entries)
            {
                var indexName = GetIndex(entry);
                operations.Add(new BulkIndexOperation <object>(entry.JsonDocument)
                {
                    Id    = !string.IsNullOrWhiteSpace(entry.Id) ? new Id(entry.Id) : null,
                    Index = indexName,
                    Type  = entry.TypeName
                });
                activity.AddDocument(indexName, entry.IndexName, entry.TypeName, entry.JsonDocument.Length);

                if (operations.Count == BatchSize)
                {
                    await IngestBatch(operations, activity);

                    operations.Clear();
                    activity = new IngestActivity();
                }
            }

            if (operations.Count > 0)
            {
                await IngestBatch(operations, activity);
            }
        }