public async Task End(Exception ex = null)
        {
            if (ex != null)
            {
                return;
            }

            if (_pendingDocs.Any())
            {
                _logger.DebugEvent("Save", "Committing {Count} operations", _pendingDocs.Count);
                var pending = new Nest.BulkDescriptor();
                foreach (var op in _pendingDocs.Values)
                {
                    pending.AddOperation(op);
                }

                // Index the pending docs
                //var response = await _client.BulkAsync(_pendingDocs.Consistency(Consistency.Quorum)).ConfigureAwait(false);
                var response = await _client.BulkAsync(pending).ConfigureAwait(false);

                if (response.Errors)
                {
                    foreach (var item in response.Items.Select(x => $"{x.Type}, {x.Id}").Except(response.ItemsWithErrors.Select(x => $"{x.Type}, {x.Id}")))
                    {
                        Bag.Saved.Add(item);
                    }

                    throw new StorageException(response.DebugInformation);
                }

                // refresh all indicies which were "inserted" into so we can GET by Id immediately
                var indices = _pendingDocs.Values.Where(x => x.Operation == "index");
                if (indices.Any())
                {
                    await _client.RefreshAsync(indices.Select(x => x.Index).ToArray()).ConfigureAwait(false);
                }
            }
        }
Example #2
0
        public Nest.BulkDescriptor OnBuildMergeQuery(IEnumerable <User> enumerable, User mainUser, object data, Nest.BulkDescriptor desc)
        {
            var profiles = (List <PlayerProfile>)data;

            foreach (var profile in profiles)
            {
                desc = desc.Update <object>(u => u.Doc(new { PlayerId = mainUser.Id }).Id(profile.Id));
            }
            return(desc);
        }