//[I]
		public void ServerTestWhenThrowExceptionsDisabled()
		{
			var settings = new ConnectionSettings(new Uri("http://ipv4.fiddler:9200"));
			var client = new ElasticClient(settings);
			var response = client.GetMapping<Project>(s => s.Index("doesntexist"));
			response.CallDetails.OriginalException.Should().NotBeNull();
			response.CallDetails.ServerError.Should().NotBeNull();
			response.CallDetails.ServerError.Status.Should().BeGreaterThan(0);
		}
		//[I]
		public void ServerTestWhenThrowExceptionsEnabled()
		{
			var settings = new ConnectionSettings(new Uri("http://ipv4.fiddler:9200"))
				.ThrowExceptions();
			var client = new ElasticClient(settings);
			var exception = Assert.Throws<ElasticsearchClientException>(() => client.GetMapping<Project>(s => s.Index("doesntexist")));
			exception.InnerException.Should().NotBeNull();
			exception.Response.Should().NotBeNull();
			exception.Response.ServerError.Should().NotBeNull();
			exception.Response.ServerError.Status.Should().BeGreaterThan(0);
		}
		public void ServerTestWhenThrowExceptionsDisabled()
		{
			var settings = new ConnectionSettings(new Uri($"http://{TestClient.Host}:{_port}"));
			var client = new ElasticClient(settings);
			var response = client.GetMapping<Project>(s => s.Index("doesntexist"));
#if DOTNETCORE 
			// HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set
			response.CallDetails.OriginalException.Should().BeNull();
#else 
			response.CallDetails.OriginalException.Should().NotBeNull();
#endif
			response.CallDetails.ServerError.Should().NotBeNull();
			response.CallDetails.ServerError.Status.Should().BeGreaterThan(0);
		}
		public void ServerTestWhenThrowExceptionsEnabled()
		{
			var settings = new ConnectionSettings(new Uri($"http://{TestClient.Host}:{_port}"))
				.ThrowExceptions();
			var client = new ElasticClient(settings);
			var exception = Assert.Throws<ElasticsearchClientException>(() => client.GetMapping<Project>(s => s.Index("doesntexist")));
#if DOTNETCORE 
			// HttpClient does not throw on "known error" status codes (i.e. 404) thus the inner exception should not be set
			exception.InnerException.Should().BeNull();
#else
			exception.InnerException.Should().NotBeNull();
#endif
			exception.Response.Should().NotBeNull();
			exception.Response.ServerError.Should().NotBeNull();
			exception.Response.ServerError.Status.Should().BeGreaterThan(0);
		}
		public void CanDeserializeCopyTo()
		{
			var json = "{\"test-events-v1-201412\":{\"mappings\":{\"events\":{\"dynamic\":\"false\",\"_size\":{\"enabled\":true},\"properties\":{\"created_utc\":{\"type\":\"date\"},\"data\":{\"properties\":{\"@environment\":{\"properties\":{\"o_s_name\":{\"type\":\"text\",\"index\":false,\"copy_to\":[\"os\"]}}}}},\"id\":{\"type\":\"keyword\"},\"os\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}}}}},\"test-events-v1-201502\":{\"mappings\":{\"events\":{\"dynamic\":\"false\",\"_size\":{\"enabled\":true},\"properties\":{\"created_utc\":{\"type\":\"date\"},\"data\":{\"properties\":{\"@environment\":{\"properties\":{\"o_s_name\":{\"type\":\"text\",\"index\":false,\"copy_to\":[\"os\"]}}}}},\"id\":{\"type\":\"keyword\"},\"os\":{\"type\":\"text\",\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}}}}}}";

			var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

			var connection = new InMemoryConnection(Encoding.UTF8.GetBytes(json));
			var settings = new ConnectionSettings(pool, connection).DefaultIndex("test-events-v1-201412");
			var client = new ElasticClient(settings);

			var mappingResponse = client.GetMapping<Events>();

			mappingResponse.IsValid.Should().BeTrue();

			var mappingWalker = new MappingWalker(new CopyToVisitor());
			mappingWalker.Accept(mappingResponse);
		}
        private void EagerCreateIndex(Contexts.Mouths.Mouth destination)
        {
            IGetMappingResponse mapping = null;

            try
            {
                if (destination.DeleteExisting)
                {
                    // Get previous mapping
                    mapping = _client.GetMapping <object>(m =>
                    {
                        m.Index(destination.Index);
                        m.Type(destination.Type);
                        return(m);
                    });
                    _client.DeleteMapping(new DeleteMappingRequest(destination.Index, destination.Type));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            try
            {
                var index = _client.CreateIndex(c => c
                                                .Index(destination.Index)
                                                .InitializeUsing(new Nest.IndexSettings())
                                                );

                _indexCreated = true;

                if (mapping != null)
                {
                    // Use previous mapping to create mapping for new index
                    log.Info("Adding previously pulled mapping");
                    _client.Map <object>(m =>
                    {
                        m.InitializeUsing(mapping.Mapping);

                        m.Index(destination.Index);
                        m.Type(destination.Type);

                        return(m);
                    });
                }
                else
                {
                    // Process parent mapping as normal for type creation
                    if (destination.Mapping != null)
                    {
                        _client.Map <object>(m =>
                        {
                            m.Index(destination.Index);
                            m.Type(destination.Type);

                            if (destination.Mapping.Parent != null)
                            {
                                m.SetParent(destination.Mapping.Parent.Type);
                            }

                            return(m);
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }