示例#1
0
        public void Test1()
        {
            var config = new Configuration {
                Index = "Test1"
            };
            var client        = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
            var indexMappings = new IndexMappings(config, client);
            var result        = indexMappings.CreateIndex();

            result.IsValid.ShouldBeTrue();

            CleanUpIndex(client, config);
        }
示例#2
0
        private static ElasticClient CreateIndex(Configuration config)
        {
            var connection = new ConnectionSettings(new Uri("http://localhost:9200"))
                             .DisableDirectStreaming()
                             .OnRequestCompleted(apiCallDetails =>
            {
                // log out the request and the request body, if one exists for the type of request
                if (apiCallDetails.RequestBodyInBytes != null)
                {
                    Log.Information(
                        $"{apiCallDetails.HttpMethod} {apiCallDetails.Uri} " +
                        $"{Encoding.UTF8.GetString(apiCallDetails.RequestBodyInBytes)}");
                }
                else
                {
                    Log.Information($"{apiCallDetails.HttpMethod} {apiCallDetails.Uri}");
                }

                // log out the response and the response body, if one exists for the type of response
                if (apiCallDetails.ResponseBodyInBytes != null)
                {
                    Log.Information($"Status: {apiCallDetails.HttpStatusCode}" +
                                    $"{Encoding.UTF8.GetString(apiCallDetails.ResponseBodyInBytes)}");
                }
                else
                {
                    Log.Information($"Status: {apiCallDetails.HttpStatusCode}");
                }
            });
            var client        = new ElasticClient(connection);
            var indexMappings = new IndexMappings(config, client);
            var result        = indexMappings.CreateIndex();

            result.IsValid.ShouldBeTrue();
            return(client);
        }