public void SnapshotRestoreObservable()
		{
			var exceptionOccured = false;
			Exception lastException = null;

			var snapshotObservable = this.Client.SnapshotObservable(TimeSpan.FromMilliseconds(100),
				descriptor => descriptor
					.Repository(_repositoryName)
					.Snapshot(_snapshotName)
					.Index(_indexName));

			bool snapshotCompleted = false;

			var snapshotObserver = new SnapshotObserver(
				onNext: r =>
				{
					var snapshotsCount = r.Snapshots.Count();
					Assert.IsTrue(r.IsValid);
					Assert.AreEqual(1, snapshotsCount);
					CollectionAssert.Contains(r.Snapshots.ElementAt(0).Indices.Keys, _indexName);
				},
				onError: e =>
				{
					lastException = e;
					exceptionOccured = true;
				},
				completed: () =>
				{
					snapshotCompleted = true;
				}
				);

			using (var observable = snapshotObservable.Subscribe(snapshotObserver))
			{
				while (!snapshotCompleted)
				{
					if (exceptionOccured) Assert.Fail(lastException.Message);
					Thread.Sleep(100);
				}
			}

			exceptionOccured = false;
			lastException = null;

			var getSnapshotResponse = this.Client.GetSnapshot(_repositoryName, _snapshotName, descriptor => descriptor);
			var snapshot = getSnapshotResponse.Snapshots.ElementAt(0);
			Assert.IsTrue(getSnapshotResponse.IsValid);
			Assert.AreEqual(1, getSnapshotResponse.Snapshots.Count());
			Assert.AreEqual("SUCCESS", snapshot.State);
			CollectionAssert.Contains(snapshot.Indices, _indexName);

			var d = ElasticsearchConfiguration.DefaultIndex;

			_restoredIndexName = Regex.Replace(_indexName, d + "_(.+)", d + "_restored_$1");
			var restoredIndexExistsResponse = this.Client.IndexExists(f => f.Index(_restoredIndexName));
			restoredIndexExistsResponse.Exists.Should().BeFalse();

			var restoreObservable = this.Client.RestoreObservable(TimeSpan.FromMilliseconds(100), r => r
				.Repository(_repositoryName)
				.Snapshot(_snapshotName)
				.RenamePattern(d + "_(.+)")
				.RenameReplacement(d + "_restored_$1")
				.Index(_indexName)
				.IgnoreUnavailable(true));

			bool restoreCompleted = false;
			var restoreObserver = new RestoreObserver(
				onNext: r =>
				{
					var index = r.Indices.FirstOrDefault();
					Assert.AreEqual(1, r.Indices.Count);
				},
				onError: e =>
				{
					lastException = e;
					exceptionOccured = true;
				},
				completed: () =>
				{
					restoreCompleted = true;
				}
				);

			using (var observable = restoreObservable.Subscribe(restoreObserver))
			{
				while (!restoreCompleted)
				{
					if (exceptionOccured) Assert.Fail(lastException.Message);
					Thread.Sleep(100);
				}
			}

			restoredIndexExistsResponse = this.Client.IndexExists(f => f.Index(_restoredIndexName));
			restoredIndexExistsResponse.Exists.Should().BeTrue();

			var count = this.Client.Count<ElasticsearchProject>(descriptor => descriptor.Index(_restoredIndexName)).Count;
			var indexContent = this.Client.SourceMany<ElasticsearchProject>(_indexedElements.Select(x => (long)x.Id),
				_restoredIndexName);

			count.Should().Be(_indexedElements.Count);
			indexContent.ShouldBeEquivalentTo(_indexedElements);
		}
        public void SnapshotRestoreObservable()
        {
            var       exceptionOccured = false;
            Exception lastException    = null;

            var snapshotObservable = this.Client.SnapshotObservable(TimeSpan.FromMilliseconds(100),
                                                                    descriptor => descriptor
                                                                    .Repository(_repositoryName)
                                                                    .Snapshot(_snapshotName)
                                                                    .Index(_indexName));

            bool snapshotCompleted = false;

            var snapshotObserver = new SnapshotObserver(
                onNext: r =>
            {
                var snapshotsCount = r.Snapshots.Count();
                Assert.IsTrue(r.IsValid);
                Assert.AreEqual(1, snapshotsCount);
                CollectionAssert.Contains(r.Snapshots.ElementAt(0).Indices.Keys, _indexName);
            },
                onError: e =>
            {
                lastException    = e;
                exceptionOccured = true;
            },
                completed: () =>
            {
                snapshotCompleted = true;
            }
                );

            using (var observable = snapshotObservable.Subscribe(snapshotObserver))
            {
                while (!snapshotCompleted)
                {
                    if (exceptionOccured)
                    {
                        Assert.Fail(lastException.Message);
                    }
                    Thread.Sleep(100);
                }
            }

            exceptionOccured = false;
            lastException    = null;

            var getSnapshotResponse = this.Client.GetSnapshot(_repositoryName, _snapshotName, descriptor => descriptor);
            var snapshot            = getSnapshotResponse.Snapshots.ElementAt(0);

            Assert.IsTrue(getSnapshotResponse.IsValid);
            Assert.AreEqual(1, getSnapshotResponse.Snapshots.Count());
            Assert.AreEqual("SUCCESS", snapshot.State);
            CollectionAssert.Contains(snapshot.Indices, _indexName);

            var d = ElasticsearchConfiguration.DefaultIndex;

            _restoredIndexName = Regex.Replace(_indexName, d + "_(.+)", d + "_restored_$1");
            var restoredIndexExistsResponse = this.Client.IndexExists(f => f.Index(_restoredIndexName));

            restoredIndexExistsResponse.Exists.Should().BeFalse();

            var restoreObservable = this.Client.RestoreObservable(TimeSpan.FromMilliseconds(100), r => r
                                                                  .Repository(_repositoryName)
                                                                  .Snapshot(_snapshotName)
                                                                  .RenamePattern(d + "_(.+)")
                                                                  .RenameReplacement(d + "_restored_$1")
                                                                  .Index(_indexName)
                                                                  .IgnoreUnavailable(true));

            bool restoreCompleted = false;
            var  restoreObserver  = new RestoreObserver(
                onNext: r =>
            {
                var index = r.Indices.FirstOrDefault();
                Assert.AreEqual(1, r.Indices.Count);
            },
                onError: e =>
            {
                lastException    = e;
                exceptionOccured = true;
            },
                completed: () =>
            {
                restoreCompleted = true;
            }
                );

            using (var observable = restoreObservable.Subscribe(restoreObserver))
            {
                while (!restoreCompleted)
                {
                    if (exceptionOccured)
                    {
                        Assert.Fail(lastException.Message);
                    }
                    Thread.Sleep(100);
                }
            }

            restoredIndexExistsResponse = this.Client.IndexExists(f => f.Index(_restoredIndexName));
            restoredIndexExistsResponse.Exists.Should().BeTrue();

            var count        = this.Client.Count <ElasticsearchProject>(descriptor => descriptor.Index(_restoredIndexName)).Count;
            var indexContent = this.Client.SourceMany <ElasticsearchProject>(_indexedElements.Select(x => (long)x.Id),
                                                                             _restoredIndexName);

            count.Should().Be(_indexedElements.Count);
            indexContent.ShouldBeEquivalentTo(_indexedElements);
        }