diff --git a/.editorconfig b/.editorconfig index 2c0f81a480b..cd2391b636d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -111,6 +111,17 @@ csharp_space_between_method_call_parameter_list_parentheses = false:error csharp_preserve_single_line_statements = false:error csharp_preserve_single_line_blocks = true:error +# Resharper +resharper_csharp_braces_for_lock=required_for_complex +resharper_csharp_braces_for_using=required_for_complex +resharper_csharp_braces_for_while=required_for_complex +resharper_csharp_braces_for_foreach=required_for_complex +resharper_csharp_braces_for_for=required_for_complex +resharper_csharp_braces_for_fixed=required_for_complex +resharper_csharp_braces_for_ifelse=required_for_complex + +resharper_csharp_accessor_owner_body=expression_body + # Override source included files [{SimpleJson|SynchronizedCollection}.cs] csharp_style_var_for_built_in_types = false:none diff --git a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs index 6f1f9ea141c..06fe34dd6ad 100644 --- a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs +++ b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs @@ -4,10 +4,9 @@ using System.IO; using System.Linq; using ApiGenerator.Domain; -using Newtonsoft.Json; -using ShellProgressBar; using Newtonsoft.Json.Linq; using RazorLight; +using ShellProgressBar; namespace ApiGenerator { @@ -17,39 +16,6 @@ public class ApiGenerator .UseMemoryCachingProvider() .Build(); - public static void Generate(string downloadBranch, params string[] folders) - { - Warnings = new List(); - var spec = CreateRestApiSpecModel(downloadBranch, folders); - var actions = new Dictionary, string> - { - { GenerateClientInterface, "Client interface" }, - { GenerateRequestParameters, "Request parameters" }, - { GenerateDescriptors, "Descriptors" }, - { GenerateRequests, "Requests" }, - { GenerateEnums, "Enums" }, - { GenerateRawClient, "Lowlevel client" }, - { GenerateRawDispatch, "Dispatch" }, - }; - - using (var pbar = new ProgressBar(actions.Count, "Generating code", new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray })) - { - foreach(var kv in actions) - { - pbar.Message = "Generating " + kv.Value; - kv.Key(spec); - pbar.Tick("Generated " + kv.Value); - } - } - - if (Warnings.Count == 0) return; - - Console.ForegroundColor = ConsoleColor.Yellow; - foreach (var warning in Warnings.Distinct().OrderBy(w=>w)) - Console.WriteLine(warning); - Console.ResetColor(); - } - public static List Warnings { get; private set; } private static string[] IgnoredApis { get; } = @@ -85,27 +51,63 @@ public static void Generate(string downloadBranch, params string[] folders) "nodes.reload_secure_settings.json" }; + public static void Generate(string downloadBranch, params string[] folders) + { + Warnings = new List(); + var spec = CreateRestApiSpecModel(downloadBranch, folders); + var actions = new Dictionary, string> + { + { GenerateClientInterface, "Client interface" }, + { GenerateRequestParameters, "Request parameters" }, + { GenerateDescriptors, "Descriptors" }, + { GenerateRequests, "Requests" }, + { GenerateEnums, "Enums" }, + { GenerateRawClient, "Lowlevel client" }, + { GenerateRawDispatch, "Dispatch" }, + }; + + using (var pbar = new ProgressBar(actions.Count, "Generating code", new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray })) + { + foreach (var kv in actions) + { + pbar.Message = "Generating " + kv.Value; + kv.Key(spec); + pbar.Tick("Generated " + kv.Value); + } + } + + if (Warnings.Count == 0) return; + + Console.ForegroundColor = ConsoleColor.Yellow; + foreach (var warning in Warnings.Distinct().OrderBy(w => w)) + Console.WriteLine(warning); + Console.ResetColor(); + } + private static RestApiSpec CreateRestApiSpecModel(string downloadBranch, string[] folders) { var directories = Directory.GetDirectories(CodeConfiguration.RestSpecificationFolder, "*", SearchOption.AllDirectories) - .Where(f=>folders == null || folders.Length == 0 || folders.Contains(new DirectoryInfo(f).Name)) + .Where(f => folders == null || folders.Length == 0 || folders.Contains(new DirectoryInfo(f).Name)) .ToList(); var endpoints = new Dictionary(); - using (var pbar = new ProgressBar(directories.Count, $"Listing {directories.Count} directories", new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray })) + using (var pbar = new ProgressBar(directories.Count, $"Listing {directories.Count} directories", + new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray })) { var folderFiles = directories.Select(dir => Directory.GetFiles(dir) - .Where(f => f.EndsWith(".json") && !IgnoredApis.Contains(new FileInfo(f).Name)) - .ToList() + .Where(f => f.EndsWith(".json") && !IgnoredApis.Contains(new FileInfo(f).Name)) + .ToList() ); var commonFile = Path.Combine(CodeConfiguration.RestSpecificationFolder, "Core", "_common.json"); if (!File.Exists(commonFile)) throw new Exception($"Expected to find {commonFile}"); + RestApiSpec.CommonApiQueryParameters = CreateCommonApiQueryParameters(commonFile); foreach (var jsonFiles in folderFiles) { - using (var fileProgress = pbar.Spawn(jsonFiles.Count, $"Listing {jsonFiles.Count} files", new ProgressBarOptions { ProgressCharacter = '─', BackgroundColor = ConsoleColor.DarkGray })) + using (var fileProgress = pbar.Spawn(jsonFiles.Count, $"Listing {jsonFiles.Count} files", + new ProgressBarOptions { ProgressCharacter = '─', BackgroundColor = ConsoleColor.DarkGray })) { foreach (var file in jsonFiles) { @@ -118,6 +120,7 @@ private static RestApiSpec CreateRestApiSpecModel(string downloadBranch, string[ var endpoint = CreateApiEndpoint(file); endpoints.Add(endpoint.Key, endpoint.Value); } + fileProgress.Tick(); } } @@ -169,13 +172,7 @@ private static void PatchOfficialSpec(JObject original, string jsonFile) MergeArrayHandling = MergeArrayHandling.Union }); - if (pathsOverride != null) - { - original.SelectToken("*.url.paths").Replace(pathsOverride); - } - - - + if (pathsOverride != null) original.SelectToken("*.url.paths").Replace(pathsOverride); } private static Dictionary CreateCommonApiQueryParameters(string jsonFile) @@ -183,44 +180,43 @@ private static Dictionary CreateCommonApiQueryParame var json = File.ReadAllText(jsonFile); var jobject = JObject.Parse(json); var commonParameters = jobject.Property("params").Value.ToObject>(); - return ApiQueryParametersPatcher.Patch(null, commonParameters, null, checkCommon: false); + return ApiQueryParametersPatcher.Patch(null, commonParameters, null, false); } - private static string CreateMethodName(string apiEndpointKey) - { - return PascalCase(apiEndpointKey); - } + private static string CreateMethodName(string apiEndpointKey) => PascalCase(apiEndpointKey); - private static string DoRazor(string name, string template, RestApiSpec model) - { - return Razor.CompileRenderAsync(name, template, model).GetAwaiter().GetResult(); - } + private static string DoRazor(string name, string template, RestApiSpec model) => + Razor.CompileRenderAsync(name, template, model).GetAwaiter().GetResult(); private static void GenerateClientInterface(RestApiSpec model) { var targetFile = CodeConfiguration.EsNetFolder + @"IElasticLowLevelClient.Generated.cs"; - var source = DoRazor(nameof(GenerateClientInterface), File.ReadAllText(CodeConfiguration.ViewFolder + @"IElasticLowLevelClient.Generated.cshtml"), model); + var source = DoRazor(nameof(GenerateClientInterface), + File.ReadAllText(CodeConfiguration.ViewFolder + @"IElasticLowLevelClient.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateRawDispatch(RestApiSpec model) { var targetFile = CodeConfiguration.NestFolder + @"_Generated/_LowLevelDispatch.generated.cs"; - var source = DoRazor(nameof(GenerateRawDispatch), File.ReadAllText(CodeConfiguration.ViewFolder + @"_LowLevelDispatch.Generated.cshtml"), model); + var source = DoRazor(nameof(GenerateRawDispatch), File.ReadAllText(CodeConfiguration.ViewFolder + @"_LowLevelDispatch.Generated.cshtml"), + model); File.WriteAllText(targetFile, source); } private static void GenerateRawClient(RestApiSpec model) { var targetFile = CodeConfiguration.EsNetFolder + @"ElasticLowLevelClient.Generated.cs"; - var source = DoRazor(nameof(GenerateRawClient), File.ReadAllText(CodeConfiguration.ViewFolder + @"ElasticLowLevelClient.Generated.cshtml"), model); + var source = DoRazor(nameof(GenerateRawClient), + File.ReadAllText(CodeConfiguration.ViewFolder + @"ElasticLowLevelClient.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateDescriptors(RestApiSpec model) { var targetFile = CodeConfiguration.NestFolder + @"_Generated\_Descriptors.generated.cs"; - var source = DoRazor(nameof(GenerateDescriptors), File.ReadAllText(CodeConfiguration.ViewFolder + @"_Descriptors.Generated.cshtml"), model); + var source = DoRazor(nameof(GenerateDescriptors), File.ReadAllText(CodeConfiguration.ViewFolder + @"_Descriptors.Generated.cshtml"), + model); File.WriteAllText(targetFile, source); } @@ -234,7 +230,8 @@ private static void GenerateRequests(RestApiSpec model) private static void GenerateRequestParameters(RestApiSpec model) { var targetFile = CodeConfiguration.EsNetFolder + @"Domain\RequestParameters\RequestParameters.Generated.cs"; - var source = DoRazor(nameof(GenerateRequestParameters), File.ReadAllText(CodeConfiguration.ViewFolder + @"RequestParameters.Generated.cshtml"), model); + var source = DoRazor(nameof(GenerateRequestParameters), + File.ReadAllText(CodeConfiguration.ViewFolder + @"RequestParameters.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } diff --git a/src/CodeGeneration/ApiGenerator/CodeConfiguration.cs b/src/CodeGeneration/ApiGenerator/CodeConfiguration.cs index 8b6e72edf23..5b2d60104c2 100644 --- a/src/CodeGeneration/ApiGenerator/CodeConfiguration.cs +++ b/src/CodeGeneration/ApiGenerator/CodeConfiguration.cs @@ -8,32 +8,9 @@ namespace ApiGenerator { public static class CodeConfiguration { - public static readonly Assembly Assembly = typeof(ApiGenerator).Assembly; - private static string _root = null; - private static string Root - { - get - { - if (CodeConfiguration._root != null) return CodeConfiguration._root; - var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory()); - - var runningAsDnx = - directoryInfo.Name == "ApiGenerator" && - directoryInfo.Parent != null && - directoryInfo.Parent.Name == "CodeGeneration"; - - CodeConfiguration._root = runningAsDnx ? "" : @"..\..\..\"; - return CodeConfiguration._root; - } - } - - public static string NestFolder { get; } = $@"{Root}..\..\..\src\Nest\"; - public static string EsNetFolder { get; } = $@"{Root}..\..\..\src\Elasticsearch.Net\"; - public static string ViewFolder { get; } = $@"{Root}Views\"; - public static string RestSpecificationFolder { get; } = $@"{Root}RestSpecification\"; - public static string LastDownloadedVersionFile { get; } = Path.Combine(Root, "last_downloaded_version.txt"); + public static readonly Assembly Assembly = typeof(ApiGenerator).Assembly; public static readonly Dictionary ApiNameMapping = (from f in new DirectoryInfo(NestFolder).GetFiles("*.cs", SearchOption.AllDirectories) @@ -41,8 +18,9 @@ private static string Root let c = Regex.Replace(contents, @"^.+\[MapsApi\(""([^ \r\n]+)""\)\].*$", "$1", RegexOptions.Singleline) where !c.Contains(" ") //filter results that did not match select new { Value = f.Name.Replace("Request", ""), Key = c.Replace(".json", "") }) - .DistinctBy(v => v.Key) - .ToDictionary(k => k.Key, v => v.Value.Replace(".cs", "")); + .DistinctBy(v => v.Key) + .ToDictionary(k => k.Key, v => v.Value.Replace(".cs", "")); + public static readonly Dictionary MethodNameOverrides = (from f in new DirectoryInfo(NestFolder).GetFiles("*.cs", SearchOption.AllDirectories) @@ -50,26 +28,51 @@ private static string Root let c = Regex.Replace(contents, @"^.+\[DescriptorFor\(""([^ \r\n]+)""\)\].*$", "$1", RegexOptions.Singleline) where !c.Contains(" ") //filter results that did not match select new { Value = f.Name.Replace("Request", ""), Key = c }) - .DistinctBy(v => v.Key) - .ToDictionary(k => k.Key, v => v.Value.Replace(".cs", "")); + .DistinctBy(v => v.Key) + .ToDictionary(k => k.Key, v => v.Value.Replace(".cs", "")); - public static readonly Dictionary KnownDescriptors = + public static readonly Dictionary KnownDescriptors = (from f in new DirectoryInfo(NestFolder).GetFiles("*Request.cs", SearchOption.AllDirectories) let contents = File.ReadAllText(f.FullName) let c = Regex.Replace(contents, @"^.+class ([^ \r\n]+Descriptor(?:<[^>\r\n]+>)?[^ \r\n]*).*$", "$1", RegexOptions.Singleline) select new { Key = Regex.Replace(c, "<.*$", ""), Value = Regex.Replace(c, @"^.*?(?:(\<.+>).*?)?$", "$1") }) - .DistinctBy(v => v.Key) - .OrderBy(v => v.Key) - .ToDictionary(k => k.Key, v => v.Value); + .DistinctBy(v => v.Key) + .OrderBy(v => v.Key) + .ToDictionary(k => k.Key, v => v.Value); - public static readonly Dictionary KnownRequests = + public static readonly Dictionary KnownRequests = (from f in new DirectoryInfo(NestFolder).GetFiles("*Request.cs", SearchOption.AllDirectories) let contents = File.ReadAllText(f.FullName) let c = Regex.Replace(contents, @"^.+interface ([^ \r\n]+Request(?:<[^>\r\n]+>)?[^ \r\n]*).*$", "$1", RegexOptions.Singleline) where c.StartsWith("I") && c.Contains("Request") select new { Key = Regex.Replace(c, "<.*$", ""), Value = Regex.Replace(c, @"^.*?(?:(\<.+>).*?)?$", "$1") }) - .DistinctBy(v => v.Key) - .ToDictionary(k => k.Key, v => v.Value); + .DistinctBy(v => v.Key) + .ToDictionary(k => k.Key, v => v.Value); + + public static string EsNetFolder { get; } = $@"{Root}..\..\..\src\Elasticsearch.Net\"; + public static string LastDownloadedVersionFile { get; } = Path.Combine(Root, "last_downloaded_version.txt"); + + public static string NestFolder { get; } = $@"{Root}..\..\..\src\Nest\"; + public static string RestSpecificationFolder { get; } = $@"{Root}RestSpecification\"; + public static string ViewFolder { get; } = $@"{Root}Views\"; + + private static string Root + { + get + { + if (_root != null) return _root; + + var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory()); + + var runningAsDnx = + directoryInfo.Name == "ApiGenerator" && + directoryInfo.Parent != null && + directoryInfo.Parent.Name == "CodeGeneration"; + + _root = runningAsDnx ? "" : @"..\..\..\"; + return _root; + } + } } } diff --git a/src/CodeGeneration/ApiGenerator/CodeGenerator.cs b/src/CodeGeneration/ApiGenerator/CodeGenerator.cs index 13fa7f633df..d20e0f9518c 100644 --- a/src/CodeGeneration/ApiGenerator/CodeGenerator.cs +++ b/src/CodeGeneration/ApiGenerator/CodeGenerator.cs @@ -19,7 +19,10 @@ public static string Property(string type, string name, string key, string sette A(PropertyGenerator(type, name, key, setter)); return string.Join("\r\n\t\t", components); - void A(string s) => components.Add(s); + void A(string s) + { + components.Add(s); + } } public static string Constructor(Constructor c) @@ -32,9 +35,12 @@ public static string Constructor(Constructor c) if (!c.Body.IsNullOrEmpty()) A(c.Body); if (!c.AdditionalCode.IsNullOrEmpty()) A(c.AdditionalCode); return string.Join("\r\n\t\t", components); - void A(string s) => components.Add(s); - } + void A(string s) + { + components.Add(s); + } + } private static IEnumerable RenderDocumentation(params string[] doc) @@ -44,24 +50,30 @@ private static IEnumerable RenderDocumentation(params string[] doc) { case 0: yield break; case 1: - yield return ($"///{doc[0]}"); + yield return $"///{doc[0]}"; + yield break; default: yield return "///"; + foreach (var d in doc) yield return $"/// {d}"; + yield return "///"; + yield break; } } + private static string[] WrapDocumentation(string documentation) { const int max = 140; - var lines = documentation.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); + var lines = documentation.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var charCount = 0; return lines.GroupBy(Wrap).Select(l => string.Join(" ", l.ToArray())).ToArray(); + int Wrap(string w) { - var increase = (charCount % max + w.Length + 1 >= max ? max - (charCount % max) : 0); + var increase = charCount % max + w.Length + 1 >= max ? max - charCount % max : 0; return (charCount += increase + w.Length + 1) / max; } } diff --git a/src/CodeGeneration/ApiGenerator/Domain/ApiEndpoint.cs b/src/CodeGeneration/ApiGenerator/Domain/ApiEndpoint.cs index 1deabb99138..c6bf3bd1a81 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/ApiEndpoint.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/ApiEndpoint.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; -using ApiGenerator.Overrides; using ApiGenerator.Overrides.Descriptors; -using CsQuery.ExtensionMethods.Internal; namespace ApiGenerator.Domain { @@ -12,6 +10,23 @@ public class RawDispatchInfo { public CsharpMethod CsharpMethod { get; set; } + public string IfCheck + { + get + { + var parts = CsharpMethod.Parts.Where(p => p.Name != "body").ToList(); + if (!parts.Any()) return string.Empty; + + var allPartsAreRequired = parts.Any() && parts.All(p => p.Required); + var call = allPartsAreRequired ? "AllSetNoFallback" : "AllSet"; + var assignments = parts + .Select(p => $"p.RouteValues.{p.Name.ToPascalCase()}") + .ToList(); + + return $"{call}({string.Join(", ", assignments)})"; + } + } + public IEnumerable MethodArguments { get @@ -31,86 +46,17 @@ public IEnumerable MethodArguments return $"p.RouteValues.{p.Name.ToPascalCase()}"; } }) - .Concat(new[] {"p.RequestParameters"}); + .Concat(new[] { "p.RequestParameters" }); return methodArgs; } } - - public string IfCheck - { - get - { - var parts = this.CsharpMethod.Parts.Where(p => p.Name != "body").ToList(); - if (!parts.Any()) return string.Empty; - - var allPartsAreRequired = parts.Any() && parts.All(p => p.Required); - var call = allPartsAreRequired ? "AllSetNoFallback" : "AllSet"; - var assignments = parts - .Select(p => $"p.RouteValues.{p.Name.ToPascalCase()}") - .ToList(); - - return $"{call}({string.Join(", ", assignments)})"; - } - } } public class ApiEndpoint { private List _csharpMethods; - - public string RestSpecName { get; set; } - public string CsharpMethodName { get; set; } - public string Documentation { get; set; } - public IEnumerable Methods { get; set; } - public IDictionary RemovedMethods { get; set; } = new Dictionary(); - public ApiUrl Url { get; set; } public ApiBody Body { get; set; } - - public string PascalCase(string s) - { - return ApiGenerator.PascalCase(s); - } - - public IEnumerable GetCsharpMethods() - { - //we distinct by here to catch aliased endpoints like: - // /_cluster/nodes/hotthreads and /_nodes/hotthreads - return this.CsharpMethods.ToList() - .DistinctBy(m => m.ReturnType + "--" + m.FullName + "--" + m.Arguments - ); - } - - public IDictionary> RawDispatches - { - get - { - return this.GetCsharpMethods() - .GroupBy(p => p.HttpMethod) - .ToDictionary(kv => kv.Key, kv => kv - .DistinctBy(m => m.Path) - .OrderByDescending(m => m.Parts.Count()) - .Select(m => - new RawDispatchInfo - { - CsharpMethod = m, - } - ) - ); - } - } - - public string OptionallyAppendHttpMethod(IEnumerable availableMethods, string currentHttpMethod) - { - if (availableMethods.Count() == 1) - return string.Empty; - if (availableMethods.Count() == 2 && availableMethods.Contains("GET")) - { - //if on operation has two endpoints and one of them is GET always favor the other as default - return currentHttpMethod == "GET" ? "Get" : string.Empty; - } - - return availableMethods.First() == currentHttpMethod ? string.Empty : this.PascalCase(currentHttpMethod); - } + public string CsharpMethodName { get; set; } public IEnumerable CsharpMethods { @@ -120,28 +66,29 @@ public IEnumerable CsharpMethods { foreach (var csharpMethod in _csharpMethods) yield return csharpMethod; + yield break; } // enumerate once and cache _csharpMethods = new List(); - this.PatchEndpoint(); + PatchEndpoint(); - var methods = new Dictionary(this.RemovedMethods); - foreach (var method in this.Methods) methods.Add(method, null); + var methods = new Dictionary(RemovedMethods); + foreach (var method in Methods) methods.Add(method, null); foreach (var kv in methods) { var method = kv.Key; var obsoleteVersion = kv.Value; - var methodName = this.CsharpMethodName + this.OptionallyAppendHttpMethod(methods.Keys, method); + var methodName = CsharpMethodName + OptionallyAppendHttpMethod(methods.Keys, method); //the distinctby here catches aliases routes i.e // /_cluster/nodes/{node_id}/hotthreads vs /_cluster/nodes/{node_id}/hot_threads - foreach (var path in this.Url.Paths.DistinctBy(p => p.Replace("_", ""))) + foreach (var path in Url.Paths.DistinctBy(p => p.Replace("_", ""))) { - var parts = (this.Url.Parts ?? new Dictionary()) + var parts = (Url.Parts ?? new Dictionary()) .Where(p => path.Contains("{" + p.Key + "}")) - .OrderBy(p => path.IndexOf("{" + p.Key, System.StringComparison.Ordinal)) + .OrderBy(p => path.IndexOf("{" + p.Key, StringComparison.Ordinal)) .Select(p => { p.Value.Name = p.Key; @@ -152,20 +99,15 @@ public IEnumerable CsharpMethods var args = parts.Select(p => p.Argument); //.NET does not allow get requests to have a body payload. - if (method != "GET" && this.Body != null) - { + if (method != "GET" && Body != null) parts.Add(new ApiUrlPart { Name = "body", Type = "PostData", - Description = this.Body.Description + Description = Body.Description }); - } - if (this.Url.Params == null || !this.Url.Params.Any()) - { - this.Url.Params = new Dictionary(); - } - var queryStringParamName = this.CsharpMethodName + "RequestParameters"; + if (Url.Params == null || !Url.Params.Any()) Url.Params = new Dictionary(); + var queryStringParamName = CsharpMethodName + "RequestParameters"; var apiMethod = new CsharpMethod { QueryStringParamName = queryStringParamName, @@ -175,11 +117,11 @@ public IEnumerable CsharpMethods ReturnDescription = "", FullName = methodName, HttpMethod = method, - Documentation = this.Documentation, + Documentation = Documentation, ObsoleteMethodVersion = obsoleteVersion, Path = path, Parts = parts, - Url = this.Url + Url = Url }; PatchMethod(apiMethod); @@ -206,27 +148,62 @@ public IEnumerable CsharpMethods ReturnDescription = "", FullName = methodName + "Async", HttpMethod = method, - Documentation = this.Documentation, + Documentation = Documentation, ObsoleteMethodVersion = obsoleteVersion, Arguments = string.Join(", ", args), Path = path, Parts = parts, - Url = this.Url + Url = Url }; PatchMethod(apiMethod); _csharpMethods.Add(apiMethod); yield return apiMethod; - } } } } + public string Documentation { get; set; } + public IEnumerable Methods { get; set; } + + public IDictionary> RawDispatches => GetCsharpMethods() + .GroupBy(p => p.HttpMethod) + .ToDictionary(kv => kv.Key, kv => kv + .DistinctBy(m => m.Path) + .OrderByDescending(m => m.Parts.Count()) + .Select(m => + new RawDispatchInfo + { + CsharpMethod = m, + } + ) + ); + + public IDictionary RemovedMethods { get; set; } = new Dictionary(); + + public string RestSpecName { get; set; } + public ApiUrl Url { get; set; } + + public string PascalCase(string s) => ApiGenerator.PascalCase(s); + + public IEnumerable GetCsharpMethods() => CsharpMethods.ToList() + .DistinctBy(m => m.ReturnType + "--" + m.FullName + "--" + m.Arguments + ); + + public string OptionallyAppendHttpMethod(IEnumerable availableMethods, string currentHttpMethod) + { + if (availableMethods.Count() == 1) + return string.Empty; + if (availableMethods.Count() == 2 && availableMethods.Contains("GET")) return currentHttpMethod == "GET" ? "Get" : string.Empty; + + return availableMethods.First() == currentHttpMethod ? string.Empty : PascalCase(currentHttpMethod); + } + private IEndpointOverrides GetOverrides() { - var method = this.CsharpMethodName; - if (CodeConfiguration.ApiNameMapping.TryGetValue(this.RestSpecName, out var mapsApiMethodName)) + var method = CsharpMethodName; + if (CodeConfiguration.ApiNameMapping.TryGetValue(RestSpecName, out var mapsApiMethodName)) method = mapsApiMethodName; else if (CodeConfiguration.MethodNameOverrides.TryGetValue(method, out var manualOverride)) method = manualOverride; @@ -235,51 +212,47 @@ private IEndpointOverrides GetOverrides() var type = CodeConfiguration.Assembly.GetType(typeName); if (type != null && Activator.CreateInstance(type) is IEndpointOverrides overrides) return overrides; + return null; } private void PatchEndpoint() { - var overrides = this.GetOverrides(); + var overrides = GetOverrides(); PatchRequestParameters(overrides); //rename the {metric} route param to something more specific on XpackWatcherStats // TODO: find a better place to do this - if (this.CsharpMethodName == "XpackWatcherStats") + if (CsharpMethodName == "XpackWatcherStats") { - var metric = this.Url.Parts.First(p => p.Key == "metric"); + var metric = Url.Parts.First(p => p.Key == "metric"); var apiUrlPart = metric.Value; apiUrlPart.Name = "watcher_stats_metric"; - if (this.Url.Parts.Remove("metric")) - { - this.Url.Parts.Add("watcher_stats_metric", apiUrlPart); - } + if (Url.Parts.Remove("metric")) Url.Parts.Add("watcher_stats_metric", apiUrlPart); - this.Url.Path = RenameMetricUrlPathParam(this.Url.Path); - this.Url.Paths = this.Url.Paths.Select(RenameMetricUrlPathParam); + Url.Path = RenameMetricUrlPathParam(Url.Path); + Url.Paths = Url.Paths.Select(RenameMetricUrlPathParam); } } private void PatchRequestParameters(IEndpointOverrides overrides) { - var newParams = ApiQueryParametersPatcher.Patch(this.Url.Path, this.Url.Params, overrides); - this.Url.Params = newParams; + var newParams = ApiQueryParametersPatcher.Patch(Url.Path, Url.Params, overrides); + Url.Params = newParams; } - private static string RenameMetricUrlPathParam(string path) - { - return path.Replace("{metric}", "{watcher_stats_metric}"); - } + private static string RenameMetricUrlPathParam(string path) => path.Replace("{metric}", "{watcher_stats_metric}"); //Patches a method name for the exceptions (IndicesStats needs better unique names for all the url endpoints) //or to get rid of double verbs in an method name i,e ClusterGetSettingsGet > ClusterGetSettings public void PatchMethod(CsharpMethod method) { if (method == null) return; + Func ms = s => method.FullName.StartsWith(s); Func pc = s => method.Path.Contains(s); @@ -294,10 +267,10 @@ public void PatchMethod(CsharpMethod method) method.FullName = Regex.Replace(method.FullName, m, a => a.Index != method.FullName.IndexOf(m, StringComparison.Ordinal) ? "" : m); - method = this.GetOverrides()?.PatchMethod(method) ?? method; + method = GetOverrides()?.PatchMethod(method) ?? method; var key = method.QueryStringParamName.Replace("RequestParameters", ""); - if (CodeConfiguration.ApiNameMapping.TryGetValue(this.RestSpecName, out var mapsApiMethodName)) + if (CodeConfiguration.ApiNameMapping.TryGetValue(RestSpecName, out var mapsApiMethodName)) method.QueryStringParamName = mapsApiMethodName + "RequestParameters"; else if (CodeConfiguration.MethodNameOverrides.TryGetValue(key, out var manualOverride)) method.QueryStringParamName = manualOverride + "RequestParameters"; @@ -311,7 +284,6 @@ public void PatchMethod(CsharpMethod method) if (CodeConfiguration.KnownDescriptors.TryGetValue(method.DescriptorType, out var generic)) method.DescriptorTypeGeneric = generic; else method.Unmapped = true; - } } } diff --git a/src/CodeGeneration/ApiGenerator/Domain/ApiQueryParameters.cs b/src/CodeGeneration/ApiGenerator/Domain/ApiQueryParameters.cs index ad45d5e6ca9..19652fff1b2 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/ApiQueryParameters.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/ApiQueryParameters.cs @@ -1,73 +1,111 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using CsQuery.ExtensionMethods.Internal; namespace ApiGenerator.Domain { public class ApiQueryParameters { - public string QueryStringKey { get; set; } + private static readonly string[] FieldsParams = { "fields", "_source_include", "_source_exclude" }; - public bool RenderPartial { get; set; } + public string ClsArgumentName => ClsName.ToCamelCase(); public string ClsName { get; set; } + public string Description { get; set; } + + public IEnumerable DescriptionHighLevel + { + get + { + switch (QueryStringKey) + { + case "routing": + yield return "A document is routed to a particular shard in an index using the following formula"; + yield return " shard_num = hash(_routing) % num_primary_shards"; + yield return "Elasticsearch will use the document id if not provided. "; + yield return "For requests that are constructed from/for a document NEST will automatically infer the routing key"; + yield return + "if that document has a or a routing mapping on for its type exists on "; + + yield break; + case "_source": + yield return "Whether the _source should be included in the response."; + + yield break; + case "filter_path": + yield return Description; + yield return "Use of response filtering can result in a response from Elasticsearch "; + yield return "that cannot be correctly deserialized to the respective response type for the request. "; + yield return "In such situations, use the low level client to issue the request and handle response deserialization"; + + yield break; + default: + yield return Description; + + yield break; + } + } + } + + public string DescriptorArgumentType => + Type == "list" && TypeHighLevel.EndsWith("[]") ? "params " + TypeHighLevel : TypeHighLevel; + + public Func FluentGenerator { get; set; } + public bool IsFieldParam => TypeHighLevel == "Field"; + + public bool IsFieldsParam => TypeHighLevel == "Fields"; + public string Obsolete { get; set; } public IEnumerable Options { get; set; } + public string QueryStringKey { get; set; } + + public bool RenderPartial { get; set; } + public string SetterHighLevel => "value"; + + public string SetterLowLevel => "value"; public string Type { get; set; } - private static readonly string[] FieldsParams = {"fields", "_source_include", "_source_exclude"}; public string TypeHighLevel { get { - if (this.QueryStringKey == "routing") return "Routing"; - var isFields = FieldsParams.Contains(this.QueryStringKey) || this.QueryStringKey.EndsWith("_fields"); + if (QueryStringKey == "routing") return "Routing"; + + var isFields = FieldsParams.Contains(QueryStringKey) || QueryStringKey.EndsWith("_fields"); - var csharpType = this.TypeLowLevel; + var csharpType = TypeLowLevel; switch (csharpType) { case "TimeSpan": return "Time"; } - switch (this.Type) + switch (Type) { case "list" when isFields: case "string" when isFields: return "Fields"; - case "string" when this.QueryStringKey.Contains("field"): return "Field"; + case "string" when QueryStringKey.Contains("field"): return "Field"; default: return csharpType; } } } - public string ClsArgumentName => this.ClsName.ToCamelCase(); - public string DescriptorArgumentType => - this.Type == "list" && this.TypeHighLevel.EndsWith("[]") ? "params " + this.TypeHighLevel : TypeHighLevel; - public string SetterHighLevel => "value"; - - public string SetterLowLevel => "value"; - - public bool IsFieldsParam => this.TypeHighLevel == "Fields"; - public bool IsFieldParam => this.TypeHighLevel == "Field"; - public string TypeLowLevel { get { - switch (this.Type) + switch (Type) { case "boolean": return "bool?"; case "list": return "string[]"; case "integer": return "int?"; case "date": return "DateTimeOffset?"; - case "enum": return $"{this.ClsName}?"; + case "enum": return $"{ClsName}?"; case "number": - return new[] {"boost", "percen", "score"}.Any(s => this.QueryStringKey.ToLowerInvariant().Contains(s)) + return new[] { "boost", "percen", "score" }.Any(s => QueryStringKey.ToLowerInvariant().Contains(s)) ? "double?" : "long?"; case "duration": @@ -78,45 +116,12 @@ public string TypeLowLevel case null: return "string"; default: - return this.Type; - } - } - } - - public string Description { get; set; } - public IEnumerable DescriptionHighLevel - { - get - { - switch (this.QueryStringKey) - { - case "routing": - yield return "A document is routed to a particular shard in an index using the following formula"; - yield return " shard_num = hash(_routing) % num_primary_shards"; - yield return "Elasticsearch will use the document id if not provided. "; - yield return "For requests that are constructed from/for a document NEST will automatically infer the routing key"; - yield return - "if that document has a or a routing mapping on for its type exists on "; - yield break; - case "_source": - yield return "Whether the _source should be included in the response."; - yield break; - case "filter_path": - yield return this.Description; - yield return "Use of response filtering can result in a response from Elasticsearch "; - yield return "that cannot be correctly deserialized to the respective response type for the request. "; - yield return "In such situations, use the low level client to issue the request and handle response deserialization"; - yield break; - default: - yield return this.Description; - yield break; + return Type; } } } public string InitializerGenerator(string type, string name, string key, string setter, params string[] doc) => - CodeGenerator.Property(type, name, key, setter, this.Obsolete, doc); - - public Func FluentGenerator { get; set; } + CodeGenerator.Property(type, name, key, setter, Obsolete, doc); } } diff --git a/src/CodeGeneration/ApiGenerator/Domain/ApiQueryParametersPatcher.cs b/src/CodeGeneration/ApiGenerator/Domain/ApiQueryParametersPatcher.cs index e97f4fc1989..50e773dcac4 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/ApiQueryParametersPatcher.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/ApiQueryParametersPatcher.cs @@ -8,12 +8,12 @@ namespace ApiGenerator.Domain { public static class ApiQueryParametersPatcher { - public static Dictionary Patch( string urlPath, IDictionary source, IEndpointOverrides overrides, - bool checkCommon = true) + bool checkCommon = true + ) { if (source == null) return null; @@ -54,14 +54,13 @@ public static Dictionary Patch( } return patchedParams; - } private static string CreateCSharpName(string queryStringKey) { if (string.IsNullOrWhiteSpace(queryStringKey)) return "UNKNOWN"; - var cased = queryStringKey.ToPascalCase(); + var cased = queryStringKey.ToPascalCase(); switch (cased) { case "Type": @@ -81,7 +80,8 @@ private static IList CreatePartialList(IEndpointOverrides global, IEndpo CreateList(global, local, "partial", e => e.RenderPartial, declaredKeys); private static IDictionary CreateLookup(IEndpointOverrides global, IEndpointOverrides local, string type, - Func> @from, ICollection declaredKeys) + Func> @from, ICollection declaredKeys + ) { var d = new Dictionary(); foreach (var kv in from(global)) d[kv.Key] = kv.Value; @@ -99,7 +99,8 @@ private static IDictionary CreateLookup(IEndpointOverrides globa } private static IList CreateList(IEndpointOverrides global, IEndpointOverrides local, string type, - Func> @from, ICollection declaredKeys) + Func> @from, ICollection declaredKeys + ) { var list = new List(); if (global != null) list.AddRange(from(global)); @@ -115,12 +116,13 @@ private static IList CreateList(IEndpointOverrides global, IEndpointOver } private static IDictionary CreateRenameLookup(IEndpointOverrides global, IEndpointOverrides local, - ICollection declaredKeys) => + ICollection declaredKeys + ) => CreateLookup(global, local, "rename", e => e.RenameQueryStringParams, declaredKeys); private static IDictionary CreateObsoleteLookup(IEndpointOverrides global, IEndpointOverrides local, - ICollection declaredKeys) => + ICollection declaredKeys + ) => CreateLookup(global, local, "obsolete", e => e.ObsoleteQueryStringParams, declaredKeys); - } } diff --git a/src/CodeGeneration/ApiGenerator/Domain/ApiUrl.cs b/src/CodeGeneration/ApiGenerator/Domain/ApiUrl.cs index 787b0adaa4a..b837d6fb6c5 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/ApiUrl.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/ApiUrl.cs @@ -10,21 +10,20 @@ public class ApiUrl //allowing these will cause too many overloads being generated which helps noone public static readonly string[] BlackListRouteValues = { "{search_groups}", "{indexing_types}", "{body}", "{scroll_id}" }; private IEnumerable _paths; + public IDictionary Params { get; set; } + + public IDictionary Parts { get; set; } public string Path { get; set; } public IEnumerable Paths { get => _paths?.Where(p => !BlackListRouteValues.Any(p.Contains)) - .ToList() ?? _paths; - set => _paths = this.EnsureBackslash(value); + .ToList() ?? _paths; + set => _paths = EnsureBackslash(value); } public IList EnsureBackslash(IEnumerable paths) => paths?.Select(p => p.StartsWith("/") ? p : $"/{p}").ToList(); - - public IDictionary Parts { get; set; } - public IDictionary Params { get; set; } - } } diff --git a/src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs b/src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs index 09f33a8c48b..dcdfd1bfbce 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/ApiUrlPart.cs @@ -1,28 +1,30 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace ApiGenerator.Domain { public class ApiUrlPart { - public string Name { get; set; } - public string Type { get; set; } - - private string _description; - public string Description - { - get => _description; - set => _description = CleanUpDescription(value); - } - public bool Required { get; set; } - public IEnumerable Options { get; set; } - - private string CleanUpDescription(string value) + public string Argument { - if (string.IsNullOrWhiteSpace(value)) return value; - return value.Replace("use `_all` or empty string", "use the special string `_all` or Indices.All"); + get + { + switch (Type) + { + case "int": + case "string": + return Type + " " + Name; + case "list": + return "string " + Name; + case "enum": + return ApiGenerator.PascalCase(Name) + " " + Name; + case "number": + return "string " + Name; + default: + return Type + " " + Name; + } + } } public string ClrTypeName @@ -31,26 +33,26 @@ public string ClrTypeName { if (ClrTypeNameOverride != null) return ClrTypeNameOverride; - switch(this.Name) + switch (Name) { case "index": case "new_index": - return this.Type == "string" ? "IndexName" : "Indices"; + return Type == "string" ? "IndexName" : "Indices"; case "target": return "IndexName"; - case "type": return this.Type == "string" ? "TypeName" : "Types"; + case "type": return Type == "string" ? "TypeName" : "Types"; case "watch_id": case "job_id": case "datafeed_id": case "snapshot_id": case "filter_id": - case "id": return this.Type == "string" ? "Id" : "Ids"; + case "id": return Type == "string" ? "Id" : "Ids"; case "category_id": return "CategoryId"; case "nodes": - case "node_id": return this.Type == "string" ? "NodeId" : "NodeIds"; - case "scroll_id": return this.Type == "string" ? "ScrollId" : "ScrollIds"; + case "node_id": return Type == "string" ? "NodeId" : "NodeIds"; + case "scroll_id": return Type == "string" ? "ScrollId" : "ScrollIds"; case "field": - case "fields": return this.Type == "string" ? "Field" : "Fields"; + case "fields": return Type == "string" ? "Field" : "Fields"; case "index_metric": return "IndexMetrics"; case "metric": case "watcher_stats_metric": @@ -68,48 +70,46 @@ public string ClrTypeName case "context": case "name": case "thread_pool_patterns": - return this.Type == "string" ? "Name" : "Names"; + return Type == "string" ? "Name" : "Names"; case "parent_task_id": case "task_id": return "TaskId"; case "timestamp": return "Timestamp"; - default: return this.Type + "_"; + default: return Type + "_"; } } } public string ClrTypeNameOverride { get; set; } + public string Description + { + get => _description; + set => _description = CleanUpDescription(value); + } + public string InterfaceName { get { - switch(this.Name) + switch (Name) { case "repository": return "RepositoryName"; - default: return this.Name.ToPascalCase(); + default: return Name.ToPascalCase(); } } } - public string Argument + public string Name { get; set; } + public IEnumerable Options { get; set; } + public bool Required { get; set; } + public string Type { get; set; } + + + private string CleanUpDescription(string value) { - get - { - switch (this.Type) - { - case "int": - case "string": - return this.Type + " " + this.Name; - case "list": - return "string " + this.Name; - case "enum": - return ApiGenerator.PascalCase(this.Name) + " " + this.Name; - case "number": - return "string " + this.Name; - default: - return this.Type + " " + this.Name; - } - } + if (string.IsNullOrWhiteSpace(value)) return value; + + return value.Replace("use `_all` or empty string", "use the special string `_all` or Indices.All"); } } } diff --git a/src/CodeGeneration/ApiGenerator/Domain/Constructor.cs b/src/CodeGeneration/ApiGenerator/Domain/Constructor.cs index a540ac5b4c0..c4b1faf4892 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/Constructor.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/Constructor.cs @@ -1,14 +1,12 @@ -using CsQuery.ExtensionMethods.Internal; - -namespace ApiGenerator.Domain +namespace ApiGenerator.Domain { public class Constructor { - public string Generated { get; set; } + public string AdditionalCode { get; set; } = string.Empty; public string Body { get; set; } - public string Url { get; set; } public string Description { get; set; } - public string AdditionalCode { get; set; } = string.Empty; + public string Generated { get; set; } + public string Url { get; set; } } public class FluentRouteSetter diff --git a/src/CodeGeneration/ApiGenerator/Domain/CsharpMethod.cs b/src/CodeGeneration/ApiGenerator/Domain/CsharpMethod.cs index cf3c777e02c..8ecd82d79cb 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/CsharpMethod.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/CsharpMethod.cs @@ -8,60 +8,74 @@ namespace ApiGenerator.Domain { public class CsharpMethod { - public string ReturnType { get; set; } - public string ReturnTypeGeneric { get; set; } + public IEnumerable AllParts => + (Url?.Parts?.Values ?? Enumerable.Empty()).Where(p => !string.IsNullOrWhiteSpace(p.Name)); + + public string Arguments { get; set; } public string CallTypeGeneric { get; set; } - public string ReturnDescription { get; set; } - public string FullName { get; set; } - public string QueryStringParamName { get; set; } public string DescriptorType { get; set; } public string DescriptorTypeGeneric { get; set; } - public string RequestType { get; set; } - public string ObsoleteMethodVersion { get; set; } + public string Documentation { get; set; } + public string FullName { get; set; } + public string HttpMethod { get; set; } - public string InterfaceType => "I" + (this.RequestTypeGeneric == "" || this.RequestTypeGeneric == "" ? this.RequestType : this.RequestType + this.RequestTypeGeneric); + public bool IndicesAndTypes => AllParts.Count() == 2 && AllParts.All(p => p.Type == "list") + && AllParts.All(p => new[] { "index", "type" }.Contains(p.Name)); + + public string InterfaceType => + "I" + (RequestTypeGeneric == "" || RequestTypeGeneric == "" ? RequestType : RequestType + RequestTypeGeneric); + + public bool IsDocumentPath => AllParts.Count() == 3 && AllParts.All(p => p.Type != "list") + && AllParts.All(p => new[] { "index", "type", "id" }.Contains(p.Name)); + + public bool IsDocumentRequest => IsDocumentPath && Url.Params.ContainsKey("routing"); + public string ObsoleteMethodVersion { get; set; } + public IEnumerable Parts { get; set; } + public string Path { get; set; } + public string QueryStringParamName { get; set; } + public string RequestType { get; set; } public string RequestTypeGeneric { get; set; } public bool RequestTypeUnmapped { get; set; } - public string HttpMethod { get; set; } - public string Documentation { get; set; } - public string Path { get; set; } - public string Arguments { get; set; } + public string ReturnDescription { get; set; } + public string ReturnType { get; set; } + public string ReturnTypeGeneric { get; set; } + + public bool SkipInterface { get; set; } public bool Unmapped { get; set; } - public IEnumerable Parts { get; set; } public ApiUrl Url { get; set; } - public bool SkipInterface { get; set; } + private bool IsPartless => Url.Parts == null || !Url.Parts.Any(); + private bool IsScroll => Url.Parts.All(p => p.Key == "scroll_id"); + + private string MetricPrefix => RequestType.Replace("Request", ""); - public static CsharpMethod Clone(CsharpMethod method) + public static CsharpMethod Clone(CsharpMethod method) => new CsharpMethod { - return new CsharpMethod - { - Path = method.Path, - RequestType = method.RequestType, - ReturnDescription = method.ReturnDescription, - Arguments = method.Arguments, - CallTypeGeneric = method.CallTypeGeneric, - DescriptorType = method.DescriptorType, - DescriptorTypeGeneric = method.DescriptorTypeGeneric, - Documentation = method.Documentation, - FullName = method.FullName, - HttpMethod = method.HttpMethod, - Parts = method.Parts, - QueryStringParamName = method.QueryStringParamName, - RequestTypeGeneric = method.RequestTypeGeneric, - RequestTypeUnmapped = method.RequestTypeUnmapped, - ReturnType = method.ReturnType, - ReturnTypeGeneric = method.ReturnTypeGeneric, - Unmapped = method.Unmapped, - Url = method.Url, - SkipInterface = method.SkipInterface - }; - } + Path = method.Path, + RequestType = method.RequestType, + ReturnDescription = method.ReturnDescription, + Arguments = method.Arguments, + CallTypeGeneric = method.CallTypeGeneric, + DescriptorType = method.DescriptorType, + DescriptorTypeGeneric = method.DescriptorTypeGeneric, + Documentation = method.Documentation, + FullName = method.FullName, + HttpMethod = method.HttpMethod, + Parts = method.Parts, + QueryStringParamName = method.QueryStringParamName, + RequestTypeGeneric = method.RequestTypeGeneric, + RequestTypeUnmapped = method.RequestTypeUnmapped, + ReturnType = method.ReturnType, + ReturnTypeGeneric = method.ReturnTypeGeneric, + Unmapped = method.Unmapped, + Url = method.Url, + SkipInterface = method.SkipInterface + }; - private string MetricPrefix => this.RequestType.Replace("Request", ""); private string ClrParamType(string clrType) => clrType.EndsWith("Metrics", StringComparison.OrdinalIgnoreCase) - ? this.MetricPrefix + clrType.Replace("Metrics", "Metric") : clrType; + ? MetricPrefix + clrType.Replace("Metrics", "Metric") + : clrType; public IEnumerable RequestConstructors() { @@ -73,10 +87,10 @@ public IEnumerable RequestConstructors() // Scroll ids should always be passed as part of the request body and enforced via manual ctors if (IsScroll) return ctors; - var m = this.RequestType; - foreach (var url in this.Url.Paths) + var m = RequestType; + foreach (var url in Url.Paths) { - var urlRouteParameters = this.Url.Parts + var urlRouteParameters = Url.Parts .Where(p => !ApiUrl.BlackListRouteValues.Contains(p.Key)) .Where(p => url.Contains($"{{{p.Value.Name}}}")) .OrderBy(kv => url.IndexOf($"{{{kv.Value.Name}}}", StringComparison.Ordinal)); @@ -93,7 +107,6 @@ public IEnumerable RequestConstructors() } if (urlRouteParameters.Any()) - { routing = "r=>r." + string.Join(".", urlRouteParameters .Select(p => new { @@ -106,26 +119,25 @@ public IEnumerable RequestConstructors() : p.Key }) .Select(p => $"{p.call}(\"{p.route}\", {p.v})") - ); - } + ); var doc = $@"///{url}"; if (urlRouteParameters.Any()) - { - doc += "\r\n\t\t" + string.Join("\r\n\t\t", urlRouteParameters.Select(p => $"///{(p.Value.Required ? "this parameter is required" : "Optional, accepts null")}")); - } + doc += "\r\n\t\t" + string.Join("\r\n\t\t", + urlRouteParameters.Select(p => + $"///{(p.Value.Required ? "this parameter is required" : "Optional, accepts null")}")); var generated = $"public {m}({par}) : base({routing})"; // special case SearchRequest to pass the type of T as the type, when only the index is specified. - if ((m == "SearchRequest") && urlRouteParameters.Count() == 1 && !string.IsNullOrEmpty(this.RequestTypeGeneric)) + if (m == "SearchRequest" && urlRouteParameters.Count() == 1 && !string.IsNullOrEmpty(RequestTypeGeneric)) { - var generic = this.RequestTypeGeneric.Replace("<", "").Replace(">", ""); + var generic = RequestTypeGeneric.Replace("<", "").Replace(">", ""); generated = $"public {m}({par}) : this({urlRouteParameters.First().Key}, typeof({generic}))"; } - if (string.IsNullOrEmpty(par) && !string.IsNullOrEmpty(this.RequestTypeGeneric)) + if (string.IsNullOrEmpty(par) && !string.IsNullOrEmpty(RequestTypeGeneric)) { - var generic = this.RequestTypeGeneric.Replace("<", "").Replace(">", ""); + var generic = RequestTypeGeneric.Replace("<", "").Replace(">", ""); doc = AppendToSummary(doc, ". Will infer the index from the generic type"); generated = $"public {m}({par}) : this(typeof({generic}))"; } @@ -134,22 +146,24 @@ public IEnumerable RequestConstructors() { Generated = generated, Description = doc, - Body = this.IsDocumentRequest ? $" => Q(\"routing\", new Routing(() => AutoRouteDocument()));" : string.Empty + Body = IsDocumentRequest ? $" => Q(\"routing\", new Routing(() => AutoRouteDocument()));" : string.Empty }; ctors.Add(c); } - if (IsDocumentPath && !string.IsNullOrEmpty(this.RequestTypeGeneric)) + if (IsDocumentPath && !string.IsNullOrEmpty(RequestTypeGeneric)) { - var documentPathGeneric = Regex.Replace(this.DescriptorTypeGeneric, @"^]+).*$", "$1"); - var doc = $"/// {this.Url.Path}"; - doc += "\r\n\t\t" + $"/// describes an elasticsearch document of type from which the index, type and id can be inferred"; - var documentRoute = "r=>r.Required(\"index\", index ?? document.Self.Index).Required(\"type\", type ?? document.Self.Type).Required(\"id\", id ?? document.Self.Id)"; + var documentPathGeneric = Regex.Replace(DescriptorTypeGeneric, @"^]+).*$", "$1"); + var doc = $"/// {Url.Path}"; + doc += "\r\n\t\t" + + $"/// describes an elasticsearch document of type from which the index, type and id can be inferred"; + var documentRoute = + "r=>r.Required(\"index\", index ?? document.Self.Index).Required(\"type\", type ?? document.Self.Type).Required(\"id\", id ?? document.Self.Id)"; var documentFromPath = $"partial void DocumentFromPath({documentPathGeneric} document);"; var constructor = $"DocumentPath<{documentPathGeneric}> document, IndexName index = null, TypeName type = null, Id id = null"; - var autoRoute = this.IsDocumentRequest ? "Q(\"routing\", new Routing(() => AutoRouteDocument() ?? document.Document));" : string.Empty; + var autoRoute = IsDocumentRequest ? "Q(\"routing\", new Routing(() => AutoRouteDocument() ?? document.Document));" : string.Empty; var body = $"{{ this.DocumentFromPath(document.Document); {autoRoute} }}"; var c = new Constructor @@ -166,21 +180,22 @@ public IEnumerable RequestConstructors() private void ParameterlessIndicesTypesConstructor(List ctors, string m) { - var generic = this.RequestTypeGeneric?.Replace("<", "").Replace(">", ""); + var generic = RequestTypeGeneric?.Replace("<", "").Replace(">", ""); string doc; Constructor c; if (string.IsNullOrEmpty(generic)) { - doc = $@"/// {this.Url.Path}"; + doc = $@"/// {Url.Path}"; c = new Constructor { Generated = $"public {m}()", Description = doc }; } else { - doc = $"///{this.Url.Path} describes an elasticsearch document type from which the index, type and id can be inferred"; + doc = + $"///{Url.Path} describes an elasticsearch document type from which the index, type and id can be inferred"; c = new Constructor { Generated = $"public {m}() : this(typeof({generic}), typeof({generic}))", Description = doc, }; } - c.Body = this.IsDocumentRequest ? $"Q(\"routing\", new Routing(() => AutoRouteDocument()));" : string.Empty; + c.Body = IsDocumentRequest ? $"Q(\"routing\", new Routing(() => AutoRouteDocument()));" : string.Empty; ctors.Add(c); } @@ -188,10 +203,11 @@ public IEnumerable DescriptorConstructors() { var ctors = new List(); if (IsPartless) return ctors; - var m = this.DescriptorType; - foreach (var url in this.Url.Paths) + + var m = DescriptorType; + foreach (var url in Url.Paths) { - var requiredUrlRouteParameters = this.Url.Parts + var requiredUrlRouteParameters = Url.Parts .Where(p => !ApiUrl.BlackListRouteValues.Contains(p.Key)) .Where(p => p.Value.Required) .Where(p => url.Contains($"{{{p.Value.Name}}}")) @@ -221,23 +237,23 @@ public IEnumerable DescriptorConstructors() ); var doc = $@"/// {url}"; if (requiredUrlRouteParameters.Any()) - { - doc += "\r\n\t\t" + string.Join("\r\n\t\t", requiredUrlRouteParameters.Select(p => $"/// this parameter is required")); - } + doc += "\r\n\t\t" + string.Join("\r\n\t\t", + requiredUrlRouteParameters.Select(p => $"/// this parameter is required")); var generated = $"public {m}({par}) : base({routing})"; - var body = this.IsDocumentRequest ? $"Q(\"routing\", new Routing(() => AutoRouteDocument()));" : string.Empty; + var body = IsDocumentRequest ? $"Q(\"routing\", new Routing(() => AutoRouteDocument()));" : string.Empty; // Add typeof(T) as the default type when only index specified - if ((m == "DeleteByQueryDescriptor" || m == "UpdateByQueryDescriptor") && requiredUrlRouteParameters.Count() == 1 && !string.IsNullOrEmpty(this.RequestTypeGeneric)) + if ((m == "DeleteByQueryDescriptor" || m == "UpdateByQueryDescriptor") && requiredUrlRouteParameters.Count() == 1 + && !string.IsNullOrEmpty(RequestTypeGeneric)) { - var generic = this.RequestTypeGeneric.Replace("<", "").Replace(">", ""); + var generic = RequestTypeGeneric.Replace("<", "").Replace(">", ""); generated = $"public {m}({par}) : base({routing}.Required(\"type\", (Types)typeof({generic})))"; } - if ((m == "SearchShardsDescriptor") && !string.IsNullOrEmpty(this.RequestTypeGeneric)) + if (m == "SearchShardsDescriptor" && !string.IsNullOrEmpty(RequestTypeGeneric)) { - var generic = this.RequestTypeGeneric.Replace("<", "").Replace(">", ""); + var generic = RequestTypeGeneric.Replace("<", "").Replace(">", ""); doc = AppendToSummary(doc, ". Will infer the index from the generic type"); generated = $"public {m}({par}) : base(r => r.Optional(\"index\", (Indices)typeof({generic})))"; } @@ -255,18 +271,20 @@ public IEnumerable DescriptorConstructors() { Generated = generated, Description = doc, - Body = (!body.IsNullOrEmpty() && !body.StartsWith("{")) ? ("=> " + body) : body + Body = !body.IsNullOrEmpty() && !body.StartsWith("{") ? "=> " + body : body }; ctors.Add(c); } - if (IsDocumentPath && !string.IsNullOrEmpty(this.DescriptorTypeGeneric)) + if (IsDocumentPath && !string.IsNullOrEmpty(DescriptorTypeGeneric)) { - var documentPathGeneric = Regex.Replace(this.DescriptorTypeGeneric, @"^]+).*$", "$1"); - var doc = $"/// {this.Url.Path}"; - doc += "\r\n\t\t" + $"/// describes an elasticsearch document of type from which the index, type and id can be inferred"; - var documentRoute = "r=>r.Required(\"index\", document.Self.Index).Required(\"type\", document.Self.Type).Required(\"id\", document.Self.Id)"; + var documentPathGeneric = Regex.Replace(DescriptorTypeGeneric, @"^]+).*$", "$1"); + var doc = $"/// {Url.Path}"; + doc += "\r\n\t\t" + + $"/// describes an elasticsearch document of type from which the index, type and id can be inferred"; + var documentRoute = + "r=>r.Required(\"index\", document.Self.Index).Required(\"type\", document.Self.Type).Required(\"id\", document.Self.Id)"; var documentFromPath = $"partial void DocumentFromPath({documentPathGeneric} document);"; - var autoRoute = this.IsDocumentRequest ? $"Q(\"routing\", new Routing(() => AutoRouteDocument() ?? document.Document));" : string.Empty; + var autoRoute = IsDocumentRequest ? $"Q(\"routing\", new Routing(() => AutoRouteDocument() ?? document.Document));" : string.Empty; var c = new Constructor { AdditionalCode = documentFromPath, @@ -283,13 +301,13 @@ public IEnumerable DescriptorConstructors() private void AddParameterlessIndicesTypesConstructor(List ctors, string m) { - var generic = this.DescriptorTypeGeneric?.Replace("<", "").Replace(">", ""); - var doc = $@"/// {this.Url.Path}"; + var generic = DescriptorTypeGeneric?.Replace("<", "").Replace(">", ""); + var doc = $@"/// {Url.Path}"; var documentRoute = $"r=> r.Required(\"index\", (Indices)typeof({generic})).Required(\"type\", (Types)typeof({generic}))"; var c = new Constructor { Generated = $"public {m}() : base({documentRoute})", Description = doc }; if (string.IsNullOrEmpty(generic)) c = new Constructor { Generated = $"public {m}()", Description = doc }; - c.Body = this.IsDocumentRequest ? $" => Q(\"routing\", new Routing(() => AutoRouteDocument()));" : string.Empty; + c.Body = IsDocumentRequest ? $" => Q(\"routing\", new Routing(() => AutoRouteDocument()));" : string.Empty; ctors.Add(c); } @@ -297,13 +315,14 @@ public IEnumerable GetFluentRouteSetters() { var setters = new List(); if (IsPartless) return setters; + var alwaysGenerate = new[] { "index", "type" }; - var parts = this.Url.Parts + var parts = Url.Parts .Where(p => !ApiUrl.BlackListRouteValues.Contains(p.Key)) .Where(p => !p.Value.Required || alwaysGenerate.Contains(p.Key)) .Where(p => !string.IsNullOrEmpty(p.Value.Name)) .ToList(); - var returnType = this.DescriptorType + this.DescriptorTypeGeneric; + var returnType = DescriptorType + DescriptorTypeGeneric; foreach (var part in parts) { var p = part.Value; @@ -319,7 +338,8 @@ public IEnumerable GetFluentRouteSetters() if (paramName == "metric" || paramName == "watcherStatsMetric") routeValue = "(Metrics)" + paramName; else if (paramName == "indexMetric") routeValue = "(IndexMetrics)indexMetric"; - var code = $"public {returnType} {p.InterfaceName}({ClrParamType(p.ClrTypeName)} {paramName}) => Assign(a=>a.RouteValues.{routeSetter}(\"{p.Name}\", {routeValue}));"; + var code = + $"public {returnType} {p.InterfaceName}({ClrParamType(p.ClrTypeName)} {paramName}) => Assign(a=>a.RouteValues.{routeSetter}(\"{p.Name}\", {routeValue}));"; var xmlDoc = $"///{p.Description}"; setters.Add(new FluentRouteSetter { Code = code, XmlDoc = xmlDoc }); if (paramName == "index" || paramName == "type") @@ -352,19 +372,9 @@ public IEnumerable GetFluentRouteSetters() return setters; } - private string AppendToSummary(string doc, string toAppend) - { - return Regex.Replace( - doc, - @"^(\/\/\/ )(.*?)(<\/summary>)(.*)", - "$1$2" + toAppend + "$3$4"); - } - - private bool IsPartless => this.Url.Parts == null || !this.Url.Parts.Any(); - private bool IsScroll => this.Url.Parts.All(p => p.Key == "scroll_id"); - public bool IndicesAndTypes => AllParts.Count() == 2 && AllParts.All(p => p.Type == "list") && AllParts.All(p => new[] { "index", "type" }.Contains(p.Name)); - public bool IsDocumentPath => AllParts.Count() == 3 && AllParts.All(p => p.Type != "list") && AllParts.All(p => new[] { "index", "type", "id" }.Contains(p.Name)); - public bool IsDocumentRequest => this.IsDocumentPath && this.Url.Params.ContainsKey("routing"); - public IEnumerable AllParts => (this.Url?.Parts?.Values ?? Enumerable.Empty()).Where(p => !string.IsNullOrWhiteSpace(p.Name)); + private string AppendToSummary(string doc, string toAppend) => Regex.Replace( + doc, + @"^(\/\/\/ )(.*?)(<\/summary>)(.*)", + "$1$2" + toAppend + "$3$4"); } } diff --git a/src/CodeGeneration/ApiGenerator/Domain/RestApiSpec.cs b/src/CodeGeneration/ApiGenerator/Domain/RestApiSpec.cs index af98365f6b7..442e9b96ba8 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/RestApiSpec.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/RestApiSpec.cs @@ -14,16 +14,38 @@ public class RestApiSpec private IEnumerable _enumDescriptions; public string Commit { get; set; } - public IDictionary Endpoints { get; set; } public static Dictionary CommonApiQueryParameters { get; set; } + + public IEnumerable CsharpMethodsWithQueryStringInfo => + (from u in Endpoints.Values.SelectMany(v => v.CsharpMethods) + where u.QueryStringParamName != "FluentQueryString" + select u).GroupBy(m => m.QueryStringParamName) + .Select(g => + { + if (g.Count() == 1) return g.First(); + + return g.OrderBy(v => + { + switch (v.HttpMethod.ToUpper()) + { + case "GET": return 1; + default: return 0; + } + }) + .First(); + }); + + public IDictionary Endpoints { get; set; } + public IEnumerable EnumsInTheSpec { get { if (_enumDescriptions != null) return _enumDescriptions; - var queryParamEnums = from m in this.CsharpMethodsWithQueryStringInfo.SelectMany(m => m.Url.Params) + + var queryParamEnums = from m in CsharpMethodsWithQueryStringInfo.SelectMany(m => m.Url.Params) where m.Value.Type == "enum" select new EnumDescription { @@ -31,7 +53,7 @@ public IEnumerable EnumsInTheSpec Options = m.Value.Options }; - var urlParamEnums = from data in this.Endpoints.Values + var urlParamEnums = from data in Endpoints.Values .SelectMany(v => v.CsharpMethods.Select(m => new { m, n = v.CsharpMethodName })) .SelectMany(m => m.m.Parts.Select(part => new { m = m.n, p = part })) let p = data.p @@ -50,24 +72,6 @@ public IEnumerable EnumsInTheSpec return _enumDescriptions; } - } - - - public IEnumerable CsharpMethodsWithQueryStringInfo => - (from u in this.Endpoints.Values.SelectMany(v => v.CsharpMethods) - where u.QueryStringParamName != "FluentQueryString" - select u).GroupBy(m => m.QueryStringParamName).Select(g => - { - if (g.Count() == 1) return g.First(); - return g.OrderBy(v => - { - switch (v.HttpMethod.ToUpper()) - { - case "GET": return 1; - default: return 0; - } - }).First(); - }); } } diff --git a/src/CodeGeneration/ApiGenerator/Extensions.cs b/src/CodeGeneration/ApiGenerator/Extensions.cs index d5d450eb9b1..3cc1a179650 100644 --- a/src/CodeGeneration/ApiGenerator/Extensions.cs +++ b/src/CodeGeneration/ApiGenerator/Extensions.cs @@ -9,18 +9,18 @@ namespace ApiGenerator { public static class Extensions { - public static IEnumerable DistinctBy(this IEnumerable items, Func property) - { - return items.GroupBy(property).Select(x => x.First()); - } - /// /// Removes _ . but not an underscore at the start of the string, unless the string is _all or removeLeadingUnderscore == true. /// private static readonly Regex RemovePunctuationExceptFirstUnderScore = new Regex(@"(?!^_(?!All$))[_\.]"); + + public static IEnumerable DistinctBy(this IEnumerable items, Func property) => + items.GroupBy(property).Select(x => x.First()); + public static string ToPascalCase(this string s, bool removeLeadingUnderscore = false) { if (string.IsNullOrEmpty(s)) return s; + var textInfo = new CultureInfo("en-US").TextInfo; var titleCased = textInfo.ToTitleCase(s.ToLowerInvariant()); var result = RemovePunctuationExceptFirstUnderScore.Replace(titleCased, ""); @@ -28,11 +28,14 @@ public static string ToPascalCase(this string s, bool removeLeadingUnderscore = result = result.TrimStart('_'); return result; } + public static string ToCamelCase(this string s) { if (string.IsNullOrEmpty(s)) return s; + var pascal = s.ToPascalCase(true); if (pascal.Length <= 1) return pascal; + return pascal[0].ToLower() + s.Substring(1); } } diff --git a/src/CodeGeneration/ApiGenerator/Overrides/EndpointOverridesBase.cs b/src/CodeGeneration/ApiGenerator/Overrides/EndpointOverridesBase.cs index cd79fa14a11..54055487b92 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/EndpointOverridesBase.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/EndpointOverridesBase.cs @@ -5,15 +5,14 @@ namespace ApiGenerator.Overrides { - public abstract class EndpointOverridesBase: IEndpointOverrides + public abstract class EndpointOverridesBase : IEndpointOverrides { - public virtual IEnumerable SkipQueryStringParams { get; } = Enumerable.Empty(); - - public virtual IEnumerable RenderPartial { get; } = Enumerable.Empty(); + public virtual IDictionary ObsoleteQueryStringParams { get; set; } = new Dictionary(); public virtual IDictionary RenameQueryStringParams { get; } = new Dictionary(); - public virtual IDictionary ObsoleteQueryStringParams { get; set; } = new Dictionary(); + public virtual IEnumerable RenderPartial { get; } = Enumerable.Empty(); + public virtual IEnumerable SkipQueryStringParams { get; } = Enumerable.Empty(); public virtual CsharpMethod PatchMethod(CsharpMethod method) => method; diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ClearCacheOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ClearCacheOverrides.cs index eeba987d98d..34fe76dca71 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ClearCacheOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ClearCacheOverrides.cs @@ -5,7 +5,7 @@ namespace ApiGenerator.Overrides.Endpoints // ReSharper disable once UnusedMember.Global public class ClearCacheOverrides : EndpointOverridesBase { - public override IEnumerable SkipQueryStringParams => new [] + public override IEnumerable SkipQueryStringParams => new[] { "field_data" //this API declares both field_data and fielddata, this is the odd one out. }; diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ForecastJobOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ForecastJobOverrides.cs index cd10b99de0a..7f02b557c9f 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ForecastJobOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ForecastJobOverrides.cs @@ -10,4 +10,4 @@ public class ForecastJobOverrides : EndpointOverridesBase "expires_in" }; } -} \ No newline at end of file +} diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/IndicesStatsOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/IndicesStatsOverrides.cs index c5176ef3225..54f562ba770 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/IndicesStatsOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/IndicesStatsOverrides.cs @@ -5,7 +5,7 @@ namespace ApiGenerator.Overrides.Endpoints // ReSharper disable once UnusedMember.Global public class IndicesStatsOverrides : EndpointOverridesBase { - public override IEnumerable SkipQueryStringParams => new [] + public override IEnumerable SkipQueryStringParams => new[] { "types" }; diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/MultiTermVectorsOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/MultiTermVectorsOverrides.cs index 53dc0d4ce3b..83628f85cee 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/MultiTermVectorsOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/MultiTermVectorsOverrides.cs @@ -5,7 +5,7 @@ namespace ApiGenerator.Overrides.Endpoints // ReSharper disable once UnusedMember.Global public class MultiTermVectorsOverrides : EndpointOverridesBase { - public override IEnumerable SkipQueryStringParams => new [] + public override IEnumerable SkipQueryStringParams => new[] { "ids" }; diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/NodesHotThreadsOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/NodesHotThreadsOverrides.cs index 344f6e33d69..eabe68bea16 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/NodesHotThreadsOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/NodesHotThreadsOverrides.cs @@ -7,7 +7,7 @@ public class NodesHotThreadsOverrides : EndpointOverridesBase { public override IDictionary RenameQueryStringParams => new Dictionary { - { "type", "thread_type"} + { "type", "thread_type" } }; } } diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/PutIndexTemplateOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/PutIndexTemplateOverrides.cs index abd02915a6a..0e6b40ecb12 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/PutIndexTemplateOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/PutIndexTemplateOverrides.cs @@ -5,7 +5,7 @@ namespace ApiGenerator.Overrides.Endpoints // ReSharper disable once UnusedMember.Global public class PutIndexTemplateOverrides : EndpointOverridesBase { - public override IEnumerable SkipQueryStringParams => new [] + public override IEnumerable SkipQueryStringParams => new[] { "order" }; diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ScrollOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ScrollOverrides.cs index d34c523a6e2..801004d3112 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ScrollOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/ScrollOverrides.cs @@ -5,7 +5,7 @@ namespace ApiGenerator.Overrides.Endpoints // ReSharper disable once UnusedMember.Global public class ScrollOverrides : EndpointOverridesBase { - public override IEnumerable SkipQueryStringParams => new [] + public override IEnumerable SkipQueryStringParams => new[] { "scroll_id", "scroll" }; diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/SearchOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/SearchOverrides.cs index 690db3fecb1..e6acff9afde 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/SearchOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/SearchOverrides.cs @@ -5,7 +5,7 @@ namespace ApiGenerator.Overrides.Endpoints // ReSharper disable once UnusedMember.Global public class SearchOverrides : EndpointOverridesBase { - public override IEnumerable SkipQueryStringParams => new [] + public override IEnumerable SkipQueryStringParams => new[] { "size", "from", diff --git a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/UpdateOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/UpdateOverrides.cs index 132c347a481..29292e03795 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/UpdateOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/Endpoints/UpdateOverrides.cs @@ -5,7 +5,7 @@ namespace ApiGenerator.Overrides.Endpoints // ReSharper disable once UnusedMember.Global public class UpdateOverrides : EndpointOverridesBase { - public override IEnumerable SkipQueryStringParams => new [] + public override IEnumerable SkipQueryStringParams => new[] { "fields", "_source_include", "_source_exclude" }; diff --git a/src/CodeGeneration/ApiGenerator/Overrides/GlobalOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/GlobalOverrides.cs index b11d09cf4fe..558551ad24b 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/GlobalOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/GlobalOverrides.cs @@ -1,42 +1,47 @@ -using System; using System.Collections.Generic; -using ApiGenerator.Overrides.Descriptors; namespace ApiGenerator.Overrides { public class GlobalOverrides : EndpointOverridesBase { - public override IEnumerable RenderPartial => new[] + public IDictionary> ObsoleteEnumMembers { get; set; } = new Dictionary> { - "stored_fields", - "script_fields", - "docvalue_fields" + { + "NodesStatsIndexMetric", + new Dictionary { { "suggest", "As of 5.0 this option always returned an empty object in the response" } } + }, + { + "IndicesStatsMetric", + new Dictionary { { "suggest", "Suggest stats have folded under the search stats, this alias will be removed" } } + } }; - public IDictionary> ObsoleteEnumMembers { get; set; } = new Dictionary> + + public override IDictionary ObsoleteQueryStringParams { get; set; } = new Dictionary { - { "NodesStatsIndexMetric", new Dictionary{{"suggest", "As of 5.0 this option always returned an empty object in the response"}}}, - { "IndicesStatsMetric", new Dictionary{{"suggest", "Suggest stats have folded under the search stats, this alias will be removed"}}} + { "parent", "the parent parameter has been deprecated from elasticsearch, please use routing instead directly." }, + { "update_all_types", "Elasticsearch 6.x only allows a single type per index so this parameter is now useless" }, + { "copy_settings", "Elasticsearch 6.4 will throw an exception if this is turned off see elastic/elasticsearch#30404" } }; public override IDictionary RenameQueryStringParams { get; } = new Dictionary { - {"_source", "source_enabled"}, - {"_source_include", "source_include"}, - {"_source_exclude", "source_exclude"}, - {"docvalue_fields", "doc_value_fields"}, - {"q", "query_on_query_string"}, + { "_source", "source_enabled" }, + { "_source_include", "source_include" }, + { "_source_exclude", "source_exclude" }, + { "docvalue_fields", "doc_value_fields" }, + { "q", "query_on_query_string" }, //make cat parameters more descriptive - {"h", "Headers"}, - {"s", "sort_by_columns"}, - {"v", "verbose"}, - {"ts", "include_timestamp"}, + { "h", "Headers" }, + { "s", "sort_by_columns" }, + { "v", "verbose" }, + { "ts", "include_timestamp" }, }; - public override IDictionary ObsoleteQueryStringParams { get; set; } = new Dictionary + public override IEnumerable RenderPartial => new[] { - { "parent", "the parent parameter has been deprecated from elasticsearch, please use routing instead directly."}, - { "update_all_types", "Elasticsearch 6.x only allows a single type per index so this parameter is now useless"}, - { "copy_settings", "Elasticsearch 6.4 will throw an exception if this is turned off see elastic/elasticsearch#30404"} + "stored_fields", + "script_fields", + "docvalue_fields" }; public override IEnumerable SkipQueryStringParams { get; } = new[] diff --git a/src/CodeGeneration/ApiGenerator/Overrides/IEndpointOverrides.cs b/src/CodeGeneration/ApiGenerator/Overrides/IEndpointOverrides.cs index 2889a694637..70b54934306 100644 --- a/src/CodeGeneration/ApiGenerator/Overrides/IEndpointOverrides.cs +++ b/src/CodeGeneration/ApiGenerator/Overrides/IEndpointOverrides.cs @@ -1,5 +1,4 @@ -using System.Collections; -using System.Collections.Generic; +using System.Collections.Generic; using ApiGenerator.Domain; namespace ApiGenerator.Overrides.Descriptors @@ -10,26 +9,26 @@ namespace ApiGenerator.Overrides.Descriptors public interface IEndpointOverrides { /// - /// Sometimes params can be defined on the body as well as on the querystring - /// We favor specifying params on the body so here we can specify params we don't want on the querystring. + /// A map of key -> obsolete message for properties in the spec that should not be used any longer /// - IEnumerable SkipQueryStringParams { get; } + IDictionary ObsoleteQueryStringParams { get; set; } /// - /// Force these be rendered as interface properties only, so that they'd have to be implemented manually - /// and become part of the body. This only takes affect on requests that take a body (e.g not GET or HEAD). + /// Override how the query param name is exposed to the client. /// - IEnumerable RenderPartial { get; } + IDictionary RenameQueryStringParams { get; } /// - /// Override how the query param name is exposed to the client. + /// Force these be rendered as interface properties only, so that they'd have to be implemented manually + /// and become part of the body. This only takes affect on requests that take a body (e.g not GET or HEAD). /// - IDictionary RenameQueryStringParams { get; } + IEnumerable RenderPartial { get; } /// - /// A map of key -> obsolete message for properties in the spec that should not be used any longer + /// Sometimes params can be defined on the body as well as on the querystring + /// We favor specifying params on the body so here we can specify params we don't want on the querystring. /// - IDictionary ObsoleteQueryStringParams { get; set; } + IEnumerable SkipQueryStringParams { get; } /// /// Patch the CSharp method diff --git a/src/CodeGeneration/ApiGenerator/Program.cs b/src/CodeGeneration/ApiGenerator/Program.cs index d45640a127e..18793411d0a 100644 --- a/src/CodeGeneration/ApiGenerator/Program.cs +++ b/src/CodeGeneration/ApiGenerator/Program.cs @@ -7,10 +7,10 @@ public static class Program { private static readonly string DownloadBranch = "master"; - static void Main(string[] args) + private static void Main(string[] args) { - bool redownloadCoreSpecification = false; - string downloadBranch = DownloadBranch; + var redownloadCoreSpecification = false; + var downloadBranch = DownloadBranch; var answer = "invalid"; while (answer != "y" && answer != "n" && answer != "") @@ -30,9 +30,7 @@ static void Main(string[] args) { // read last downloaded branch from file. if (File.Exists(CodeConfiguration.LastDownloadedVersionFile)) - { downloadBranch = File.ReadAllText(CodeConfiguration.LastDownloadedVersionFile); - } } if (string.IsNullOrEmpty(downloadBranch)) @@ -41,7 +39,8 @@ static void Main(string[] args) if (redownloadCoreSpecification) RestSpecDownloader.Download(downloadBranch); - ApiGenerator.Generate(downloadBranch, "Core", "Graph", "License", "Security", "Watcher", "Info", "MachineLearning", "Migration", "Sql", "Rollup"); + ApiGenerator.Generate(downloadBranch, "Core", "Graph", "License", "Security", "Watcher", "Info", "MachineLearning", "Migration", "Sql", + "Rollup"); } } } diff --git a/src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs b/src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs index b43bb6f99db..395bfa508be 100644 --- a/src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs +++ b/src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs @@ -10,21 +10,13 @@ namespace ApiGenerator { public class RestSpecDownloader { - public static RestSpecDownloader Download(string branch) => new RestSpecDownloader(branch); + private static readonly ProgressBarOptions MainProgressBarOptions = new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray }; private static readonly Dictionary OnlineSpecifications = new Dictionary { { "Core", "https://github.com/elastic/elasticsearch/tree/{version}/rest-api-spec/src/main/resources/rest-api-spec/api" }, }; - private class Specification - { - public string FolderOnDisk { get; set; } - public string GithubListingUrl { get; set; } - public string Branch { get; set; } - public string GithubDownloadUrl(string file) => this.GithubListingUrl.Replace("github.com", "raw.githubusercontent.com").Replace("tree/", "") + "/" + file; - } - private static readonly ProgressBarOptions MainProgressBarOptions = new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray }; private static readonly ProgressBarOptions SubProgressBarOptions = new ProgressBarOptions { ForegroundColor = ConsoleColor.Cyan, @@ -54,6 +46,8 @@ private RestSpecDownloader(string branch) File.WriteAllText(CodeConfiguration.LastDownloadedVersionFile, branch); } + public static RestSpecDownloader Download(string branch) => new RestSpecDownloader(branch); + private void DownloadJsonDefinitions(Specification spec, IProgressBar pbar) { using (var client = new WebClient()) @@ -98,5 +92,15 @@ private void WriteToEndpointsFolder(string folder, string filename, string conte if (!Directory.Exists(f)) Directory.CreateDirectory(f); File.WriteAllText(f + "\\" + filename, contents); } + + private class Specification + { + public string Branch { get; set; } + public string FolderOnDisk { get; set; } + public string GithubListingUrl { get; set; } + + public string GithubDownloadUrl(string file) => + GithubListingUrl.Replace("github.com", "raw.githubusercontent.com").Replace("tree/", "") + "/" + file; + } } } diff --git a/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs b/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs index 820df6e4e94..533861a42cc 100644 --- a/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs +++ b/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs @@ -1,20 +1,14 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; -using System.Reflection.PortableExecutable; using System.Text; using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; using AsciiDocNet; -using DocGenerator.Walkers; using DocGenerator.XmlDocs; using Elasticsearch.Net; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Nest; using NuDoq; using Container = AsciiDocNet.Container; @@ -29,15 +23,15 @@ namespace DocGenerator.AsciiDoc /// public class GeneratedAsciidocVisitor : NoopVisitor { - private static readonly Dictionary Ids = new Dictionary(); - - private readonly FileInfo _source; + private static readonly Dictionary Ids = new Dictionary(); private readonly FileInfo _destination; private readonly Dictionary _projects; - private int _topSectionTitleLevel; + + private readonly FileInfo _source; private Document _document; private Document _newDocument; private bool _topLevel = true; + private int _topSectionTitleLevel; public GeneratedAsciidocVisitor(FileInfo source, FileInfo destination, Dictionary projects) { @@ -61,35 +55,22 @@ public override void VisitDocument(Document document) DocType = document.DocType }; - foreach (var authorInfo in document.Authors) - { - _newDocument.Authors.Add(authorInfo); - } + foreach (var authorInfo in document.Authors) _newDocument.Authors.Add(authorInfo); RemoveDocDirectoryAttribute(_newDocument); RemoveDocDirectoryAttribute(document); - foreach (var attributeEntry in document.Attributes) - { - _newDocument.Attributes.Add(attributeEntry); - } + foreach (var attributeEntry in document.Attributes) _newDocument.Attributes.Add(attributeEntry); if (document.Attributes.All(a => a.Name != "ref_current")) - { _newDocument.Attributes.Add(new AttributeEntry("ref_current", $"https://www.elastic.co/guide/en/elasticsearch/reference/{Program.DocVersion}")); - } var github = "https://github.com/elastic/elasticsearch-net"; - if (document.Attributes.All(a => a.Name != "github")) - { - _newDocument.Attributes.Add(new AttributeEntry("github", github)); - } + if (document.Attributes.All(a => a.Name != "github")) _newDocument.Attributes.Add(new AttributeEntry("github", github)); if (document.Attributes.All(a => a.Name != "nuget")) - { _newDocument.Attributes.Add(new AttributeEntry("nuget", "https://www.nuget.org/packages")); - } var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", $"{github}/tree/{Program.BranchName}/src/Tests/Tests/"); @@ -98,15 +79,15 @@ public override void VisitDocument(Document document) { Style = CommentStyle.MultiLine, Text = $"IMPORTANT NOTE\r\n==============\r\nThis file has been generated from {originalFile}. \r\n" + - "If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,\r\n" + - "please modify the original csharp file found at the link and submit the PR with that change. Thanks!" + "If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,\r\n" + + "please modify the original csharp file found at the link and submit the PR with that change. Thanks!" }); _topSectionTitleLevel = _source.Directory.Name.Equals("request", StringComparison.OrdinalIgnoreCase) && - _source.Directory.Parent != null && - _source.Directory.Parent.Name.Equals("search", StringComparison.OrdinalIgnoreCase) - ? 2 - : 3; + _source.Directory.Parent != null && + _source.Directory.Parent.Name.Equals("search", StringComparison.OrdinalIgnoreCase) + ? 2 + : 3; // see if the document has some kind of top level title and add one with an anchor if not. // Used to add titles to *Usage test files @@ -118,7 +99,7 @@ public override void VisitDocument(Document document) if (sectionTitle != null && sectionTitle.Level <= 3) _topSectionTitleLevel = sectionTitle.Level; - if (sectionTitle == null || (sectionTitle.Level > 3)) + if (sectionTitle == null || sectionTitle.Level > 3) { var id = Path.GetFileNameWithoutExtension(_destination.Name); var title = id.LowercaseHyphenToPascal(); @@ -136,7 +117,7 @@ public override void VisitContainer(Container elements) if (_topLevel) { _topLevel = false; - for (int index = 0; index < elements.Count; index++) + for (var index = 0; index < elements.Count; index++) { var element = elements[index]; var source = element as Source; @@ -144,10 +125,7 @@ public override void VisitContainer(Container elements) if (source != null) { // remove empty source blocks - if (string.IsNullOrWhiteSpace(source.Text)) - { - continue; - } + if (string.IsNullOrWhiteSpace(source.Text)) continue; var method = source.Attributes.OfType().FirstOrDefault(a => a.Name == "method"); if (method == null) @@ -176,9 +154,7 @@ public override void VisitContainer(Container elements) case "queryfluent": case "fluentaggs": if (!LastSectionTitleMatches(text => text.StartsWith("Fluent DSL", StringComparison.OrdinalIgnoreCase))) - { _newDocument.Add(CreateSubsectionTitle("Fluent DSL example")); - } _newDocument.Add(source); break; @@ -191,9 +167,7 @@ public override void VisitContainer(Container elements) case "expectresponse": // Don't add the Handlng Response section title if it was the last title (it might be defined in the doc already) if (!LastSectionTitleMatches(text => text.Equals("Handling responses", StringComparison.OrdinalIgnoreCase))) - { _newDocument.Add(CreateSubsectionTitle("Handling Responses")); - } _newDocument.Add(source); break; default: @@ -202,9 +176,7 @@ public override void VisitContainer(Container elements) } } else - { _newDocument.Add(element); - } } } @@ -216,10 +188,7 @@ public override void VisitSource(Source source) // remove method attributes as the elastic doc generation doesn't like them; it // expects a linenumbering in the index 2 position of a source block var methodAttribute = source.Attributes.FirstOrDefault(a => a.Name == "method"); - if (methodAttribute != null) - { - source.Attributes.Remove(methodAttribute); - } + if (methodAttribute != null) source.Attributes.Remove(methodAttribute); // Replace tabs with spaces and remove C# comment escaping from callouts // (elastic docs generation does not like this callout format) @@ -231,13 +200,10 @@ public override void VisitSource(Source source) public override void VisitSectionTitle(SectionTitle sectionTitle) { // Generate an anchor for all top level section titles - if (this._document.IndexOf(sectionTitle) == 0 && !sectionTitle.Attributes.HasAnchor) + if (_document.IndexOf(sectionTitle) == 0 && !sectionTitle.Attributes.HasAnchor) { var builder = new StringBuilder(); - using (var writer = new AsciiDocVisitor(new StringWriter(builder))) - { - writer.VisitInlineContainer(sectionTitle); - } + using (var writer = new AsciiDocVisitor(new StringWriter(builder))) writer.VisitInlineContainer(sectionTitle); var title = builder.ToString().PascalToHyphen(); sectionTitle.Attributes.Add(new Anchor(title)); @@ -248,9 +214,7 @@ public override void VisitSectionTitle(SectionTitle sectionTitle) // Check for duplicate ids across documents var key = sectionTitle.Attributes.Anchor.Id; if (Ids.TryGetValue(key, out var existingFile)) - { throw new Exception($"duplicate id {key} in {_destination.FullName}. Id already exists in {existingFile}"); - } Ids.Add(key, _destination.FullName); } @@ -261,6 +225,7 @@ public override void VisitSectionTitle(SectionTitle sectionTitle) public override void VisitAttributeEntry(AttributeEntry attributeEntry) { if (attributeEntry.Name != "xml-docs") return; + //true when running from the IDE, build/output might have not been created string configuration = null; if (Program.BuildOutputPath.Contains("src")) @@ -274,6 +239,7 @@ string XmlFile(string project) { if (configuration == null) return Path.Combine(Program.BuildOutputPath, project, "netstandard2.0", $"{project}.XML"); + return Path.Combine(Program.BuildOutputPath, project, "bin", configuration, "netstandard2.0", $"{project}.XML"); } @@ -328,10 +294,7 @@ string XmlFile(string project) diagnostic.Severity == DiagnosticSeverity.Error); var builder = new StringBuilder($"Unable to emit compilation for: {assemblyName}"); - foreach (var diagnostic in failures) - { - builder.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}"); - } + foreach (var diagnostic in failures) builder.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}"); builder.AppendLine(new string('-', 30)); @@ -348,10 +311,7 @@ string XmlFile(string project) if (visitor.LabeledListItems.Any()) { var labeledList = new LabeledList(); - foreach (var item in visitor.LabeledListItems.OrderBy(l => l.Label)) - { - labeledList.Items.Add(item); - } + foreach (var item in visitor.LabeledListItems.OrderBy(l => l.Label)) labeledList.Items.Add(item); _newDocument.Insert(_newDocument.IndexOf(attributeEntry), labeledList); } @@ -360,10 +320,7 @@ string XmlFile(string project) private void RemoveDocDirectoryAttribute(Document document) { var directoryAttribute = document.Attributes.FirstOrDefault(a => a.Name == "docdir"); - if (directoryAttribute != null) - { - document.Attributes.Remove(directoryAttribute); - } + if (directoryAttribute != null) document.Attributes.Remove(directoryAttribute); } private bool LastSectionTitleMatches(Func predicate) @@ -372,10 +329,7 @@ private bool LastSectionTitleMatches(Func predicate) if (lastSectionTitle != null && lastSectionTitle.Level == _topSectionTitleLevel + 1) { var builder = new StringBuilder(); - using (var visitor = new AsciiDocVisitor(new StringWriter(builder))) - { - visitor.VisitInlineContainer(lastSectionTitle); - } + using (var visitor = new AsciiDocVisitor(new StringWriter(builder))) visitor.VisitInlineContainer(lastSectionTitle); return predicate(builder.ToString()); } diff --git a/src/CodeGeneration/DocGenerator/AsciiDoc/RawAsciidocVisitor.cs b/src/CodeGeneration/DocGenerator/AsciiDoc/RawAsciidocVisitor.cs index bbd6ed51c01..31be614a28f 100644 --- a/src/CodeGeneration/DocGenerator/AsciiDoc/RawAsciidocVisitor.cs +++ b/src/CodeGeneration/DocGenerator/AsciiDoc/RawAsciidocVisitor.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -12,8 +11,8 @@ namespace DocGenerator.AsciiDoc /// public class RawAsciidocVisitor : NoopVisitor { - private readonly FileInfo _source; private readonly FileInfo _destination; + private readonly FileInfo _source; private Document _document; public RawAsciidocVisitor(FileInfo source, FileInfo destination) @@ -27,10 +26,7 @@ public override void VisitDocument(Document document) _document = document; var directoryAttribute = document.Attributes.FirstOrDefault(a => a.Name == "docdir"); - if (directoryAttribute != null) - { - document.Attributes.Remove(directoryAttribute); - } + if (directoryAttribute != null) document.Attributes.Remove(directoryAttribute); var github = "https://github.com/elastic/elasticsearch-net"; var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", $"{github}/tree/master/src/Tests/Tests/"); @@ -38,8 +34,8 @@ public override void VisitDocument(Document document) { Style = CommentStyle.MultiLine, Text = $"IMPORTANT NOTE\r\n==============\r\nThis file has been generated from {originalFile}. \r\n" + - "If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,\r\n" + - "please modify the original csharp file found at the link and submit the PR with that change. Thanks!" + "If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,\r\n" + + "please modify the original csharp file found at the link and submit the PR with that change. Thanks!" }); base.VisitDocument(document); @@ -56,7 +52,8 @@ public override void VisitAttributeEntry(AttributeEntry attributeEntry) foreach (var directory in directories) { - foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.OutputDirPath, directory), "*.asciidoc", SearchOption.AllDirectories)) + foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.OutputDirPath, directory), "*.asciidoc", + SearchOption.AllDirectories)) { var fileInfo = new FileInfo(file); var referencedFileUri = new Uri(fileInfo.FullName); @@ -69,12 +66,9 @@ public override void VisitAttributeEntry(AttributeEntry attributeEntry) ++counter; } else - { _document.Add(include); - } } } - } else if (attributeEntry.Name == "anchor-list") { @@ -84,7 +78,8 @@ public override void VisitAttributeEntry(AttributeEntry attributeEntry) foreach (var directory in directories) { - foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.OutputDirPath, directory), "*.asciidoc", SearchOption.AllDirectories)) + foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.OutputDirPath, directory), "*.asciidoc", + SearchOption.AllDirectories)) { var fileInfo = new FileInfo(file); var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name); @@ -97,13 +92,9 @@ public override void VisitAttributeEntry(AttributeEntry attributeEntry) } if (attributeEntry.Parent != null) - { attributeEntry.Parent.Insert(attributeEntry.Parent.IndexOf(attributeEntry) + 1, list); - } else - { _document.Add(list); - } } base.VisitAttributeEntry(attributeEntry); diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs index 9ac58dbc13e..0a1b44035d1 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; @@ -34,131 +36,114 @@ namespace DocGenerator.Buildalyzer { - public class AnalyzerManager - { - private readonly Dictionary _projects = new Dictionary(); - - public IReadOnlyDictionary Projects => _projects; - - internal ILogger ProjectLogger { get; } - - internal LoggerVerbosity LoggerVerbosity { get; } - - public string SolutionDirectory { get; } - - public AnalyzerManager(ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) - : this(null, null, loggerFactory, loggerVerbosity) - { - } - - public AnalyzerManager(TextWriter logWriter, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) - : this(null, logWriter, loggerVerbosity) - { - } - - public AnalyzerManager(string solutionFilePath, string[] projects, ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) - { - LoggerVerbosity = loggerVerbosity; - ProjectLogger = loggerFactory?.CreateLogger(); - - if (solutionFilePath != null) - { - solutionFilePath = ValidatePath(solutionFilePath, true); - SolutionDirectory = Path.GetDirectoryName(solutionFilePath); - GetProjectsInSolution(solutionFilePath, projects); - } - } - - public AnalyzerManager(string solutionFilePath, TextWriter logWriter, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) - { - LoggerVerbosity = loggerVerbosity; - if (logWriter != null) - { - LoggerFactory loggerFactory = new LoggerFactory(); - loggerFactory.AddProvider(new TextWriterLoggerProvider(logWriter)); - ProjectLogger = loggerFactory.CreateLogger(); - } - - if (solutionFilePath != null) - { - solutionFilePath = ValidatePath(solutionFilePath, true); - SolutionDirectory = Path.GetDirectoryName(solutionFilePath); - GetProjectsInSolution(solutionFilePath); - } - } - - private void GetProjectsInSolution(string solutionFilePath, string[] projects = null) - { - projects = projects ?? new string[] { }; - var supportedType = new[] - { - SolutionProjectType.KnownToBeMSBuildFormat, - SolutionProjectType.WebProject - }; - - SolutionFile solution = SolutionFile.Parse(solutionFilePath); - foreach(ProjectInSolution project in solution.ProjectsInOrder) - { - if (!supportedType.Contains(project.ProjectType)) continue; - if (projects.Length > 0 && !projects.Contains(project.ProjectName)) continue; - GetProject(project.AbsolutePath); - } - } - - public ProjectAnalyzer GetProject(string projectFilePath) - { - if (projectFilePath == null) - { - throw new ArgumentNullException(nameof(projectFilePath)); - } - - // Normalize as .sln uses backslash regardless of OS the sln is created on - projectFilePath = projectFilePath.Replace('\\', Path.DirectorySeparatorChar); - projectFilePath = ValidatePath(projectFilePath, true); - if (_projects.TryGetValue(projectFilePath, out ProjectAnalyzer project)) - { - return project; - } - project = new ProjectAnalyzer(this, projectFilePath); - _projects.Add(projectFilePath, project); - return project; - } - - public ProjectAnalyzer GetProject(string projectFilePath, XDocument projectDocument) - { - if (projectFilePath == null) - { - throw new ArgumentNullException(nameof(projectFilePath)); - } - if (projectDocument == null) - { - throw new ArgumentNullException(nameof(projectDocument)); - } - - // Normalize as .sln uses backslash regardless of OS the sln is created on - projectFilePath = projectFilePath.Replace('\\', Path.DirectorySeparatorChar); - projectFilePath = ValidatePath(projectFilePath, false); - if (_projects.TryGetValue(projectFilePath, out ProjectAnalyzer project)) - { - return project; - } - project = new ProjectAnalyzer(this, projectFilePath, projectDocument); - _projects.Add(projectFilePath, project); - return project; - } - - private static string ValidatePath(string path, bool checkExists) - { - if (path == null) - { - throw new ArgumentNullException(nameof(path)); - } - path = Path.GetFullPath(path); // Normalize the path - if (checkExists && !File.Exists(path)) - { - throw new ArgumentException($"The path {path} could not be found."); - } - return path; - } - } + public class AnalyzerManager + { + private readonly Dictionary _projects = new Dictionary(); + + public AnalyzerManager(ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) + : this(null, null, loggerFactory, loggerVerbosity) { } + + public AnalyzerManager(TextWriter logWriter, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) + : this(null, logWriter, loggerVerbosity) { } + + public AnalyzerManager(string solutionFilePath, string[] projects, ILoggerFactory loggerFactory = null, + LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal + ) + { + LoggerVerbosity = loggerVerbosity; + ProjectLogger = loggerFactory?.CreateLogger(); + + if (solutionFilePath != null) + { + solutionFilePath = ValidatePath(solutionFilePath, true); + SolutionDirectory = Path.GetDirectoryName(solutionFilePath); + GetProjectsInSolution(solutionFilePath, projects); + } + } + + public AnalyzerManager(string solutionFilePath, TextWriter logWriter, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) + { + LoggerVerbosity = loggerVerbosity; + if (logWriter != null) + { + var loggerFactory = new LoggerFactory(); + loggerFactory.AddProvider(new TextWriterLoggerProvider(logWriter)); + ProjectLogger = loggerFactory.CreateLogger(); + } + + if (solutionFilePath != null) + { + solutionFilePath = ValidatePath(solutionFilePath, true); + SolutionDirectory = Path.GetDirectoryName(solutionFilePath); + GetProjectsInSolution(solutionFilePath); + } + } + + public IReadOnlyDictionary Projects => _projects; + + public string SolutionDirectory { get; } + + internal LoggerVerbosity LoggerVerbosity { get; } + + internal ILogger ProjectLogger { get; } + + private void GetProjectsInSolution(string solutionFilePath, string[] projects = null) + { + projects = projects ?? new string[] { }; + var supportedType = new[] + { + SolutionProjectType.KnownToBeMSBuildFormat, + SolutionProjectType.WebProject + }; + + var solution = SolutionFile.Parse(solutionFilePath); + foreach (var project in solution.ProjectsInOrder) + { + if (!supportedType.Contains(project.ProjectType)) continue; + if (projects.Length > 0 && !projects.Contains(project.ProjectName)) continue; + + GetProject(project.AbsolutePath); + } + } + + public ProjectAnalyzer GetProject(string projectFilePath) + { + if (projectFilePath == null) throw new ArgumentNullException(nameof(projectFilePath)); + + // Normalize as .sln uses backslash regardless of OS the sln is created on + projectFilePath = projectFilePath.Replace('\\', Path.DirectorySeparatorChar); + projectFilePath = ValidatePath(projectFilePath, true); + if (_projects.TryGetValue(projectFilePath, out var project)) return project; + + project = new ProjectAnalyzer(this, projectFilePath); + _projects.Add(projectFilePath, project); + return project; + } + + public ProjectAnalyzer GetProject(string projectFilePath, XDocument projectDocument) + { + if (projectFilePath == null) throw new ArgumentNullException(nameof(projectFilePath)); + + if (projectDocument == null) throw new ArgumentNullException(nameof(projectDocument)); + + // Normalize as .sln uses backslash regardless of OS the sln is created on + projectFilePath = projectFilePath.Replace('\\', Path.DirectorySeparatorChar); + projectFilePath = ValidatePath(projectFilePath, false); + if (_projects.TryGetValue(projectFilePath, out var project)) return project; + + project = new ProjectAnalyzer(this, projectFilePath, projectDocument); + _projects.Add(projectFilePath, project); + return project; + } + + private static string ValidatePath(string path, bool checkExists) + { + if (path == null) throw new ArgumentNullException(nameof(path)); + + path = Path.GetFullPath(path); // Normalize the path + if (checkExists && !File.Exists(path)) throw new ArgumentException($"The path {path} could not be found."); + + return path; + } + } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManagerExtensions.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManagerExtensions.cs index bd80736f010..663953b4a4b 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManagerExtensions.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManagerExtensions.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using Microsoft.CodeAnalysis; @@ -30,11 +32,8 @@ public static class AnalyzerManagerExtensions { public static AdhocWorkspace GetWorkspace(this AnalyzerManager manager) { - AdhocWorkspace workspace = new AdhocWorkspace(); - foreach (ProjectAnalyzer project in manager.Projects.Values) - { - project.AddToWorkspace(workspace); - } + var workspace = new AdhocWorkspace(); + foreach (var project in manager.Projects.Values) project.AddToWorkspace(workspace); return workspace; } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/BuildEnvironment.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/BuildEnvironment.cs index ed90e292e8c..75014c96f44 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/BuildEnvironment.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/BuildEnvironment.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System.Collections.Generic; @@ -62,13 +64,8 @@ public virtual void SetEnvironmentVars(IReadOnlyDictionary globa public virtual void UnsetEnvironmentVars() { if (_oldMsBuildExtensionsPath != null) - { System.Environment.SetEnvironmentVariable(MsBuildProperties.MSBuildExtensionsPath, _oldMsBuildExtensionsPath); - } - if (_oldMsBuildSdksPath != null) - { - System.Environment.SetEnvironmentVariable(MsBuildProperties.MSBuildSDKsPath, _oldMsBuildSdksPath); - } + if (_oldMsBuildSdksPath != null) System.Environment.SetEnvironmentVariable(MsBuildProperties.MSBuildSDKsPath, _oldMsBuildSdksPath); } } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/CoreEnvironment.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/CoreEnvironment.cs index fc5a5243006..15b0a37c6c5 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/CoreEnvironment.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/CoreEnvironment.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System.Collections.Generic; @@ -31,25 +33,25 @@ namespace DocGenerator.Buildalyzer.Environment // https://github.com/OmniSharp/omnisharp-roslyn/blob/78ccc8b4376c73da282a600ac6fb10fce8620b52/src/OmniSharp.Abstractions/Services/DotNetCliService.cs internal class CoreEnvironment : BuildEnvironment { - public string ToolsPath { get; } - public string ExtensionsPath { get; } - public string SDKsPath { get; } - public string RoslynTargetsPath { get; } - public CoreEnvironment(string projectPath) { - string dotnetPath = DotnetPathResolver.ResolvePath(projectPath); + var dotnetPath = DotnetPathResolver.ResolvePath(projectPath); ToolsPath = dotnetPath; ExtensionsPath = dotnetPath; SDKsPath = Path.Combine(dotnetPath, "Sdks"); RoslynTargetsPath = Path.Combine(dotnetPath, "Roslyn"); } + public string ExtensionsPath { get; } + public string RoslynTargetsPath { get; } + public string SDKsPath { get; } + public string ToolsPath { get; } + public override string GetToolsPath() => ToolsPath; public override Dictionary GetGlobalProperties(string solutionDir) { - Dictionary globalProperties = base.GetGlobalProperties(solutionDir); + var globalProperties = base.GetGlobalProperties(solutionDir); globalProperties.Add(MsBuildProperties.MSBuildExtensionsPath, ExtensionsPath); globalProperties.Add(MsBuildProperties.MSBuildSDKsPath, SDKsPath); globalProperties.Add(MsBuildProperties.RoslynTargetsPath, RoslynTargetsPath); diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/DotnetPathResolver.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/DotnetPathResolver.cs index a89a5448499..4fd19c9c489 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/DotnetPathResolver.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/DotnetPathResolver.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; @@ -31,23 +33,20 @@ namespace DocGenerator.Buildalyzer.Environment { internal static class DotnetPathResolver { - const string DOTNET_CLI_UI_LANGUAGE = nameof(DOTNET_CLI_UI_LANGUAGE); + private const string DOTNET_CLI_UI_LANGUAGE = nameof(DOTNET_CLI_UI_LANGUAGE); + private static string BasePath = null; private static readonly object BasePathLock = new object(); - private static string BasePath = null; public static string ResolvePath(string projectPath) { - lock(BasePathLock) + lock (BasePathLock) { - if(BasePath != null) - { - return BasePath; - } + if (BasePath != null) return BasePath; // Need to rety calling "dotnet --info" and do a hacky timeout for the process otherwise it occasionally locks up during testing (and possibly in the field) - List lines = GetInfo(projectPath); - int retry = 0; + var lines = GetInfo(projectPath); + var retry = 0; do { lines = GetInfo(projectPath); @@ -63,35 +62,33 @@ private static List GetInfo(string projectPath) { // Ensure that we set the DOTNET_CLI_UI_LANGUAGE environment variable to "en-US" before // running 'dotnet --info'. Otherwise, we may get localized results. - string originalCliLanguage = System.Environment.GetEnvironmentVariable(DOTNET_CLI_UI_LANGUAGE); + var originalCliLanguage = System.Environment.GetEnvironmentVariable(DOTNET_CLI_UI_LANGUAGE); System.Environment.SetEnvironmentVariable(DOTNET_CLI_UI_LANGUAGE, "en-US"); try { // Create the process info - Process process = new Process(); + var process = new Process(); process.StartInfo.FileName = "dotnet"; process.StartInfo.Arguments = "--info"; - process.StartInfo.WorkingDirectory = Path.GetDirectoryName(projectPath); // global.json may change the version, so need to set working directory + process.StartInfo.WorkingDirectory = + Path.GetDirectoryName(projectPath); // global.json may change the version, so need to set working directory process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; // Capture output - List lines = new List(); + var lines = new List(); process.StartInfo.RedirectStandardOutput = true; process.OutputDataReceived += (s, e) => lines.Add(e.Data); // Execute the process process.Start(); process.BeginOutputReadLine(); - Stopwatch sw = new Stopwatch(); + var sw = new Stopwatch(); sw.Start(); while (!process.HasExited) { - if (sw.ElapsedMilliseconds > 4000) - { - break; - } + if (sw.ElapsedMilliseconds > 4000) break; } sw.Stop(); process.Close(); @@ -105,36 +102,27 @@ private static List GetInfo(string projectPath) private static string ParseBasePath(List lines) { - if (lines == null || lines.Count == 0) - { - throw new InvalidOperationException("Could not get results from `dotnet --info` call"); - } + if (lines == null || lines.Count == 0) throw new InvalidOperationException("Could not get results from `dotnet --info` call"); - foreach (string line in lines) + foreach (var line in lines) { - int colonIndex = line.IndexOf(':'); + var colonIndex = line.IndexOf(':'); if (colonIndex >= 0 - && line.Substring(0, colonIndex).Trim().Equals("Base Path", StringComparison.OrdinalIgnoreCase)) + && line.Substring(0, colonIndex).Trim().Equals("Base Path", StringComparison.OrdinalIgnoreCase)) { - string basePath = line.Substring(colonIndex + 1).Trim(); + var basePath = line.Substring(colonIndex + 1).Trim(); // Make sure the base path matches the runtime architecture if on Windows // Note that this only works for the default installation locations under "Program Files" if (basePath.Contains(@"\Program Files\") && !System.Environment.Is64BitProcess) { - string newBasePath = basePath.Replace(@"\Program Files\", @"\Program Files (x86)\"); - if (Directory.Exists(newBasePath)) - { - basePath = newBasePath; - } + var newBasePath = basePath.Replace(@"\Program Files\", @"\Program Files (x86)\"); + if (Directory.Exists(newBasePath)) basePath = newBasePath; } else if (basePath.Contains(@"\Program Files (x86)\") && System.Environment.Is64BitProcess) { - string newBasePath = basePath.Replace(@"\Program Files (x86)\", @"\Program Files\"); - if (Directory.Exists(newBasePath)) - { - basePath = newBasePath; - } + var newBasePath = basePath.Replace(@"\Program Files (x86)\", @"\Program Files\"); + if (Directory.Exists(newBasePath)) basePath = newBasePath; } return basePath; diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/EnvironmentFactory.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/EnvironmentFactory.cs index 3c513c981ba..030942a4340 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/EnvironmentFactory.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/EnvironmentFactory.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,10 +21,12 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; using System.Linq; +using System.Runtime.InteropServices; using System.Xml.Linq; namespace DocGenerator.Buildalyzer.Environment @@ -33,42 +36,36 @@ internal abstract class EnvironmentFactory public static BuildEnvironment GetBuildEnvironment(string projectPath, XDocument projectDocument) { // If we're running on .NET Core, use the .NET Core SDK regardless of the project file - if (System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription - .Replace(" ", "").StartsWith(".NETCore", StringComparison.OrdinalIgnoreCase)) - { + if (RuntimeInformation.FrameworkDescription + .Replace(" ", "") + .StartsWith(".NETCore", StringComparison.OrdinalIgnoreCase)) return new CoreEnvironment(projectPath); - } // Look at the project file to determine - XElement projectElement = projectDocument.GetDescendants("Project").FirstOrDefault(); + var projectElement = projectDocument.GetDescendants("Project").FirstOrDefault(); if (projectElement != null) { // Does this project use the SDK? // Check for an SDK attribute on the project element // If no attribute, check for a SDK import (see https://github.com/Microsoft/msbuild/issues/1493) if (projectElement.GetAttributeValue("Sdk") != null - || projectElement.GetDescendants("Import").Any(x => x.GetAttributeValue("Sdk") != null)) + || projectElement.GetDescendants("Import").Any(x => x.GetAttributeValue("Sdk") != null)) { // Use the Framework tools if this project targets .NET Framework ("net" followed by a digit) // https://docs.microsoft.com/en-us/dotnet/standard/frameworks - string targetFramework = projectElement.GetDescendants("TargetFramework").FirstOrDefault()?.Value; - if(targetFramework != null - && targetFramework.StartsWith("net", StringComparison.OrdinalIgnoreCase) - && targetFramework.Length > 3 - && char.IsDigit(targetFramework[4])) - { + var targetFramework = projectElement.GetDescendants("TargetFramework").FirstOrDefault()?.Value; + if (targetFramework != null + && targetFramework.StartsWith("net", StringComparison.OrdinalIgnoreCase) + && targetFramework.Length > 3 + && char.IsDigit(targetFramework[4])) return new FrameworkEnvironment(projectPath, true); - } // Otherwise use the .NET Core SDK return new CoreEnvironment(projectPath); } // Use Framework tools if a ToolsVersion attribute - if (projectElement.GetAttributeValue("ToolsVersion") != null) - { - return new FrameworkEnvironment(projectPath, false); - } + if (projectElement.GetAttributeValue("ToolsVersion") != null) return new FrameworkEnvironment(projectPath, false); } throw new InvalidOperationException("Unrecognized project file format"); diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/FrameworkEnvironment.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/FrameworkEnvironment.cs index e41be6f9088..d14bd8f06c7 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/FrameworkEnvironment.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/FrameworkEnvironment.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; @@ -32,11 +34,6 @@ namespace DocGenerator.Buildalyzer.Environment { internal class FrameworkEnvironment : BuildEnvironment { - public string ToolsPath { get; } - public string ExtensionsPath { get; } - public string SDKsPath { get; } - public string RoslynTargetsPath { get; } - public FrameworkEnvironment(string projectPath, bool sdkProject) { ToolsPath = LocateToolsPath(); @@ -45,11 +42,16 @@ public FrameworkEnvironment(string projectPath, bool sdkProject) RoslynTargetsPath = Path.Combine(ToolsPath, "Roslyn"); } + public string ExtensionsPath { get; } + public string RoslynTargetsPath { get; } + public string SDKsPath { get; } + public string ToolsPath { get; } + public override string GetToolsPath() => ToolsPath; public override Dictionary GetGlobalProperties(string solutionDir) { - Dictionary globalProperties = base.GetGlobalProperties(solutionDir); + var globalProperties = base.GetGlobalProperties(solutionDir); globalProperties.Add(MsBuildProperties.MSBuildExtensionsPath, ExtensionsPath); globalProperties.Add(MsBuildProperties.MSBuildSDKsPath, SDKsPath); globalProperties.Add(MsBuildProperties.RoslynTargetsPath, RoslynTargetsPath); @@ -58,24 +60,17 @@ public override Dictionary GetGlobalProperties(string solutionDi private static string LocateToolsPath() { - string toolsPath = ToolLocationHelper.GetPathToBuildToolsFile("msbuild.exe", ToolLocationHelper.CurrentToolsVersion); - if (string.IsNullOrEmpty(toolsPath)) - { - // Could not find the tools path, possibly due to https://github.com/Microsoft/msbuild/issues/2369 - // Try to poll for it - toolsPath = PollForToolsPath(); - } - if (string.IsNullOrEmpty(toolsPath)) - { - throw new InvalidOperationException("Could not locate the tools (msbuild.exe) path"); - } + var toolsPath = ToolLocationHelper.GetPathToBuildToolsFile("msbuild.exe", ToolLocationHelper.CurrentToolsVersion); + if (string.IsNullOrEmpty(toolsPath)) toolsPath = PollForToolsPath(); + if (string.IsNullOrEmpty(toolsPath)) throw new InvalidOperationException("Could not locate the tools (msbuild.exe) path"); + return Path.GetDirectoryName(toolsPath); } // From https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/4649f55f900a324421bad5a714a2584926a02138/src/StructuredLogViewer/MSBuildLocator.cs private static string PollForToolsPath() { - string programFilesX86 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86); + var programFilesX86 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86); return new[] { Path.Combine(programFilesX86, @"Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe"), diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/MsBuildProperties.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/MsBuildProperties.cs index fa44dd87217..889d7693d84 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/MsBuildProperties.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/MsBuildProperties.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,25 +21,27 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion namespace DocGenerator.Buildalyzer.Environment { public static class MsBuildProperties { - // MSBuild Project Loading - public const string MSBuildExtensionsPath = nameof(MSBuildExtensionsPath); - public const string MSBuildSDKsPath = nameof(MSBuildSDKsPath); - public const string RoslynTargetsPath = nameof(RoslynTargetsPath); - public const string SolutionDir = nameof(SolutionDir); + public const string BuildProjectReferences = nameof(BuildProjectReferences); // Design-time Build public const string DesignTimeBuild = nameof(DesignTimeBuild); - public const string BuildProjectReferences = nameof(BuildProjectReferences); - public const string SkipCompilerExecution = nameof(SkipCompilerExecution); - public const string ProvideCommandLineArgs = nameof(ProvideCommandLineArgs); // Others public const string GenerateResourceMSBuildArchitecture = nameof(GenerateResourceMSBuildArchitecture); + + // MSBuild Project Loading + public const string MSBuildExtensionsPath = nameof(MSBuildExtensionsPath); + public const string MSBuildSDKsPath = nameof(MSBuildSDKsPath); + public const string ProvideCommandLineArgs = nameof(ProvideCommandLineArgs); + public const string RoslynTargetsPath = nameof(RoslynTargetsPath); + public const string SkipCompilerExecution = nameof(SkipCompilerExecution); + public const string SolutionDir = nameof(SolutionDir); } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/EmptyDisposable.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/EmptyDisposable.cs index a8d34fac0cd..745f4b14915 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/EmptyDisposable.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/EmptyDisposable.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; @@ -28,8 +30,6 @@ namespace DocGenerator.Buildalyzer.Logging { public class EmptyDisposable : IDisposable { - public void Dispose() - { - } + public void Dispose() { } } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/TextWriterLogger.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/TextWriterLogger.cs index 1d90e4dd622..da28a3df10b 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/TextWriterLogger.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/TextWriterLogger.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; @@ -32,16 +34,13 @@ internal class TextWriterLogger : ILogger { private readonly TextWriter _textWriter; - public TextWriterLogger(TextWriter textWriter) - { - _textWriter = textWriter; - } + public TextWriterLogger(TextWriter textWriter) => _textWriter = textWriter; - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => - _textWriter.Write(formatter(state, exception)); + public IDisposable BeginScope(TState state) => new EmptyDisposable(); public bool IsEnabled(LogLevel logLevel) => true; - public IDisposable BeginScope(TState state) => new EmptyDisposable(); + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => + _textWriter.Write(formatter(state, exception)); } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/TextWriterLoggerProvider.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/TextWriterLoggerProvider.cs index afadaa24bc6..dc700a89d12 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/TextWriterLoggerProvider.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Logging/TextWriterLoggerProvider.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System.IO; @@ -31,14 +33,9 @@ public class TextWriterLoggerProvider : ILoggerProvider { private readonly TextWriter _textWriter; - public TextWriterLoggerProvider(TextWriter textWriter) - { - _textWriter = textWriter; - } + public TextWriterLoggerProvider(TextWriter textWriter) => _textWriter = textWriter; - public void Dispose() - { - } + public void Dispose() { } public ILogger CreateLogger(string categoryName) => new TextWriterLogger(_textWriter); } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs index 2cdba3b3de4..f8f5502c573 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,13 +21,13 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Xml; using System.Xml.Linq; using DocGenerator.Buildalyzer.Environment; using Microsoft.Build.Evaluation; @@ -41,32 +42,16 @@ namespace DocGenerator.Buildalyzer { public class ProjectAnalyzer { - private readonly XDocument _projectDocument; - private readonly Dictionary _globalProperties; private readonly BuildEnvironment _buildEnvironment; + private readonly Dictionary _globalProperties; private readonly ConsoleLogger _logger; - - private Project _project = null; + private readonly XDocument _projectDocument; private ProjectInstance _compiledProject = null; - public AnalyzerManager Manager { get; } - - public string ProjectFilePath { get; } - - /// - /// The global properties for MSBuild. By default, each project - /// is configured with properties that use a design-time build without calling the compiler. - /// - public IReadOnlyDictionary GlobalProperties => _globalProperties; - - public Project Project => Load(); - - public ProjectInstance CompiledProject => Compile(); + private Project _project = null; internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath) - : this(manager, projectFilePath, XDocument.Load(projectFilePath)) - { - } + : this(manager, projectFilePath, XDocument.Load(projectFilePath)) { } internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocument projectDocument) { @@ -79,34 +64,43 @@ internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocum _buildEnvironment = EnvironmentFactory.GetBuildEnvironment(projectFilePath, _projectDocument); // Preload/enforce referencing some required asemblies - Copy copy = new Copy(); + var copy = new Copy(); - string solutionDir = manager.SolutionDirectory ?? projectFolder; + var solutionDir = manager.SolutionDirectory ?? projectFolder; _globalProperties = _buildEnvironment.GetGlobalProperties(solutionDir); // Create the logger if (manager.ProjectLogger != null) - { _logger = new ConsoleLogger(manager.LoggerVerbosity, x => manager.ProjectLogger.LogInformation(x), null, null); - } } + public ProjectInstance CompiledProject => Compile(); + + /// + /// The global properties for MSBuild. By default, each project + /// is configured with properties that use a design-time build without calling the compiler. + /// + public IReadOnlyDictionary GlobalProperties => _globalProperties; + + public AnalyzerManager Manager { get; } + + public Project Project => Load(); + + public string ProjectFilePath { get; } + public Project Load() { - if (_project != null) - { - return _project; - } + if (_project != null) return _project; // Create a project collection for each project since the toolset might change depending on the type of project - ProjectCollection projectCollection = CreateProjectCollection(); + var projectCollection = CreateProjectCollection(); // Load the project _buildEnvironment.SetEnvironmentVars(GlobalProperties); try { - using (XmlReader projectReader = _projectDocument.CreateReader()) + using (var projectReader = _projectDocument.CreateReader()) { _project = projectCollection.LoadProject(projectReader); _project.FullPath = ProjectFilePath; @@ -120,11 +114,10 @@ public Project Load() } - // Tweaks the project file a bit to ensure a succesfull build private static XDocument TweakProjectDocument(XDocument projectDocument, string projectFolder) { - foreach (XElement import in projectDocument.GetDescendants("Import").ToArray()) + foreach (var import in projectDocument.GetDescendants("Import").ToArray()) { var att = import.Attribute("Project"); if (att == null) continue; @@ -132,23 +125,17 @@ private static XDocument TweakProjectDocument(XDocument projectDocument, string var project = att.Value; if (!ResolveKnownPropsPath(projectFolder, project, att, "PublishArtifacts.build.props")) - { ResolveKnownPropsPath(projectFolder, project, att, "Artifacts.build.props"); - } ResolveKnownPropsPath(projectFolder, project, att, "Library.build.props"); } // Add SkipGetTargetFrameworkProperties to every ProjectReference - foreach (XElement projectReference in projectDocument.GetDescendants("ProjectReference").ToArray()) - { + foreach (var projectReference in projectDocument.GetDescendants("ProjectReference").ToArray()) projectReference.AddChildElement("SkipGetTargetFrameworkProperties", "true"); - } // Removes all EnsureNuGetPackageBuildImports - foreach (XElement ensureNuGetPackageBuildImports in + foreach (var ensureNuGetPackageBuildImports in projectDocument.GetDescendants("Target").Where(x => x.GetAttributeValue("Name") == "EnsureNuGetPackageBuildImports").ToArray()) - { ensureNuGetPackageBuildImports.Remove(); - } return projectDocument; } @@ -156,53 +143,43 @@ private static XDocument TweakProjectDocument(XDocument projectDocument, string private static bool ResolveKnownPropsPath(string projectFolder, string project, XAttribute att, string buildPropFile) { if (!project.Contains(buildPropFile)) return false; + var dir = new DirectoryInfo(projectFolder).Parent; while (dir != null && dir.Name != "src") dir = dir.Parent; if (dir == null) return true; + att.Value = Path.GetFullPath(Path.Combine(dir.FullName, buildPropFile)); return false; } private ProjectCollection CreateProjectCollection() { - ProjectCollection projectCollection = new ProjectCollection(_globalProperties); + var projectCollection = new ProjectCollection(_globalProperties); projectCollection.RemoveAllToolsets(); // Make sure we're only using the latest tools projectCollection.AddToolset( new Toolset(ToolLocationHelper.CurrentToolsVersion, _buildEnvironment.GetToolsPath(), projectCollection, string.Empty)); projectCollection.DefaultToolsVersion = ToolLocationHelper.CurrentToolsVersion; - if (_logger != null) - { - projectCollection.RegisterLogger(_logger); - } + if (_logger != null) projectCollection.RegisterLogger(_logger); return projectCollection; } public ProjectInstance Compile() { - if (_compiledProject != null) - { - return _compiledProject; - } - Project project = Load(); - if (project == null) - { - return null; - } + if (_compiledProject != null) return _compiledProject; + + var project = Load(); + if (project == null) return null; // Compile the project _buildEnvironment.SetEnvironmentVars(GlobalProperties); try { - ProjectInstance projectInstance = project.CreateProjectInstance(); - if (!projectInstance.Build("Clean", _logger == null ? null : new ILogger[] { _logger })) - { - return null; - } - if (!projectInstance.Build("Compile", _logger == null ? null : new ILogger[] { _logger })) - { - return null; - } + var projectInstance = project.CreateProjectInstance(); + if (!projectInstance.Build("Clean", _logger == null ? null : new ILogger[] { _logger })) return null; + + if (!projectInstance.Build("Compile", _logger == null ? null : new ILogger[] { _logger })) return null; + _compiledProject = projectInstance; return _compiledProject; } @@ -213,38 +190,37 @@ public ProjectInstance Compile() } public IReadOnlyList GetSourceFiles() => - Compile()?.Items + Compile() + ?.Items .Where(x => x.ItemType == "CscCommandLineArgs" && !x.EvaluatedInclude.StartsWith("/")) .Select(x => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(ProjectFilePath), x.EvaluatedInclude))) .ToList(); public IReadOnlyList GetReferences() => - Compile()?.Items + Compile() + ?.Items .Where(x => x.ItemType == "CscCommandLineArgs" && x.EvaluatedInclude.StartsWith("/reference:")) .Select(x => x.EvaluatedInclude.Substring(11).Trim('"')) .ToList(); public IReadOnlyList GetProjectReferences() => - Compile()?.Items + Compile() + ?.Items .Where(x => x.ItemType == "ProjectReference") .Select(x => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(ProjectFilePath), x.EvaluatedInclude))) .ToList(); public void SetGlobalProperty(string key, string value) { - if (_project != null) - { - throw new InvalidOperationException("Can not change global properties once project has been loaded"); - } + if (_project != null) throw new InvalidOperationException("Can not change global properties once project has been loaded"); + _globalProperties[key] = value; } public bool RemoveGlobalProperty(string key) { - if (_project != null) - { - throw new InvalidOperationException("Can not change global properties once project has been loaded"); - } + if (_project != null) throw new InvalidOperationException("Can not change global properties once project has been loaded"); + return _globalProperties.Remove(key); } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzerExtensions.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzerExtensions.cs index d3ead88b114..8e2d08f8e34 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzerExtensions.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzerExtensions.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; @@ -39,15 +41,16 @@ public static class ProjectAnalyzerExtensions /// Gets a Roslyn workspace for the analyzed project. /// /// The Buildalyzer project analyzer. - /// true to add projects to the workspace for project references that exist in the same . + /// + /// true to add projects to the workspace for project references that exist in the same + /// . + /// /// A Roslyn workspace. public static AdhocWorkspace GetWorkspace(this ProjectAnalyzer analyzer, bool addProjectReferences = false) { - if (analyzer == null) - { - throw new ArgumentNullException(nameof(analyzer)); - } - AdhocWorkspace workspace = new AdhocWorkspace(); + if (analyzer == null) throw new ArgumentNullException(nameof(analyzer)); + + var workspace = new AdhocWorkspace(); AddToWorkspace(analyzer, workspace, addProjectReferences); return workspace; } @@ -57,59 +60,52 @@ public static AdhocWorkspace GetWorkspace(this ProjectAnalyzer analyzer, bool ad /// /// The Buildalyzer project analyzer. /// A Roslyn workspace. - /// true to add projects to the workspace for project references that exist in the same . + /// + /// true to add projects to the workspace for project references that exist in the same + /// . + /// /// The newly added Roslyn project. public static Project AddToWorkspace(this ProjectAnalyzer analyzer, AdhocWorkspace workspace, bool addProjectReferences = false) { - if (analyzer == null) - { - throw new ArgumentNullException(nameof(analyzer)); - } - if (workspace == null) - { - throw new ArgumentNullException(nameof(workspace)); - } + if (analyzer == null) throw new ArgumentNullException(nameof(analyzer)); + + if (workspace == null) throw new ArgumentNullException(nameof(workspace)); // Get or create an ID for this project - string projectGuid = analyzer.CompiledProject?.GetPropertyValue("ProjectGuid"); - ProjectId projectId = !string.IsNullOrEmpty(projectGuid) - && Guid.TryParse(analyzer.CompiledProject?.GetPropertyValue("ProjectGuid"), out var projectIdGuid) - ? ProjectId.CreateFromSerialized(projectIdGuid) - : ProjectId.CreateNewId(); + var projectGuid = analyzer.CompiledProject?.GetPropertyValue("ProjectGuid"); + var projectId = !string.IsNullOrEmpty(projectGuid) + && Guid.TryParse(analyzer.CompiledProject?.GetPropertyValue("ProjectGuid"), out var projectIdGuid) + ? ProjectId.CreateFromSerialized(projectIdGuid) + : ProjectId.CreateNewId(); // Create and add the project - ProjectInfo projectInfo = GetProjectInfo(analyzer, workspace, projectId); - Solution solution = workspace.CurrentSolution.AddProject(projectInfo); + var projectInfo = GetProjectInfo(analyzer, workspace, projectId); + var solution = workspace.CurrentSolution.AddProject(projectInfo); // Check if this project is referenced by any other projects in the workspace - foreach (Project existingProject in solution.Projects.ToArray()) + foreach (var existingProject in solution.Projects.ToArray()) { if (!existingProject.Id.Equals(projectId) - && analyzer.Manager.Projects.TryGetValue(existingProject.FilePath, out ProjectAnalyzer existingAnalyzer) - && (existingAnalyzer.GetProjectReferences()?.Contains(analyzer.ProjectFilePath) ?? false)) + && analyzer.Manager.Projects.TryGetValue(existingProject.FilePath, out var existingAnalyzer) + && (existingAnalyzer.GetProjectReferences()?.Contains(analyzer.ProjectFilePath) ?? false)) { // Add the reference to the existing project - ProjectReference projectReference = new ProjectReference(projectId); + var projectReference = new ProjectReference(projectId); solution = solution.AddProjectReference(existingProject.Id, projectReference); } } // Apply solution changes - if (!workspace.TryApplyChanges(solution)) - { - throw new InvalidOperationException("Could not apply workspace solution changes"); - } + if (!workspace.TryApplyChanges(solution)) throw new InvalidOperationException("Could not apply workspace solution changes"); // Add any project references not already added - if(addProjectReferences) + if (addProjectReferences) { - foreach(ProjectAnalyzer referencedAnalyzer in GetReferencedAnalyzerProjects(analyzer)) + foreach (var referencedAnalyzer in GetReferencedAnalyzerProjects(analyzer)) { // Check if the workspace contains the project inside the loop since adding one might also add this one due to transitive references - if(!workspace.CurrentSolution.Projects.Any(x => x.FilePath == referencedAnalyzer.ProjectFilePath)) - { + if (!workspace.CurrentSolution.Projects.Any(x => x.FilePath == referencedAnalyzer.ProjectFilePath)) AddToWorkspace(referencedAnalyzer, workspace, addProjectReferences); - } } } @@ -119,16 +115,16 @@ public static Project AddToWorkspace(this ProjectAnalyzer analyzer, AdhocWorkspa private static ProjectInfo GetProjectInfo(ProjectAnalyzer analyzer, AdhocWorkspace workspace, ProjectId projectId) { - string projectName = Path.GetFileNameWithoutExtension(analyzer.ProjectFilePath); - string languageName = GetLanguageName(analyzer.ProjectFilePath); - ProjectInfo projectInfo = ProjectInfo.Create( + var projectName = Path.GetFileNameWithoutExtension(analyzer.ProjectFilePath); + var languageName = GetLanguageName(analyzer.ProjectFilePath); + var projectInfo = ProjectInfo.Create( projectId, VersionStamp.Create(), projectName, projectName, languageName, - filePath: analyzer.ProjectFilePath, - outputFilePath: analyzer.CompiledProject?.GetPropertyValue("TargetPath"), + analyzer.ProjectFilePath, + analyzer.CompiledProject?.GetPropertyValue("TargetPath"), documents: GetDocuments(analyzer, projectId), projectReferences: GetExistingProjectReferences(analyzer, workspace), metadataReferences: GetMetadataReferences(analyzer), @@ -138,7 +134,7 @@ private static ProjectInfo GetProjectInfo(ProjectAnalyzer analyzer, AdhocWorkspa private static CompilationOptions CreateCompilationOptions(Microsoft.Build.Evaluation.Project project, string languageName) { - string outputType = project.GetPropertyValue("OutputType"); + var outputType = project.GetPropertyValue("OutputType"); OutputKind? kind = null; switch (outputType) { @@ -158,14 +154,9 @@ private static CompilationOptions CreateCompilationOptions(Microsoft.Build.Evalu if (kind.HasValue) { - if (languageName == LanguageNames.CSharp) - { - return new CSharpCompilationOptions(kind.Value); - } - if (languageName == LanguageNames.VisualBasic) - { - return new VisualBasicCompilationOptions(kind.Value); - } + if (languageName == LanguageNames.CSharp) return new CSharpCompilationOptions(kind.Value); + + if (languageName == LanguageNames.VisualBasic) return new VisualBasicCompilationOptions(kind.Value); } return null; @@ -180,7 +171,7 @@ private static IEnumerable GetExistingProjectReferences(Projec private static IEnumerable GetReferencedAnalyzerProjects(ProjectAnalyzer analyzer) => analyzer.GetProjectReferences() - ?.Select(x => analyzer.Manager.Projects.TryGetValue(x, out ProjectAnalyzer a) ? a : null) + ?.Select(x => analyzer.Manager.Projects.TryGetValue(x, out var a) ? a : null) .Where(x => x != null) ?? Array.Empty(); diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/XDocumentExtensions.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/XDocumentExtensions.cs index 999dfdd99f0..86dd59a5546 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/XDocumentExtensions.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/XDocumentExtensions.cs @@ -1,4 +1,5 @@ #region License + //MIT License // //Copyright (c) 2017 Dave Glick @@ -20,6 +21,7 @@ //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. + #endregion using System; diff --git a/src/CodeGeneration/DocGenerator/Documentation/Blocks/CSharpBlock.cs b/src/CodeGeneration/DocGenerator/Documentation/Blocks/CSharpBlock.cs index 406c6b269a1..199936d4787 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Blocks/CSharpBlock.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Blocks/CSharpBlock.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,70 +7,62 @@ namespace DocGenerator.Documentation.Blocks { - public class CSharpBlock : CodeBlock - { - private static readonly Regex Callout = new Regex(@"//[ \t]*(?\<\d+\>)[ \t]*(?\S.*)", RegexOptions.Compiled); - private static readonly Regex CalloutReplacer = new Regex(@"//[ \t]*\<(\d+)\>.*", RegexOptions.Compiled); + public class CSharpBlock : CodeBlock + { + private static readonly Regex Callout = new Regex(@"//[ \t]*(?\<\d+\>)[ \t]*(?\S.*)", RegexOptions.Compiled); + private static readonly Regex CalloutReplacer = new Regex(@"//[ \t]*\<(\d+)\>.*", RegexOptions.Compiled); - private List Callouts { get; } = new List(); + public CSharpBlock(SyntaxNode node, int depth, string memberName = null) + : base(node.WithoutLeadingTrivia().ToFullStringWithoutPragmaWarningDirectiveTrivia(), + node.StartingLine(), + node.IsKind(SyntaxKind.ClassDeclaration) ? depth : depth + 2, + "csharp", + memberName) { } - public CSharpBlock(SyntaxNode node, int depth, string memberName = null) - : base(node.WithoutLeadingTrivia().ToFullStringWithoutPragmaWarningDirectiveTrivia(), - node.StartingLine(), - node.IsKind(SyntaxKind.ClassDeclaration) ? depth : depth + 2, - "csharp", - memberName) - { - } + private List Callouts { get; } = new List(); - public void AddNode(SyntaxNode node) => Lines.Add(node.WithLeadingEndOfLineTrivia().ToFullStringWithoutPragmaWarningDirectiveTrivia()); + public void AddNode(SyntaxNode node) => Lines.Add(node.WithLeadingEndOfLineTrivia().ToFullStringWithoutPragmaWarningDirectiveTrivia()); - public override string ToAsciiDoc() - { - var builder = new StringBuilder(); + public override string ToAsciiDoc() + { + var builder = new StringBuilder(); - // method attribute is used to add section titles in GeneratedAsciidocVisitor - builder.AppendLine(!string.IsNullOrEmpty(MemberName) - ? $"[source, {Language.ToLowerInvariant()}, method=\"{MemberName.ToLowerInvariant()}\"]" - : $"[source, {Language.ToLowerInvariant()}]"); + // method attribute is used to add section titles in GeneratedAsciidocVisitor + builder.AppendLine(!string.IsNullOrEmpty(MemberName) + ? $"[source, {Language.ToLowerInvariant()}, method=\"{MemberName.ToLowerInvariant()}\"]" + : $"[source, {Language.ToLowerInvariant()}]"); - builder.AppendLine("----"); + builder.AppendLine("----"); - var code = ExtractCallOutsFromCode(Value); + var code = ExtractCallOutsFromCode(Value); - code = code.RemoveNumberOfLeadingTabsOrSpacesAfterNewline(Depth); - builder.AppendLine(code); + code = code.RemoveNumberOfLeadingTabsOrSpacesAfterNewline(Depth); + builder.AppendLine(code); - builder.AppendLine("----"); - foreach (var callout in Callouts) - { - builder.AppendLine(callout); - } - return builder.ToString(); - } + builder.AppendLine("----"); + foreach (var callout in Callouts) builder.AppendLine(callout); + return builder.ToString(); + } - /// - /// Extracts the callouts from code. The callout comment is defined inline within - /// source code to play nicely with C# semantics, but needs to be extracted and placed after the - /// source block delimiter to be valid asciidoc. - /// - private string ExtractCallOutsFromCode(string value) - { - var matches = Callout.Matches(value); - var callouts = new List(); + /// + /// Extracts the callouts from code. The callout comment is defined inline within + /// source code to play nicely with C# semantics, but needs to be extracted and placed after the + /// source block delimiter to be valid asciidoc. + /// + private string ExtractCallOutsFromCode(string value) + { + var matches = Callout.Matches(value); + var callouts = new List(); - foreach (Match match in matches) - { - callouts.Add($"{match.Groups["callout"].Value} {match.Groups["text"].Value}"); - } + foreach (Match match in matches) callouts.Add($"{match.Groups["callout"].Value} {match.Groups["text"].Value}"); - if (callouts.Any()) - { - value = CalloutReplacer.Replace(value, "//<$1>"); - Callouts.AddRange(callouts); - } + if (callouts.Any()) + { + value = CalloutReplacer.Replace(value, "//<$1>"); + Callouts.AddRange(callouts); + } - return value.Trim(); - } - } + return value.Trim(); + } + } } diff --git a/src/CodeGeneration/DocGenerator/Documentation/Blocks/CodeBlock.cs b/src/CodeGeneration/DocGenerator/Documentation/Blocks/CodeBlock.cs index 9b52736d691..5fa5c59636e 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Blocks/CodeBlock.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Blocks/CodeBlock.cs @@ -1,31 +1,30 @@ -using System; using System.Collections.Generic; -using System.Text; namespace DocGenerator.Documentation.Blocks { - public abstract class CodeBlock : IDocumentationBlock - { - protected readonly IList Lines = new List(); + public abstract class CodeBlock : IDocumentationBlock + { + protected readonly IList Lines = new List(); - public string Language { get; } - public int LineNumber { get; } - public int Depth { get; } - public string MemberName { get; } + protected CodeBlock(string text, int startingLine, int depth, string language, string memberName) + { + Lines.Add(text); + LineNumber = startingLine; + Depth = depth; + Language = language; + MemberName = memberName?.ToLowerInvariant() ?? string.Empty; + } - public string Value => string.Join(string.Empty, Lines); + public int Depth { get; } - public void AddLine(string line) => Lines.Add(line); + public string Language { get; } + public int LineNumber { get; } + public string MemberName { get; } - protected CodeBlock(string text, int startingLine, int depth, string language, string memberName) - { - Lines.Add(text); - LineNumber = startingLine; - Depth = depth; - Language = language; - MemberName = memberName?.ToLowerInvariant() ?? string.Empty; - } + public string Value => string.Join(string.Empty, Lines); - public abstract string ToAsciiDoc(); - } -} \ No newline at end of file + public abstract string ToAsciiDoc(); + + public void AddLine(string line) => Lines.Add(line); + } +} diff --git a/src/CodeGeneration/DocGenerator/Documentation/Blocks/IDocumentationBlock.cs b/src/CodeGeneration/DocGenerator/Documentation/Blocks/IDocumentationBlock.cs index 61b760516b5..90d5acd2a0b 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Blocks/IDocumentationBlock.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Blocks/IDocumentationBlock.cs @@ -1,9 +1,10 @@ namespace DocGenerator.Documentation.Blocks { - public interface IDocumentationBlock - { - int LineNumber { get; } - string Value { get; } - string ToAsciiDoc(); - } -} \ No newline at end of file + public interface IDocumentationBlock + { + int LineNumber { get; } + string Value { get; } + + string ToAsciiDoc(); + } +} diff --git a/src/CodeGeneration/DocGenerator/Documentation/Blocks/JavaScriptBlock.cs b/src/CodeGeneration/DocGenerator/Documentation/Blocks/JavaScriptBlock.cs index 284090fcc7a..3a4a46aa0e0 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Blocks/JavaScriptBlock.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Blocks/JavaScriptBlock.cs @@ -2,28 +2,26 @@ namespace DocGenerator.Documentation.Blocks { - public class JavaScriptBlock : CodeBlock - { - public JavaScriptBlock(string text, int startingLine, int depth, string memberName = null) - : base(text, startingLine, depth, "javascript", memberName) - { - } + public class JavaScriptBlock : CodeBlock + { + public JavaScriptBlock(string text, int startingLine, int depth, string memberName = null) + : base(text, startingLine, depth, "javascript", memberName) { } - public string Title { get; set; } + public string Title { get; set; } - public override string ToAsciiDoc() - { - var builder = new StringBuilder(); + public override string ToAsciiDoc() + { + var builder = new StringBuilder(); - if (!string.IsNullOrEmpty(Title)) - builder.AppendLine("." + Title); - builder.AppendLine(!string.IsNullOrEmpty(MemberName) - ? $"[source, {Language.ToLowerInvariant()}, method=\"{MemberName.ToLowerInvariant()}\"]" - : $"[source, {Language.ToLowerInvariant()}]"); - builder.AppendLine("----"); - builder.AppendLine(Value); - builder.AppendLine("----"); - return builder.ToString(); - } - } -} \ No newline at end of file + if (!string.IsNullOrEmpty(Title)) + builder.AppendLine("." + Title); + builder.AppendLine(!string.IsNullOrEmpty(MemberName) + ? $"[source, {Language.ToLowerInvariant()}, method=\"{MemberName.ToLowerInvariant()}\"]" + : $"[source, {Language.ToLowerInvariant()}]"); + builder.AppendLine("----"); + builder.AppendLine(Value); + builder.AppendLine("----"); + return builder.ToString(); + } + } +} diff --git a/src/CodeGeneration/DocGenerator/Documentation/Blocks/TextBlock.cs b/src/CodeGeneration/DocGenerator/Documentation/Blocks/TextBlock.cs index cafafbdafe0..f31a5fddf16 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Blocks/TextBlock.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Blocks/TextBlock.cs @@ -1,16 +1,17 @@ namespace DocGenerator.Documentation.Blocks { - public class TextBlock : IDocumentationBlock - { - public TextBlock(string text, int lineNumber) - { - Value = text; - LineNumber = lineNumber; - } + public class TextBlock : IDocumentationBlock + { + public TextBlock(string text, int lineNumber) + { + Value = text; + LineNumber = lineNumber; + } - public string Value { get; } - public int LineNumber { get; } + public int LineNumber { get; } - public string ToAsciiDoc() => Value; - } -} \ No newline at end of file + public string Value { get; } + + public string ToAsciiDoc() => Value; + } +} diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/CSharpDocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/CSharpDocumentationFile.cs index c3e5da65d45..5d28a97d37b 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/CSharpDocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/CSharpDocumentationFile.cs @@ -11,44 +11,39 @@ namespace DocGenerator.Documentation.Files { - public class CSharpDocumentationFile : DocumentationFile - { - private readonly Document _document; - private readonly Dictionary _projects; - - public CSharpDocumentationFile(Document document, Dictionary projects) - : base(new FileInfo(document.FilePath)) - { - _document = document; - _projects = projects; - } - - public override async Task SaveToDocumentationFolderAsync() - { - var converter = new DocConverter(); - var blocks = await converter.ConvertAsync(_document).ConfigureAwait(false); - - if (!blocks.Any()) return; - - var builder = new StringBuilder(); - using (var writer = new StringWriter(builder)) - { - foreach (var block in blocks) - await writer.WriteLineAsync(block.ToAsciiDoc()).ConfigureAwait(false); - } - - var destination = this.CreateDocumentationLocation(); - - // Now add Asciidoc headers, rearrange sections, etc. - var document = AsciiDocNet.Document.Parse(builder.ToString()); - var visitor = new GeneratedAsciidocVisitor(this.FileLocation, destination, _projects); - document = visitor.Convert(document); - - // Write out document to file - using (var writer = new StreamWriter(destination.FullName)) - { - document.Accept(new AsciiDocVisitor(writer)); - } - } - } + public class CSharpDocumentationFile : DocumentationFile + { + private readonly Document _document; + private readonly Dictionary _projects; + + public CSharpDocumentationFile(Document document, Dictionary projects) + : base(new FileInfo(document.FilePath)) + { + _document = document; + _projects = projects; + } + + public override async Task SaveToDocumentationFolderAsync() + { + var converter = new DocConverter(); + var blocks = await converter.ConvertAsync(_document).ConfigureAwait(false); + + if (!blocks.Any()) return; + + var builder = new StringBuilder(); + using (var writer = new StringWriter(builder)) + foreach (var block in blocks) + await writer.WriteLineAsync(block.ToAsciiDoc()).ConfigureAwait(false); + + var destination = CreateDocumentationLocation(); + + // Now add Asciidoc headers, rearrange sections, etc. + var document = AsciiDocNet.Document.Parse(builder.ToString()); + var visitor = new GeneratedAsciidocVisitor(FileLocation, destination, _projects); + document = visitor.Convert(document); + + // Write out document to file + using (var writer = new StreamWriter(destination.FullName)) document.Accept(new AsciiDocVisitor(writer)); + } + } } diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs index 7e920e9e567..f30e1362205 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs @@ -7,20 +7,16 @@ namespace DocGenerator.Documentation.Files { public abstract class DocumentationFile { - protected FileInfo FileLocation { get; } - - protected string Extension => this.FileLocation?.Extension.ToLowerInvariant(); + protected DocumentationFile(FileInfo fileLocation) => FileLocation = fileLocation; - protected DocumentationFile(FileInfo fileLocation) - { - this.FileLocation = fileLocation; - } + protected string Extension => FileLocation?.Extension.ToLowerInvariant(); + protected FileInfo FileLocation { get; } public abstract Task SaveToDocumentationFolderAsync(); public static DocumentationFile Load(FileInfo fileLocation) { - if (fileLocation == null) throw new ArgumentNullException(nameof(fileLocation)); + if (fileLocation == null) throw new ArgumentNullException(nameof(fileLocation)); var extension = fileLocation.Extension; switch (extension) @@ -32,36 +28,38 @@ public static DocumentationFile Load(FileInfo fileLocation) return new ImageDocumentationFile(fileLocation); case ".asciidoc": return new RawDocumentationFile(fileLocation); - default: - throw new ArgumentOutOfRangeException(nameof(fileLocation), - $"The extension you specified is currently not supported: {extension}"); - } + default: + throw new ArgumentOutOfRangeException(nameof(fileLocation), + $"The extension you specified is currently not supported: {extension}"); + } } protected virtual FileInfo CreateDocumentationLocation() { - var testFullPath = this.FileLocation.FullName; + var testFullPath = FileLocation.FullName; var p = "\\" + Path.DirectorySeparatorChar.ToString(); var testInDocumentationFolder = - Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "") - .TrimEnd(".doc") - .TrimEnd("Tests") - .PascalToHyphen() + ".asciidoc"; + Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + Extension + "$)", "") + .TrimEnd(".doc") + .TrimEnd("Tests") + .PascalToHyphen() + ".asciidoc"; var documentationTargetPath = Path.GetFullPath(Path.Combine(Program.OutputDirPath, testInDocumentationFolder)); var fileInfo = new FileInfo(documentationTargetPath); - if (fileInfo.Directory != null) + if (fileInfo.Directory != null) Directory.CreateDirectory(fileInfo.Directory.FullName); return fileInfo; } - protected async Task CopyFileAsync(string sourceFile, string destinationFile) - { - using (var sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan)) - using (var destinationStream = new FileStream(destinationFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan)) - await sourceStream.CopyToAsync(destinationStream); - } + protected async Task CopyFileAsync(string sourceFile, string destinationFile) + { + using (var sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, + FileOptions.Asynchronous | FileOptions.SequentialScan)) + using (var destinationStream = new FileStream(destinationFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, + FileOptions.Asynchronous | FileOptions.SequentialScan)) + await sourceStream.CopyToAsync(destinationStream); + } } } diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs index f43997f2bae..678d98cbae3 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs @@ -10,25 +10,25 @@ public ImageDocumentationFile(FileInfo fileLocation) : base(fileLocation) { } public override async Task SaveToDocumentationFolderAsync() { - var docFileName = this.CreateDocumentationLocation(); + var docFileName = CreateDocumentationLocation(); - // copy for asciidoc to work when viewing a single asciidoc in the browser (path is relative to file) - var copyRelativeTask = CopyFileAsync(this.FileLocation.FullName, docFileName.FullName); + // copy for asciidoc to work when viewing a single asciidoc in the browser (path is relative to file) + var copyRelativeTask = CopyFileAsync(FileLocation.FullName, docFileName.FullName); - // copy to the root as well, for the doc generation process (path is relative to root) - var copyRootTask = CopyFileAsync(this.FileLocation.FullName, Path.Combine(Program.OutputDirPath, docFileName.Name)); + // copy to the root as well, for the doc generation process (path is relative to root) + var copyRootTask = CopyFileAsync(FileLocation.FullName, Path.Combine(Program.OutputDirPath, docFileName.Name)); - await copyRelativeTask; - await copyRootTask; + await copyRelativeTask; + await copyRootTask; } protected override FileInfo CreateDocumentationLocation() { - var testFullPath = this.FileLocation.FullName; + var testFullPath = FileLocation.FullName; var p = "\\" + Path.DirectorySeparatorChar.ToString(); - var testInDocumenationFolder = Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "") - .PascalToHyphen() + this.Extension; + var testInDocumenationFolder = Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + Extension + "$)", "") + .PascalToHyphen() + Extension; var documentationTargetPath = Path.GetFullPath(Path.Combine(Program.OutputDirPath, testInDocumenationFolder)); diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs index cfd8e960a48..aeca30e9ac5 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs @@ -13,7 +13,7 @@ public RawDocumentationFile(FileInfo fileLocation) : base(fileLocation) { } public override Task SaveToDocumentationFolderAsync() { //load the asciidoc file for processing - var docFileName = this.CreateDocumentationLocation(); + var docFileName = CreateDocumentationLocation(); var document = Document.Load(FileLocation.FullName); // make any modifications @@ -21,19 +21,16 @@ public override Task SaveToDocumentationFolderAsync() document.Accept(rawVisitor); // write out asciidoc to file - using (var visitor = new AsciiDocVisitor(docFileName.FullName)) - { - document.Accept(visitor); - } + using (var visitor = new AsciiDocVisitor(docFileName.FullName)) document.Accept(visitor); - return Task.FromResult(0); + return Task.FromResult(0); } protected override FileInfo CreateDocumentationLocation() { - var testFullPath = this.FileLocation.FullName; + var testFullPath = FileLocation.FullName; var p = "\\" + Path.DirectorySeparatorChar.ToString(); - var testInDocumenationFolder = Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "").PascalToHyphen() + this.Extension; + var testInDocumenationFolder = Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + Extension + "$)", "").PascalToHyphen() + Extension; var documenationTargetPath = Path.GetFullPath(Path.Combine(Program.OutputDirPath, testInDocumenationFolder)); var fileInfo = new FileInfo(documenationTargetPath); diff --git a/src/CodeGeneration/DocGenerator/LitUp.cs b/src/CodeGeneration/DocGenerator/LitUp.cs index a2e5772f05d..a282f40f2b4 100644 --- a/src/CodeGeneration/DocGenerator/LitUp.cs +++ b/src/CodeGeneration/DocGenerator/LitUp.cs @@ -6,17 +6,16 @@ using System.Threading.Tasks; using DocGenerator.Buildalyzer; using DocGenerator.Documentation.Files; -using Microsoft.Build.Framework; using Microsoft.CodeAnalysis; -using Microsoft.Extensions.Logging; namespace DocGenerator { public static class LitUp { - private static readonly string[] SkipFolders = {"Debug", "Release"}; + private static readonly string[] SkipFolders = { "Debug", "Release" }; private static string GetProjectDir(string projectName) => Path.Combine(Program.InputDirPath, projectName); + private static string GetProjectFile(string projectName) => Path.Combine(GetProjectDir(projectName), $"{projectName}.csproj"); public static IEnumerable InputFiles(string path) => @@ -40,6 +39,7 @@ public static IEnumerable> GetDocumentFiles(Dicti yield return InputFiles("*.png"); yield return InputFiles("*.gif"); yield return InputFiles("*.jpg"); + // process asciidocs last as they may have generated // includes to other output asciidocs yield return InputFiles("*.asciidoc"); @@ -68,10 +68,7 @@ public static async Task GoAsync(string[] args) var projects = workspace.CurrentSolution.Projects .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); - foreach (var file in GetDocumentFiles(projects).SelectMany(s => s)) - { - await file.SaveToDocumentationFolderAsync(); - } + foreach (var file in GetDocumentFiles(projects).SelectMany(s => s)) await file.SaveToDocumentationFolderAsync(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Documentation generated."); @@ -105,9 +102,7 @@ private static void AddDocumentsToWorkspace(AdhocWorkspace workspace) } if (!workspace.TryApplyChanges(project.Solution)) - { Console.WriteLine($"failed to apply changes to workspace from project {project.Name}"); - } } } } diff --git a/src/CodeGeneration/DocGenerator/MethodInfoExtensions.cs b/src/CodeGeneration/DocGenerator/MethodInfoExtensions.cs index c2b16b0016a..1efd31adcd1 100644 --- a/src/CodeGeneration/DocGenerator/MethodInfoExtensions.cs +++ b/src/CodeGeneration/DocGenerator/MethodInfoExtensions.cs @@ -1,130 +1,127 @@ using System; using System.Reflection; +using System.Runtime.CompilerServices; using System.Text; namespace DocGenerator { - public static class MethodInfoExtensions - { - /// - /// Return the method signature as a string. - /// - /// The Method - /// Return as an callable string(public void a(string b) would return a(b)) - /// Method signature - public static string GetSignature(this MethodInfo method, bool callable = false) - { - var firstParam = true; - var sigBuilder = new StringBuilder(); - sigBuilder.Append(method.Name); + public static class MethodInfoExtensions + { + /// + /// Return the method signature as a string. + /// + /// The Method + /// Return as an callable string(public void a(string b) would return a(b)) + /// Method signature + public static string GetSignature(this MethodInfo method, bool callable = false) + { + var firstParam = true; + var sigBuilder = new StringBuilder(); + sigBuilder.Append(method.Name); - // Add method generics - if (method.IsGenericMethod) - { - sigBuilder.Append("<"); - foreach (var g in method.GetGenericArguments()) - { - if (firstParam) - firstParam = false; - else - sigBuilder.Append(", "); - sigBuilder.Append(TypeName(g)); - } - sigBuilder.Append(">"); - } - sigBuilder.Append("("); - firstParam = true; - var secondParam = false; - foreach (var param in method.GetParameters()) - { - if (firstParam) - { - firstParam = false; - if (method.IsDefined(typeof(System.Runtime.CompilerServices.ExtensionAttribute), false)) - { - if (callable) - { - secondParam = true; - continue; - } - sigBuilder.Append("this "); - } - } - else if (secondParam == true) - secondParam = false; - else - sigBuilder.Append(", "); - if (param.ParameterType.IsByRef) - sigBuilder.Append("ref "); - else if (param.IsOut) - sigBuilder.Append("out "); - if (!callable) - { - sigBuilder.Append(TypeName(param.ParameterType)); - sigBuilder.Append(' '); - } - sigBuilder.Append(param.Name); + // Add method generics + if (method.IsGenericMethod) + { + sigBuilder.Append("<"); + foreach (var g in method.GetGenericArguments()) + { + if (firstParam) + firstParam = false; + else + sigBuilder.Append(", "); + sigBuilder.Append(TypeName(g)); + } + sigBuilder.Append(">"); + } + sigBuilder.Append("("); + firstParam = true; + var secondParam = false; + foreach (var param in method.GetParameters()) + { + if (firstParam) + { + firstParam = false; + if (method.IsDefined(typeof(ExtensionAttribute), false)) + { + if (callable) + { + secondParam = true; + continue; + } + sigBuilder.Append("this "); + } + } + else if (secondParam == true) + secondParam = false; + else + sigBuilder.Append(", "); + if (param.ParameterType.IsByRef) + sigBuilder.Append("ref "); + else if (param.IsOut) + sigBuilder.Append("out "); + if (!callable) + { + sigBuilder.Append(TypeName(param.ParameterType)); + sigBuilder.Append(' '); + } + sigBuilder.Append(param.Name); - if (param.HasDefaultValue) - { - object defaultValue; - if (param.ParameterType == typeof(bool)) - { - defaultValue = (bool) param.DefaultValue ? "true" : "false"; - } - else - { - defaultValue = param.DefaultValue; - } + if (param.HasDefaultValue) + { + object defaultValue; + if (param.ParameterType == typeof(bool)) + defaultValue = (bool)param.DefaultValue ? "true" : "false"; + else + defaultValue = param.DefaultValue; - sigBuilder.Append(" = " + defaultValue); - } + sigBuilder.Append(" = " + defaultValue); + } + } + sigBuilder.Append(")"); + return sigBuilder.ToString(); + } - } - sigBuilder.Append(")"); - return sigBuilder.ToString(); - } + /// + /// Get full type name with full namespace names + /// + /// Type. May be generic or nullable + /// Full type name, fully qualified namespaces + public static string TypeName(Type type) + { + var nullableType = Nullable.GetUnderlyingType(type); + if (nullableType != null) + return nullableType.Name + "?"; - /// - /// Get full type name with full namespace names - /// - /// Type. May be generic or nullable - /// Full type name, fully qualified namespaces - public static string TypeName(Type type) - { - var nullableType = Nullable.GetUnderlyingType(type); - if (nullableType != null) - return nullableType.Name + "?"; + if (!type.IsGenericType) + { + switch (type.Name) + { + case "String": return "string"; + case "Int32": return "int"; + case "Decimal": return "decimal"; + case "Object": return "object"; + case "Void": return "void"; + default: + { + return string.IsNullOrWhiteSpace(type.FullName) ? type.Name : type.FullName; + } + } + } - if (!type.IsGenericType) - switch (type.Name) - { - case "String": return "string"; - case "Int32": return "int"; - case "Decimal": return "decimal"; - case "Object": return "object"; - case "Void": return "void"; - default: - { - return string.IsNullOrWhiteSpace(type.FullName) ? type.Name : type.FullName; - } - } - - var sb = new StringBuilder(type.Name.Substring(0, - type.Name.IndexOf('`')) - ); - sb.Append('<'); - var first = true; - foreach (var t in type.GetGenericArguments()) - { - if (!first) - sb.Append(','); - sb.Append(TypeName(t)); - first = false; - } - sb.Append('>'); - return sb.ToString(); - } - - } -} \ No newline at end of file + var sb = new StringBuilder(type.Name.Substring(0, + type.Name.IndexOf('`')) + ); + sb.Append('<'); + var first = true; + foreach (var t in type.GetGenericArguments()) + { + if (!first) + sb.Append(','); + sb.Append(TypeName(t)); + first = false; + } + sb.Append('>'); + return sb.ToString(); + } + } +} diff --git a/src/CodeGeneration/DocGenerator/Program.cs b/src/CodeGeneration/DocGenerator/Program.cs index e0c9fa45c63..e1e95b3de6b 100644 --- a/src/CodeGeneration/DocGenerator/Program.cs +++ b/src/CodeGeneration/DocGenerator/Program.cs @@ -14,19 +14,19 @@ string P(string path) } var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory()); - if (currentDirectory.Name == "DocGenerator" && currentDirectory.Parent.Name == "CodeGeneration") + if (currentDirectory.Name == "DocGenerator" && currentDirectory.Parent.Name == "CodeGeneration") { Console.WriteLine("IDE: " + currentDirectory); - InputDirPath = P(@"..\..\"); + InputDirPath = P(@"..\..\"); OutputDirPath = P(@"..\..\..\docs"); - BuildOutputPath = P(@"..\..\..\src"); + BuildOutputPath = P(@"..\..\..\src"); } else { Console.WriteLine("CMD: " + currentDirectory); InputDirPath = P(@"..\..\..\..\src"); OutputDirPath = P(@"..\..\..\..\docs"); - BuildOutputPath = P(@"..\..\..\..\build\output"); + BuildOutputPath = P(@"..\..\..\..\build\output"); } var process = new Process @@ -56,44 +56,42 @@ string P(string path) { process.Dispose(); } - } - - public static string BuildOutputPath { get; } - - public static string InputDirPath { get; } - - public static string OutputDirPath { get; } + } /// /// The branch name to include in generated docs to link back to the original source file /// public static string BranchName { get; set; } + public static string BuildOutputPath { get; } + /// /// The Elasticsearch documentation version to link to /// public static string DocVersion => "6.4"; - static int Main(string[] args) + public static string InputDirPath { get; } + + public static string OutputDirPath { get; } + + private static int Main(string[] args) { - try - { - if (args.Length > 0) - BranchName = args[0]; + try + { + if (args.Length > 0) + BranchName = args[0]; - Console.WriteLine($"Using branch name {BranchName} in documentation"); + Console.WriteLine($"Using branch name {BranchName} in documentation"); - LitUp.GoAsync(args).Wait(); - return 0; - } - catch (AggregateException ae) - { - var ex = ae.InnerException ?? ae; - Console.WriteLine(ex.Message); - return 1; - } + LitUp.GoAsync(args).Wait(); + return 0; + } + catch (AggregateException ae) + { + var ex = ae.InnerException ?? ae; + Console.WriteLine(ex.Message); + return 1; + } } } } - - diff --git a/src/CodeGeneration/DocGenerator/StringExtensions.cs b/src/CodeGeneration/DocGenerator/StringExtensions.cs index a91f2bf7dd3..49959c6b902 100644 --- a/src/CodeGeneration/DocGenerator/StringExtensions.cs +++ b/src/CodeGeneration/DocGenerator/StringExtensions.cs @@ -14,134 +14,29 @@ namespace DocGenerator { public static class StringExtensions { - private static readonly Regex LeadingSpacesAndAsterisk = new Regex(@"^(?[ \t]*\*\s?).*", RegexOptions.Compiled); - private static readonly Regex LeadingMultiLineComment = new Regex(@"^(?[ \t]*\/\*)", RegexOptions.Compiled); - private static readonly Regex TrailingMultiLineComment = new Regex(@"(?\*\/[ \t]*)$", RegexOptions.Compiled); - - public static string PascalToHyphen(this string input) - { - if (string.IsNullOrEmpty(input)) return string.Empty; - - return Regex.Replace( - Regex.Replace( - Regex.Replace(input, @"([A-Z]+)([A-Z][a-z])", "$1-$2"), @"([a-z\d])([A-Z])", "$1-$2") - , @"[-\s]+", "-", RegexOptions.Compiled).TrimEnd('-').ToLower(); - } - - public static string LowercaseHyphenToPascal(this string lowercaseHyphenatedInput) - { - return Regex.Replace( - lowercaseHyphenatedInput.Replace("-", " "), - @"\b([a-z])", - m => m.Captures[0].Value.ToUpper()); - } - - public static string TrimEnd(this string input, string trim) - { - if (string.IsNullOrEmpty(input)) return string.Empty; - - return input.EndsWith(trim, StringComparison.OrdinalIgnoreCase) - ? input.Substring(0, input.Length - trim.Length) - : input; - } - - public static string RemoveLeadingAndTrailingMultiLineComments(this string input) - { - var match = LeadingMultiLineComment.Match(input); - - if (match.Success) - { - input = input.Substring(match.Groups["value"].Value.Length); - } - - match = TrailingMultiLineComment.Match(input); - - if (match.Success) - { - input = input.Substring(0, input.Length - match.Groups["value"].Value.Length); - } - - return input; - } - - public static string RemoveLeadingSpacesAndAsterisk(this string input) - { - var match = LeadingSpacesAndAsterisk.Match(input); - if (match.Success) - { - input = input.Substring(match.Groups["value"].Value.Length); - } - - return input; - } - - /// - /// Removes the specified number of tabs (or spaces, assuming 4 spaces = 1 tab) - /// from each line of the input - /// - public static string RemoveNumberOfLeadingTabsOrSpacesAfterNewline(this string input, int numberOfTabs) - { - var leadingCharacterIndex = input.IndexOf("\t", StringComparison.OrdinalIgnoreCase); - - if (leadingCharacterIndex == -1) - { - leadingCharacterIndex = input.IndexOf(" ", StringComparison.OrdinalIgnoreCase); - - if (leadingCharacterIndex == -1) - { - return input; - } - } - - int count = 0; - char firstNonTabCharacter = char.MinValue; - - for (int i = leadingCharacterIndex; i < input.Length; i++) - { - if (input[i] != '\t' && input[i] != ' ') - { - firstNonTabCharacter = input[i]; - count = i - leadingCharacterIndex; - break; - } - } - - if (firstNonTabCharacter == '{' && numberOfTabs != count) - { - numberOfTabs = count; - } - - return Regex.Replace( - Regex.Replace( - input, - $"(?[\n|\r\n]+\t{{{numberOfTabs}}})", - m => m.Value.Replace("\t", string.Empty) - ), - $"(?[\n|\r\n]+\\s{{{numberOfTabs * 4}}})", - m => m.Value.Replace(" ", string.Empty) - ); - } - - public static string[] SplitOnNewLines(this string input, StringSplitOptions options) - { - return input.Split(new[] { "\r\n", "\n" }, options); - } + private static readonly Regex LeadingMultiLineComment = new Regex(@"^(?[ \t]*\/\*)", RegexOptions.Compiled); + private static readonly Regex LeadingSpacesAndAsterisk = new Regex(@"^(?[ \t]*\*\s?).*", RegexOptions.Compiled); // TODO: Total Hack of replacements in anonymous types that represent json. This can be resolved by referencing tests assembly when building the dynamic assembly, // but might want to put doc generation at same directory level as Tests to reference project directly. - private static Dictionary Substitutions = new Dictionary + private static readonly Dictionary Substitutions = new Dictionary { { "FixedDate", "new DateTime(2015, 06, 06, 12, 01, 02, 123)" }, { "FirstNameToFind", "\"pierce\"" }, { "Project.First.Suggest.Context.Values.SelectMany(v => v).First()", "\"red\"" }, { "Project.First.Suggest.Contexts.Values.SelectMany(v => v).First()", "\"red\"" }, { "Project.Instance.Name", "\"Durgan LLC\"" }, - { "Project.InstanceAnonymous", "new {name = \"Koch, Collier and Mohr\", state = \"BellyUp\",startedOn = " + - "\"2015-01-01T00:00:00\",lastActivity = \"0001-01-01T00:00:00\",leadDeveloper = " + - "new { gender = \"Male\", id = 0, firstName = \"Martijn\", lastName = \"Laarman\" }," + - "location = new { lat = 42.1523, lon = -80.321 }}" }, + { + "Project.InstanceAnonymous", "new {name = \"Koch, Collier and Mohr\", state = \"BellyUp\",startedOn = " + + "\"2015-01-01T00:00:00\",lastActivity = \"0001-01-01T00:00:00\",leadDeveloper = " + + "new { gender = \"Male\", id = 0, firstName = \"Martijn\", lastName = \"Laarman\" }," + + "location = new { lat = 42.1523, lon = -80.321 }}" + }, { "_templateString", "\"{ \\\"match\\\": { \\\"text\\\": \\\"{{query_string}}\\\" } }\"" }, - { "base.QueryJson", "new{ @bool = new { must = new[] { new { match_all = new { } } }, must_not = new[] { new { match_all = new { } } }, should = new[] { new { match_all = new { } } }, filter = new[] { new { match_all = new { } } }, minimum_should_match = 1, boost = 2.0, } }" }, + { + "base.QueryJson", + "new{ @bool = new { must = new[] { new { match_all = new { } } }, must_not = new[] { new { match_all = new { } } }, should = new[] { new { match_all = new { } } }, filter = new[] { new { match_all = new { } } }, minimum_should_match = 1, boost = 2.0, } }" + }, { "ExpectedTerms", "new [] { \"term1\", \"term2\" }" }, { "_ctxNumberofCommits", "\"_source.numberOfCommits > 0\"" }, { "Project.First.Name", "\"Lesch Group\"" }, @@ -149,8 +44,14 @@ public static string[] SplitOnNewLines(this string input, StringSplitOptions opt { "LastNameSearch", "\"Stokes\"" }, { "First.Language", "\"painless\"" }, { "First.Init", "\"params._agg.map = [:]\"" }, - { "First.Map", "\"if (params._agg.map.containsKey(doc['state'].value)) params._agg.map[doc['state'].value] += 1 else params._agg.map[doc['state'].value] = 1;\"" }, - { "First.Reduce", "\"def reduce = [:]; for (agg in params._aggs) { for (entry in agg.map.entrySet()) { if (reduce.containsKey(entry.getKey())) reduce[entry.getKey()] += entry.getValue(); else reduce[entry.getKey()] = entry.getValue(); } } return reduce;\"" }, + { + "First.Map", + "\"if (params._agg.map.containsKey(doc['state'].value)) params._agg.map[doc['state'].value] += 1 else params._agg.map[doc['state'].value] = 1;\"" + }, + { + "First.Reduce", + "\"def reduce = [:]; for (agg in params._aggs) { for (entry in agg.map.entrySet()) { if (reduce.containsKey(entry.getKey())) reduce[entry.getKey()] += entry.getValue(); else reduce[entry.getKey()] = entry.getValue(); } } return reduce;\"" + }, { "Second.Language", "\"painless\"" }, { "Second.Combine", "\"def sum = 0.0; for (c in params._agg.commits) { sum += c } return sum\"" }, { "Second.Init", "\"params._agg.commits = []\"" }, @@ -164,13 +65,16 @@ public static string[] SplitOnNewLines(this string input, StringSplitOptions opt { "EnvelopeCoordinates", @"new [] { new [] { 45.0, -45.0 }, new [] { -45.0, 45.0 }}" }, { "CircleCoordinates", @"new [] { 45.0, -45.0 }" }, { "MultiPointCoordinates", @"new [] { new [] {38.897676, -77.03653}, new [] {38.889939, -77.009051} }" }, - { "MultiLineStringCoordinates", @"new[] + { + "MultiLineStringCoordinates", @"new[] { new [] { new [] { 2.0, 12.0 }, new [] { 2.0, 13.0 },new [] { 3.0, 13.0 }, new []{ 3.0, 12.0 } }, new [] { new [] { 0.0, 10.0 }, new [] { 0.0, 11.0 },new [] { 1.0, 11.0 }, new []{ 1.0, 10.0 } }, new [] { new [] { 0.2, 10.2 }, new [] { 0.2, 10.8 },new [] { 0.8, 10.8 }, new []{ 0.8, 12.0 } }, - }" }, - { "MultiPolygonCoordinates", @"new[] + }" + }, + { + "MultiPolygonCoordinates", @"new[] { new [] { @@ -203,29 +107,123 @@ public static string[] SplitOnNewLines(this string input, StringSplitOptions opt new [] { 8.0, -15.0} } } - }" }, - { "PolygonCoordinates", @"new[]{ + }" + }, + { + "PolygonCoordinates", @"new[]{ new []{ new [] {10.0, -17.0}, new [] {15.0, 16.0}, new [] {0.0, 12.0}, new [] {-15.0, 16.0}, new [] {-10.0, -17.0},new [] {10.0, -17.0}}, new []{ new [] {8.2, 18.2}, new [] {8.2, -18.8}, new [] {-8.8, -10.8}, new [] {8.8, 18.2}} - }" }, + }" + }, { "LineStringCoordinates", @"new [] { new [] {38.897676, -77.03653}, new [] {38.889939, -77.009051} }" }, { "PointCoordinates", "new[] { 38.897676, -77.03653 }" }, - { "this._polygonCoordinates", @"new[]{ + { + "this._polygonCoordinates", @"new[]{ new []{ new [] {10.0, -17.0}, new [] {15.0, 16.0}, new [] {0.0, 12.0}, new [] {-15.0, 16.0}, new [] {-10.0, -17.0},new [] {10.0, -17.0}}, new []{ new [] {8.2, 18.2}, new [] {8.2, -18.8}, new [] {-8.8, -10.8}, new [] {8.8, 18.2}} - }" }, - { "ProjectFilterExpectedJson", "new {term = new {type = new {value = \"project\"}}}" } + }" + }, + { "ProjectFilterExpectedJson", "new {term = new {type = new {value = \"project\"}}}" } }; - public static bool TryGetJsonForAnonymousType(this string anonymousTypeString, out string json) + private static readonly Regex TrailingMultiLineComment = new Regex(@"(?\*\/[ \t]*)$", RegexOptions.Compiled); + + public static string PascalToHyphen(this string input) { - json = null; + if (string.IsNullOrEmpty(input)) return string.Empty; + + return Regex.Replace( + Regex.Replace( + Regex.Replace(input, @"([A-Z]+)([A-Z][a-z])", "$1-$2"), @"([a-z\d])([A-Z])", "$1-$2") + , @"[-\s]+", "-", RegexOptions.Compiled) + .TrimEnd('-') + .ToLower(); + } + + public static string LowercaseHyphenToPascal(this string lowercaseHyphenatedInput) => Regex.Replace( + lowercaseHyphenatedInput.Replace("-", " "), + @"\b([a-z])", + m => m.Captures[0].Value.ToUpper()); - foreach (var substitution in Substitutions) + public static string TrimEnd(this string input, string trim) + { + if (string.IsNullOrEmpty(input)) return string.Empty; + + return input.EndsWith(trim, StringComparison.OrdinalIgnoreCase) + ? input.Substring(0, input.Length - trim.Length) + : input; + } + + public static string RemoveLeadingAndTrailingMultiLineComments(this string input) + { + var match = LeadingMultiLineComment.Match(input); + + if (match.Success) input = input.Substring(match.Groups["value"].Value.Length); + + match = TrailingMultiLineComment.Match(input); + + if (match.Success) input = input.Substring(0, input.Length - match.Groups["value"].Value.Length); + + return input; + } + + public static string RemoveLeadingSpacesAndAsterisk(this string input) + { + var match = LeadingSpacesAndAsterisk.Match(input); + if (match.Success) input = input.Substring(match.Groups["value"].Value.Length); + + return input; + } + + /// + /// Removes the specified number of tabs (or spaces, assuming 4 spaces = 1 tab) + /// from each line of the input + /// + public static string RemoveNumberOfLeadingTabsOrSpacesAfterNewline(this string input, int numberOfTabs) + { + var leadingCharacterIndex = input.IndexOf("\t", StringComparison.OrdinalIgnoreCase); + + if (leadingCharacterIndex == -1) { - anonymousTypeString = anonymousTypeString.Replace(substitution.Key, substitution.Value); + leadingCharacterIndex = input.IndexOf(" ", StringComparison.OrdinalIgnoreCase); + + if (leadingCharacterIndex == -1) return input; + } + + var count = 0; + var firstNonTabCharacter = char.MinValue; + + for (var i = leadingCharacterIndex; i < input.Length; i++) + { + if (input[i] != '\t' && input[i] != ' ') + { + firstNonTabCharacter = input[i]; + count = i - leadingCharacterIndex; + break; + } } + if (firstNonTabCharacter == '{' && numberOfTabs != count) numberOfTabs = count; + + return Regex.Replace( + Regex.Replace( + input, + $"(?[\n|\r\n]+\t{{{numberOfTabs}}})", + m => m.Value.Replace("\t", string.Empty) + ), + $"(?[\n|\r\n]+\\s{{{numberOfTabs * 4}}})", + m => m.Value.Replace(" ", string.Empty) + ); + } + + public static string[] SplitOnNewLines(this string input, StringSplitOptions options) => input.Split(new[] { "\r\n", "\n" }, options); + + public static bool TryGetJsonForAnonymousType(this string anonymousTypeString, out string json) + { + json = null; + + foreach (var substitution in Substitutions) anonymousTypeString = anonymousTypeString.Replace(substitution.Key, substitution.Value); + var text = $@" using System; @@ -288,10 +286,7 @@ public string Write() diagnostic.Severity == DiagnosticSeverity.Error); var builder = new StringBuilder($"Unable to serialize the following C# anonymous type string to json: {anonymousTypeString}"); - foreach (var diagnostic in failures) - { - builder.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}"); - } + foreach (var diagnostic in failures) builder.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}"); builder.AppendLine(new string('-', 30)); Console.Error.WriteLine(builder.ToString()); @@ -315,18 +310,18 @@ public string Write() } } - public static string ReplaceArityWithGenericSignature(this string value) - { - var indexOfBackTick = value.IndexOf("`"); + public static string ReplaceArityWithGenericSignature(this string value) + { + var indexOfBackTick = value.IndexOf("`"); - if (indexOfBackTick == -1) - return value; + if (indexOfBackTick == -1) + return value; - var arity = value[indexOfBackTick + 1]; - value = value.Substring(0, indexOfBackTick); + var arity = value[indexOfBackTick + 1]; + value = value.Substring(0, indexOfBackTick); - return Enumerable.Range(1, int.Parse(arity.ToString())) - .Aggregate(value + "<", (l, i) => l = l + (i == 1 ? "T" : $"T{i}")) + ">"; - } + return Enumerable.Range(1, int.Parse(arity.ToString())) + .Aggregate(value + "<", (l, i) => l = l + (i == 1 ? "T" : $"T{i}")) + ">"; + } } } diff --git a/src/CodeGeneration/DocGenerator/SyntaxNodeExtensions.cs b/src/CodeGeneration/DocGenerator/SyntaxNodeExtensions.cs index 0f88029efe1..0639c819db7 100644 --- a/src/CodeGeneration/DocGenerator/SyntaxNodeExtensions.cs +++ b/src/CodeGeneration/DocGenerator/SyntaxNodeExtensions.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Text.RegularExpressions; using Microsoft.CodeAnalysis; @@ -9,99 +8,94 @@ namespace DocGenerator { public static class SyntaxNodeExtensions { - private static readonly Regex SingleLineHideComment = new Regex(@"\/\/\s*hide", RegexOptions.Compiled); - private static readonly Regex SingleLineJsonComment = new Regex(@"\/\/\s*json", RegexOptions.Compiled); - - /// - /// Determines if the node should be hidden i.e. not included in the documentation, - /// based on the precedence of a //hide single line comment - /// - public static bool ShouldBeHidden(this SyntaxNode node) => - node.HasLeadingTrivia && ShouldBeHidden(node, node.GetLeadingTrivia()); - - public static bool ShouldBeHidden(this SyntaxNode node, SyntaxTriviaList leadingTrivia) => - leadingTrivia != default(SyntaxTriviaList) && - SingleLineHideComment.IsMatch(node.GetLeadingTrivia().ToFullString()); - - /// - /// Determines if the node should be json serialized based on the precedence of - /// a //json single line comment - /// - public static bool ShouldBeConvertedToJson(this SyntaxNode node) => - node.HasLeadingTrivia && ShouldBeConvertedToJson(node, node.GetLeadingTrivia()); - - /// - /// Determines if the node should be json serialized based on the precedence of - /// a //json single line comment - /// - public static bool ShouldBeConvertedToJson(this SyntaxNode node, SyntaxTriviaList leadingTrivia) - { - if (leadingTrivia == default(SyntaxTriviaList)) - return false; - - var singleLineCommentIndex = leadingTrivia.IndexOf(SyntaxKind.SingleLineCommentTrivia); - - if (singleLineCommentIndex == -1) - return false; - - // all trivia after the single line should be whitespace or end of line - if (!leadingTrivia - .SkipWhile((l, i) => i < singleLineCommentIndex) - .Any(l => l.IsKind(SyntaxKind.EndOfLineTrivia) || l.IsKind(SyntaxKind.WhitespaceTrivia))) - { - return false; - } - - return SingleLineJsonComment.IsMatch(leadingTrivia.ElementAt(singleLineCommentIndex).ToFullString()); - } - - /// - /// Determines if the node is preceded by any multiline documentation. - /// - /// The node. - public static bool HasMultiLineDocumentationCommentTrivia(this SyntaxNode node) => - node.HasLeadingTrivia && - node.GetLeadingTrivia().Any(c => c.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia)); - - /// - /// Try to get the json representation of the first anonymous object expression descendent - /// node. - /// - /// - /// - /// - public static bool TryGetJsonForSyntaxNode(this SyntaxNode node, out string json) - { - json = null; - - // find the first anonymous object expression - var creationExpressionSyntax = node.DescendantNodes() - .OfType() - .FirstOrDefault(); - - return creationExpressionSyntax != null && - creationExpressionSyntax.ToFullString().TryGetJsonForAnonymousType(out json); - } - - /// - /// Gets the starting line of the node - /// - /// The node. - /// - public static int StartingLine(this SyntaxNode node) => - node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; - - public static SyntaxNode WithLeadingEndOfLineTrivia(this SyntaxNode node) - { - var leadingTrivia = node.GetLeadingTrivia(); - var triviaToRemove = leadingTrivia.Reverse().SkipWhile(t => t.IsKind(SyntaxKind.EndOfLineTrivia)); - foreach (var syntaxTrivia in triviaToRemove) - { - node = node.ReplaceTrivia(syntaxTrivia, default(SyntaxTrivia)); - } - - return node; - } + private static readonly Regex SingleLineHideComment = new Regex(@"\/\/\s*hide", RegexOptions.Compiled); + private static readonly Regex SingleLineJsonComment = new Regex(@"\/\/\s*json", RegexOptions.Compiled); + + /// + /// Determines if the node should be hidden i.e. not included in the documentation, + /// based on the precedence of a //hide single line comment + /// + public static bool ShouldBeHidden(this SyntaxNode node) => + node.HasLeadingTrivia && ShouldBeHidden(node, node.GetLeadingTrivia()); + + public static bool ShouldBeHidden(this SyntaxNode node, SyntaxTriviaList leadingTrivia) => + leadingTrivia != default(SyntaxTriviaList) && + SingleLineHideComment.IsMatch(node.GetLeadingTrivia().ToFullString()); + + /// + /// Determines if the node should be json serialized based on the precedence of + /// a //json single line comment + /// + public static bool ShouldBeConvertedToJson(this SyntaxNode node) => + node.HasLeadingTrivia && ShouldBeConvertedToJson(node, node.GetLeadingTrivia()); + + /// + /// Determines if the node should be json serialized based on the precedence of + /// a //json single line comment + /// + public static bool ShouldBeConvertedToJson(this SyntaxNode node, SyntaxTriviaList leadingTrivia) + { + if (leadingTrivia == default(SyntaxTriviaList)) + return false; + + var singleLineCommentIndex = leadingTrivia.IndexOf(SyntaxKind.SingleLineCommentTrivia); + + if (singleLineCommentIndex == -1) + return false; + + // all trivia after the single line should be whitespace or end of line + if (!leadingTrivia + .SkipWhile((l, i) => i < singleLineCommentIndex) + .Any(l => l.IsKind(SyntaxKind.EndOfLineTrivia) || l.IsKind(SyntaxKind.WhitespaceTrivia))) + return false; + + return SingleLineJsonComment.IsMatch(leadingTrivia.ElementAt(singleLineCommentIndex).ToFullString()); + } + + /// + /// Determines if the node is preceded by any multiline documentation. + /// + /// The node. + public static bool HasMultiLineDocumentationCommentTrivia(this SyntaxNode node) => + node.HasLeadingTrivia && + node.GetLeadingTrivia().Any(c => c.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia)); + + /// + /// Try to get the json representation of the first anonymous object expression descendent + /// node. + /// + /// + /// + /// + public static bool TryGetJsonForSyntaxNode(this SyntaxNode node, out string json) + { + json = null; + + // find the first anonymous object expression + var creationExpressionSyntax = node.DescendantNodes() + .OfType() + .FirstOrDefault(); + + return creationExpressionSyntax != null && + creationExpressionSyntax.ToFullString().TryGetJsonForAnonymousType(out json); + } + + /// + /// Gets the starting line of the node + /// + /// The node. + /// + public static int StartingLine(this SyntaxNode node) => + node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; + + public static SyntaxNode WithLeadingEndOfLineTrivia(this SyntaxNode node) + { + var leadingTrivia = node.GetLeadingTrivia(); + var triviaToRemove = leadingTrivia.Reverse().SkipWhile(t => t.IsKind(SyntaxKind.EndOfLineTrivia)); + foreach (var syntaxTrivia in triviaToRemove) node = node.ReplaceTrivia(syntaxTrivia, default(SyntaxTrivia)); + + return node; + } /// /// Gets the text representation of a syntax node without #pragma directives @@ -113,5 +107,5 @@ public static string ToFullStringWithoutPragmaWarningDirectiveTrivia(this Syntax var pragma = node.DescendantTrivia(s => true, true).Where(t => t.IsKind(SyntaxKind.PragmaWarningDirectiveTrivia)); return node.ReplaceTrivia(pragma, (s, r) => default(SyntaxTrivia)).ToFullString(); } - } + } } diff --git a/src/CodeGeneration/DocGenerator/Walkers/CSharpDocumentationFileWalker.cs b/src/CodeGeneration/DocGenerator/Walkers/CSharpDocumentationFileWalker.cs index 392705f5ac1..bb3665ca291 100644 --- a/src/CodeGeneration/DocGenerator/Walkers/CSharpDocumentationFileWalker.cs +++ b/src/CodeGeneration/DocGenerator/Walkers/CSharpDocumentationFileWalker.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Text; using DocGenerator.Documentation.Blocks; using Microsoft.CodeAnalysis; @@ -9,289 +10,249 @@ namespace DocGenerator.Walkers { - /// - /// Walks a C# syntax tree, extracting out code and multiline comments for use - /// within asciidoc documentation - /// - public class CSharpDocumentationFileWalker : CSharpSyntaxWalker - { - protected readonly IList Blocks; - - public CSharpDocumentationFileWalker(IList blocks) : base(SyntaxWalkerDepth.StructuredTrivia) - { - Blocks = blocks; - } - - protected int ClassDepth { get; set; } - - public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) - { - if (node.ShouldBeHidden()) return; - - if (node.ChildNodes().All(childNode => childNode.IsKind(SyntaxKind.PropertyDeclaration) || - childNode.IsKind(SyntaxKind.AttributeList))) - { - // simple nested interface - AddNestedType(node); - } - } - - public override void VisitClassDeclaration(ClassDeclarationSyntax node) - { - if (node.ShouldBeHidden()) return; - - ++ClassDepth; - if (ClassDepth == 1) - { - // walk the top level class - base.VisitClassDeclaration(node); - } - else if (node.ChildNodes().All(childNode => childNode.IsKind(SyntaxKind.PropertyDeclaration) || - childNode.IsKind(SyntaxKind.AttributeList))) - { - // we have a simple nested POCO class inside of a class - AddNestedType(node); - } - else - { - var methods = node.ChildNodes().OfType(); - if (!methods.Any(m => m.AttributeLists.SelectMany(a => a.Attributes).Any())) - { - // nested class with methods that are not unit or integration tests - // e.g. example PropertyVisitor in Automap.doc.cs - AddNestedType(node); - } - } - --ClassDepth; - } - - protected virtual bool SerializePropertyDeclarationToJson(PropertyDeclarationSyntax node) => false; - - public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) - { - var trivia = node.HasLeadingTrivia - ? node.GetLeadingTrivia() - : default(SyntaxTriviaList); - - if (node.ShouldBeHidden(trivia)) return; - - // multiline comment on property - AddMultiLineDocumentationComment(trivia); - - // allow derived types to determine if this method should be json serialized - if (SerializePropertyDeclarationToJson(node)) return; - - var memberName = node.Identifier.Text; - - // decide whether we should strip the modifier/accessor and return type, based on if - // this is a property on the top level class - if (ClassDepth == 1) - { - var arrowExpressionClauseSyntax = - node.ChildNodes().OfType().FirstOrDefault(); - - if (arrowExpressionClauseSyntax != null) - { - var firstChildNode = arrowExpressionClauseSyntax.ChildNodes().First(); - Blocks.Add(new CSharpBlock(firstChildNode, ClassDepth, memberName)); - } - else - { - // property getter - var blockNode = node.DescendantNodes().OfType().FirstOrDefault(); - - if (blockNode != null) - { - AddBlockChildNodes(blockNode, memberName); - } - } - } - else - { - // assume this is a nested class' property - Blocks.Add(new CSharpBlock(node, ClassDepth, memberName)); - } - - if (node.HasTrailingTrivia) - { - trivia = node.GetTrailingTrivia(); - AddMultiLineDocumentationComment(trivia); - } - } - - protected virtual bool SerializeMethodDeclarationToJson(MethodDeclarationSyntax node) => false; - - public override void VisitMethodDeclaration(MethodDeclarationSyntax node) - { - var leadingTrivia = node.HasLeadingTrivia - ? node.GetLeadingTrivia() - : default(SyntaxTriviaList); - - // multiline comment on method - AddMultiLineDocumentationComment(leadingTrivia); - - if (node.ShouldBeHidden(leadingTrivia)) return; - - // allow derived types to determine if this method should be json serialized - if (SerializeMethodDeclarationToJson(node)) return; - - var memberName = node.Identifier.Text; - - foreach(var blockNode in node.ChildNodes().OfType()) - { - AddBlockChildNodes(blockNode, memberName); - } - - foreach (var syntax in node.ChildNodes().Where(c => c.IsKind(SyntaxKind.ArrowExpressionClause))) - { - var syntaxNode = syntax.ChildNodes().First(); - Blocks.Add(new CSharpBlock(syntaxNode, ClassDepth, memberName)); - } - } - - public override void VisitTrivia(SyntaxTrivia trivia) - { - if (!trivia.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia)) - { - base.VisitTrivia(trivia); - return; - } - - var tokens = trivia.ToFullString() - .RemoveLeadingAndTrailingMultiLineComments() - .SplitOnNewLines(StringSplitOptions.None); - var builder = new StringBuilder(); - - foreach (var token in tokens) - { - var currentToken = token.RemoveLeadingSpacesAndAsterisk(); - var decodedToken = System.Net.WebUtility.HtmlDecode(currentToken); - builder.AppendLine(decodedToken); - } - - var text = builder.ToString(); - var line = trivia.SyntaxTree.GetLineSpan(trivia.Span).StartLinePosition.Line; - - Blocks.Add(new TextBlock(text, line)); - } - - private void AddNestedType(BaseTypeDeclarationSyntax node) - { - var blockAdded = false; - - if (node.HasLeadingTrivia) - { - var leadingTrivia = node.GetLeadingTrivia(); - - if (node.ShouldBeHidden(leadingTrivia)) - { - return; - } - - // inline multiline comment - AddMultiLineDocumentationComment(leadingTrivia); - - if (node.ShouldBeConvertedToJson(leadingTrivia)) - { - string json; - if (node.TryGetJsonForSyntaxNode(out json)) - { - var startingLine = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; - Blocks.Add(new JavaScriptBlock(json, startingLine, ClassDepth, node.Identifier.Text)); - blockAdded = true; - } - } - } - - if (!blockAdded) - { - Blocks.Add(new CSharpBlock(node, ClassDepth)); - } - } - - private void AddBlockChildNodes(BlockSyntax node, string memberName) - { - CSharpBlock codeBlock = null; - foreach (var blockChildNode in node.ChildNodes()) - { - if (blockChildNode.HasLeadingTrivia) - { - var trivia = blockChildNode.GetLeadingTrivia(); - - // inside method multiline comment - AddMultiLineDocumentationComment(trivia, () => - { - // flush what we may have collected so far - if (codeBlock != null) - { - Blocks.Add(codeBlock); - codeBlock = null; - } - }); - - if (blockChildNode.ShouldBeHidden(trivia)) - continue; - - if (blockChildNode.ShouldBeConvertedToJson(trivia)) - { - string json; - if (blockChildNode.TryGetJsonForSyntaxNode(out json)) - { - // flush what we may have collected so far - if (codeBlock != null) - { - Blocks.Add(codeBlock); - codeBlock = null; - } - - var startingLine = blockChildNode.StartingLine(); - Blocks.Add(new JavaScriptBlock(json, startingLine, ClassDepth, memberName)); - continue; - } - } - } - - if (codeBlock == null) - { - codeBlock = new CSharpBlock(blockChildNode, ClassDepth, memberName); - } - else - { - codeBlock.AddNode(blockChildNode); - } - - if (blockChildNode.HasTrailingTrivia) - { - var trivia = blockChildNode.GetTrailingTrivia(); - AddMultiLineDocumentationComment(trivia, () => - { - // flush what we may have collected so far - if (codeBlock != null) - { - Blocks.Add(codeBlock); - codeBlock = null; - } - }); - } - } - - if (codeBlock != null) - { - Blocks.Add(codeBlock); - } - } - - private void AddMultiLineDocumentationComment(SyntaxTriviaList leadingTrivia, Action actionIfFound = null) - { - if (leadingTrivia.Any(l => l.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia))) - { - actionIfFound?.Invoke(); - - foreach (var trivia in leadingTrivia) - { - VisitTrivia(trivia); - } - } - } - } -} \ No newline at end of file + /// + /// Walks a C# syntax tree, extracting out code and multiline comments for use + /// within asciidoc documentation + /// + public class CSharpDocumentationFileWalker : CSharpSyntaxWalker + { + protected readonly IList Blocks; + + public CSharpDocumentationFileWalker(IList blocks) : base(SyntaxWalkerDepth.StructuredTrivia) => Blocks = blocks; + + protected int ClassDepth { get; set; } + + public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) + { + if (node.ShouldBeHidden()) return; + + if (node.ChildNodes() + .All(childNode => childNode.IsKind(SyntaxKind.PropertyDeclaration) || + childNode.IsKind(SyntaxKind.AttributeList))) + AddNestedType(node); + } + + public override void VisitClassDeclaration(ClassDeclarationSyntax node) + { + if (node.ShouldBeHidden()) return; + + ++ClassDepth; + if (ClassDepth == 1) + base.VisitClassDeclaration(node); + else if (node.ChildNodes() + .All(childNode => childNode.IsKind(SyntaxKind.PropertyDeclaration) || + childNode.IsKind(SyntaxKind.AttributeList))) + AddNestedType(node); + else + { + var methods = node.ChildNodes().OfType(); + if (!methods.Any(m => m.AttributeLists.SelectMany(a => a.Attributes).Any())) AddNestedType(node); + } + --ClassDepth; + } + + protected virtual bool SerializePropertyDeclarationToJson(PropertyDeclarationSyntax node) => false; + + public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) + { + var trivia = node.HasLeadingTrivia + ? node.GetLeadingTrivia() + : default(SyntaxTriviaList); + + if (node.ShouldBeHidden(trivia)) return; + + // multiline comment on property + AddMultiLineDocumentationComment(trivia); + + // allow derived types to determine if this method should be json serialized + if (SerializePropertyDeclarationToJson(node)) return; + + var memberName = node.Identifier.Text; + + // decide whether we should strip the modifier/accessor and return type, based on if + // this is a property on the top level class + if (ClassDepth == 1) + { + var arrowExpressionClauseSyntax = + node.ChildNodes().OfType().FirstOrDefault(); + + if (arrowExpressionClauseSyntax != null) + { + var firstChildNode = arrowExpressionClauseSyntax.ChildNodes().First(); + Blocks.Add(new CSharpBlock(firstChildNode, ClassDepth, memberName)); + } + else + { + // property getter + var blockNode = node.DescendantNodes().OfType().FirstOrDefault(); + + if (blockNode != null) AddBlockChildNodes(blockNode, memberName); + } + } + else + Blocks.Add(new CSharpBlock(node, ClassDepth, memberName)); + + if (node.HasTrailingTrivia) + { + trivia = node.GetTrailingTrivia(); + AddMultiLineDocumentationComment(trivia); + } + } + + protected virtual bool SerializeMethodDeclarationToJson(MethodDeclarationSyntax node) => false; + + public override void VisitMethodDeclaration(MethodDeclarationSyntax node) + { + var leadingTrivia = node.HasLeadingTrivia + ? node.GetLeadingTrivia() + : default(SyntaxTriviaList); + + // multiline comment on method + AddMultiLineDocumentationComment(leadingTrivia); + + if (node.ShouldBeHidden(leadingTrivia)) return; + + // allow derived types to determine if this method should be json serialized + if (SerializeMethodDeclarationToJson(node)) return; + + var memberName = node.Identifier.Text; + + foreach (var blockNode in node.ChildNodes().OfType()) AddBlockChildNodes(blockNode, memberName); + + foreach (var syntax in node.ChildNodes().Where(c => c.IsKind(SyntaxKind.ArrowExpressionClause))) + { + var syntaxNode = syntax.ChildNodes().First(); + Blocks.Add(new CSharpBlock(syntaxNode, ClassDepth, memberName)); + } + } + + public override void VisitTrivia(SyntaxTrivia trivia) + { + if (!trivia.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia)) + { + base.VisitTrivia(trivia); + return; + } + + var tokens = trivia.ToFullString() + .RemoveLeadingAndTrailingMultiLineComments() + .SplitOnNewLines(StringSplitOptions.None); + var builder = new StringBuilder(); + + foreach (var token in tokens) + { + var currentToken = token.RemoveLeadingSpacesAndAsterisk(); + var decodedToken = WebUtility.HtmlDecode(currentToken); + builder.AppendLine(decodedToken); + } + + var text = builder.ToString(); + var line = trivia.SyntaxTree.GetLineSpan(trivia.Span).StartLinePosition.Line; + + Blocks.Add(new TextBlock(text, line)); + } + + private void AddNestedType(BaseTypeDeclarationSyntax node) + { + var blockAdded = false; + + if (node.HasLeadingTrivia) + { + var leadingTrivia = node.GetLeadingTrivia(); + + if (node.ShouldBeHidden(leadingTrivia)) return; + + // inline multiline comment + AddMultiLineDocumentationComment(leadingTrivia); + + if (node.ShouldBeConvertedToJson(leadingTrivia)) + { + string json; + if (node.TryGetJsonForSyntaxNode(out json)) + { + var startingLine = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; + Blocks.Add(new JavaScriptBlock(json, startingLine, ClassDepth, node.Identifier.Text)); + blockAdded = true; + } + } + } + + if (!blockAdded) Blocks.Add(new CSharpBlock(node, ClassDepth)); + } + + private void AddBlockChildNodes(BlockSyntax node, string memberName) + { + CSharpBlock codeBlock = null; + foreach (var blockChildNode in node.ChildNodes()) + { + if (blockChildNode.HasLeadingTrivia) + { + var trivia = blockChildNode.GetLeadingTrivia(); + + // inside method multiline comment + AddMultiLineDocumentationComment(trivia, () => + { + // flush what we may have collected so far + if (codeBlock != null) + { + Blocks.Add(codeBlock); + codeBlock = null; + } + }); + + if (blockChildNode.ShouldBeHidden(trivia)) + continue; + + if (blockChildNode.ShouldBeConvertedToJson(trivia)) + { + string json; + if (blockChildNode.TryGetJsonForSyntaxNode(out json)) + { + // flush what we may have collected so far + if (codeBlock != null) + { + Blocks.Add(codeBlock); + codeBlock = null; + } + + var startingLine = blockChildNode.StartingLine(); + Blocks.Add(new JavaScriptBlock(json, startingLine, ClassDepth, memberName)); + continue; + } + } + } + + if (codeBlock == null) + codeBlock = new CSharpBlock(blockChildNode, ClassDepth, memberName); + else + codeBlock.AddNode(blockChildNode); + + if (blockChildNode.HasTrailingTrivia) + { + var trivia = blockChildNode.GetTrailingTrivia(); + AddMultiLineDocumentationComment(trivia, () => + { + // flush what we may have collected so far + if (codeBlock != null) + { + Blocks.Add(codeBlock); + codeBlock = null; + } + }); + } + } + + if (codeBlock != null) Blocks.Add(codeBlock); + } + + private void AddMultiLineDocumentationComment(SyntaxTriviaList leadingTrivia, Action actionIfFound = null) + { + if (leadingTrivia.Any(l => l.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia))) + { + actionIfFound?.Invoke(); + + foreach (var trivia in leadingTrivia) VisitTrivia(trivia); + } + } + } +} diff --git a/src/CodeGeneration/DocGenerator/Walkers/DocConverter.cs b/src/CodeGeneration/DocGenerator/Walkers/DocConverter.cs index 59571bcc8e1..9e932192b7b 100644 --- a/src/CodeGeneration/DocGenerator/Walkers/DocConverter.cs +++ b/src/CodeGeneration/DocGenerator/Walkers/DocConverter.cs @@ -1,176 +1,159 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using DocGenerator.Documentation.Blocks; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; namespace DocGenerator.Walkers { - public class DocConverter - { - public async Task> ConvertAsync(Document document) - { - var node = await document.GetSyntaxRootAsync().ConfigureAwait(false); - string fileName = document.Name; - IList blocks = new List(); - - // use different walking rules for different source files - if (fileName.EndsWith("UsageTests.cs", StringComparison.OrdinalIgnoreCase) || - fileName.Equals("WritingAggregations.doc.cs", StringComparison.OrdinalIgnoreCase)) - { - var walker = new UsageTestsWalker(blocks); - walker.Visit(node); - - // apply the usage conventions to writing aggregations, - // but don't rearrange any blocks - if (!fileName.Equals("WritingAggregations.doc.cs", StringComparison.OrdinalIgnoreCase)) - { - blocks = RearrangeCodeBlocks(blocks); - } - } - else - { - var walker = new CSharpDocumentationFileWalker(blocks); - walker.Visit(node); - blocks = CondenseCodeBlocks(blocks); - } - - return blocks; - } - - private IList CondenseCodeBlocks(IList blocks) - { - var newBlocks = new List(blocks.Count); - for (int i = 0; i < blocks.Count; i++) - { - var block = blocks[i]; - var codeBlock = block as CodeBlock; - if (codeBlock == null) - { - newBlocks.Add(block); - continue; - } - - if (newBlocks.LastOrDefault() is CodeBlock previousBlock && previousBlock.Language == codeBlock.Language) - { - previousBlock.AddLine(Environment.NewLine); - previousBlock.AddLine(codeBlock.Value); - } - else - { - newBlocks.Add(codeBlock); - } - } - - return newBlocks; - } - - /// - /// Rearranges the code blocks in usage tests so that they follow the order: - /// 1. Fluent Example - /// 2. Object Initializer Example - /// 3. Example json - /// - /// The blocks. - /// - private IList RearrangeCodeBlocks(IList blocks) - { - var newBlocks = new List(blocks.Count); - var seenFluentExample = false; - var seenInitializerExample = false; - int index = -1; - - CodeBlock javascriptBlock = null; - CodeBlock initializerExample = null; - - for (int i = 0; i < blocks.Count; i++) - { - if (seenFluentExample && seenInitializerExample && javascriptBlock != null) - { - newBlocks.Insert(index + 1, javascriptBlock); - javascriptBlock = null; - seenFluentExample = false; - seenInitializerExample = false; - index = -1; - } - - var block = blocks[i]; - - var codeBlock = block as CodeBlock; - if (codeBlock == null) - { - newBlocks.Add(block); - continue; - } - - if (codeBlock.Language == "javascript") - { - ((JavaScriptBlock) codeBlock).Title = "Example json output"; - - if (seenFluentExample && seenInitializerExample) - { - newBlocks.Insert(index + 1, codeBlock); - seenFluentExample = false; - seenInitializerExample = false; - index = -1; - } - else - { - javascriptBlock = codeBlock; - } - } - else - { - if (codeBlock.MemberName != null && codeBlock.MemberName.Contains("fluent")) - { - seenFluentExample = true; - newBlocks.Add(codeBlock); - index = newBlocks.IndexOf(codeBlock); - - if (initializerExample != null) - { - newBlocks.Add(initializerExample); - index = newBlocks.IndexOf(initializerExample); - initializerExample = null; - } - } - else if (codeBlock.MemberName != null && codeBlock.MemberName.Contains("initializer")) - { - seenInitializerExample = true; - - if (seenFluentExample) - { - newBlocks.Add(codeBlock); - index = newBlocks.IndexOf(codeBlock); - } - else - { - initializerExample = codeBlock; - } - } - else - { - newBlocks.Add(codeBlock); - } - } - - if (i == blocks.Count - 1 && javascriptBlock != null) - { - if (seenFluentExample && seenInitializerExample) - { - newBlocks.Insert(index + 1, javascriptBlock); - } - else - { - newBlocks.Add(javascriptBlock); - } - } - } - - return newBlocks; - } - } + public class DocConverter + { + public async Task> ConvertAsync(Document document) + { + var node = await document.GetSyntaxRootAsync().ConfigureAwait(false); + var fileName = document.Name; + IList blocks = new List(); + + // use different walking rules for different source files + if (fileName.EndsWith("UsageTests.cs", StringComparison.OrdinalIgnoreCase) || + fileName.Equals("WritingAggregations.doc.cs", StringComparison.OrdinalIgnoreCase)) + { + var walker = new UsageTestsWalker(blocks); + walker.Visit(node); + + // apply the usage conventions to writing aggregations, + // but don't rearrange any blocks + if (!fileName.Equals("WritingAggregations.doc.cs", StringComparison.OrdinalIgnoreCase)) blocks = RearrangeCodeBlocks(blocks); + } + else + { + var walker = new CSharpDocumentationFileWalker(blocks); + walker.Visit(node); + blocks = CondenseCodeBlocks(blocks); + } + + return blocks; + } + + private IList CondenseCodeBlocks(IList blocks) + { + var newBlocks = new List(blocks.Count); + for (var i = 0; i < blocks.Count; i++) + { + var block = blocks[i]; + var codeBlock = block as CodeBlock; + if (codeBlock == null) + { + newBlocks.Add(block); + continue; + } + + if (newBlocks.LastOrDefault() is CodeBlock previousBlock && previousBlock.Language == codeBlock.Language) + { + previousBlock.AddLine(Environment.NewLine); + previousBlock.AddLine(codeBlock.Value); + } + else + newBlocks.Add(codeBlock); + } + + return newBlocks; + } + + /// + /// Rearranges the code blocks in usage tests so that they follow the order: + /// 1. Fluent Example + /// 2. Object Initializer Example + /// 3. Example json + /// + /// The blocks. + /// + private IList RearrangeCodeBlocks(IList blocks) + { + var newBlocks = new List(blocks.Count); + var seenFluentExample = false; + var seenInitializerExample = false; + var index = -1; + + CodeBlock javascriptBlock = null; + CodeBlock initializerExample = null; + + for (var i = 0; i < blocks.Count; i++) + { + if (seenFluentExample && seenInitializerExample && javascriptBlock != null) + { + newBlocks.Insert(index + 1, javascriptBlock); + javascriptBlock = null; + seenFluentExample = false; + seenInitializerExample = false; + index = -1; + } + + var block = blocks[i]; + + var codeBlock = block as CodeBlock; + if (codeBlock == null) + { + newBlocks.Add(block); + continue; + } + + if (codeBlock.Language == "javascript") + { + ((JavaScriptBlock)codeBlock).Title = "Example json output"; + + if (seenFluentExample && seenInitializerExample) + { + newBlocks.Insert(index + 1, codeBlock); + seenFluentExample = false; + seenInitializerExample = false; + index = -1; + } + else + javascriptBlock = codeBlock; + } + else + { + if (codeBlock.MemberName != null && codeBlock.MemberName.Contains("fluent")) + { + seenFluentExample = true; + newBlocks.Add(codeBlock); + index = newBlocks.IndexOf(codeBlock); + + if (initializerExample != null) + { + newBlocks.Add(initializerExample); + index = newBlocks.IndexOf(initializerExample); + initializerExample = null; + } + } + else if (codeBlock.MemberName != null && codeBlock.MemberName.Contains("initializer")) + { + seenInitializerExample = true; + + if (seenFluentExample) + { + newBlocks.Add(codeBlock); + index = newBlocks.IndexOf(codeBlock); + } + else + initializerExample = codeBlock; + } + else + newBlocks.Add(codeBlock); + } + + if (i == blocks.Count - 1 && javascriptBlock != null) + { + if (seenFluentExample && seenInitializerExample) + newBlocks.Insert(index + 1, javascriptBlock); + else + newBlocks.Add(javascriptBlock); + } + } + + return newBlocks; + } + } } diff --git a/src/CodeGeneration/DocGenerator/Walkers/UsageTestsWalker.cs b/src/CodeGeneration/DocGenerator/Walkers/UsageTestsWalker.cs index ccdd0fa7630..74534ae9e5d 100644 --- a/src/CodeGeneration/DocGenerator/Walkers/UsageTestsWalker.cs +++ b/src/CodeGeneration/DocGenerator/Walkers/UsageTestsWalker.cs @@ -6,64 +6,58 @@ namespace DocGenerator.Walkers { - public class UsageTestsWalker : CSharpDocumentationFileWalker - { - public UsageTestsWalker(IList blocks) : base(blocks) - { - } - - private static readonly string[] ConvertToJson = { - "ExpectJson", - "QueryJson", - "AggregationJson" - }; - - private static readonly string[] MembersOfInterest = { - "ExpectJson", - "QueryJson", - "AggregationJson", - "Fluent", - "Initializer", - "QueryFluent", - "QueryInitializer", - "ExpectResponse", - "FluentAggs", - "InitializerAggs" - }; - - public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) - { - if (MembersOfInterest.Contains(node.Identifier.Text)) - { - base.VisitPropertyDeclaration(node); - } - } - - public override void VisitMethodDeclaration(MethodDeclarationSyntax node) - { - if (MembersOfInterest.Contains(node.Identifier.Text)) - { - base.VisitMethodDeclaration(node); - } - } - - protected override bool SerializePropertyDeclarationToJson(PropertyDeclarationSyntax node) => - SerializeToJson(node, node.Identifier.Text); - - protected override bool SerializeMethodDeclarationToJson(MethodDeclarationSyntax node) => - SerializeToJson(node, node.Identifier.Text); - - private bool SerializeToJson(SyntaxNode node, string memberName) - { - if (!ConvertToJson.Contains(memberName)) return false; - - if (node.TryGetJsonForSyntaxNode(out var json)) - { - var startingLine = node.StartingLine(); - Blocks.Add(new JavaScriptBlock(json, startingLine, ClassDepth, memberName)); - } - - return true; - } - } + public class UsageTestsWalker : CSharpDocumentationFileWalker + { + private static readonly string[] ConvertToJson = + { + "ExpectJson", + "QueryJson", + "AggregationJson" + }; + + private static readonly string[] MembersOfInterest = + { + "ExpectJson", + "QueryJson", + "AggregationJson", + "Fluent", + "Initializer", + "QueryFluent", + "QueryInitializer", + "ExpectResponse", + "FluentAggs", + "InitializerAggs" + }; + + public UsageTestsWalker(IList blocks) : base(blocks) { } + + public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) + { + if (MembersOfInterest.Contains(node.Identifier.Text)) base.VisitPropertyDeclaration(node); + } + + public override void VisitMethodDeclaration(MethodDeclarationSyntax node) + { + if (MembersOfInterest.Contains(node.Identifier.Text)) base.VisitMethodDeclaration(node); + } + + protected override bool SerializePropertyDeclarationToJson(PropertyDeclarationSyntax node) => + SerializeToJson(node, node.Identifier.Text); + + protected override bool SerializeMethodDeclarationToJson(MethodDeclarationSyntax node) => + SerializeToJson(node, node.Identifier.Text); + + private bool SerializeToJson(SyntaxNode node, string memberName) + { + if (!ConvertToJson.Contains(memberName)) return false; + + if (node.TryGetJsonForSyntaxNode(out var json)) + { + var startingLine = node.StartingLine(); + Blocks.Add(new JavaScriptBlock(json, startingLine, ClassDepth, memberName)); + } + + return true; + } + } } diff --git a/src/CodeGeneration/DocGenerator/XmlDocs/XmlDocsVisitor.cs b/src/CodeGeneration/DocGenerator/XmlDocs/XmlDocsVisitor.cs index f0e3ff57007..5e2308221ea 100644 --- a/src/CodeGeneration/DocGenerator/XmlDocs/XmlDocsVisitor.cs +++ b/src/CodeGeneration/DocGenerator/XmlDocs/XmlDocsVisitor.cs @@ -7,143 +7,135 @@ namespace DocGenerator.XmlDocs { - /// - /// Visits XML Documentation file to build an AsciiDoc - /// collection of labeled list items to include in documentation - /// - /// - public class XmlDocsVisitor : Visitor - { - private LabeledListItem _labeledListItem; - private readonly Type _type; - - // AsciiDocNet does not currently have a type for list item continuations, so mimic here - // for the moment - private const string ListItemContinuation = "\r\n+\r\n"; - - public List LabeledListItems { get; } = new List(); - - public XmlDocsVisitor(Type type) - { - _type = type; - } - - public override void VisitText(Text text) - { - var content = text.Content.Trim(); - if (!_labeledListItem.Any()) - _labeledListItem.Add(new Paragraph(content)); - else - { - var paragraph = _labeledListItem.Last() as Paragraph; - - if (paragraph == null) - _labeledListItem.Add(new Paragraph(content)); - else - { - var literal = paragraph.Last() as TextLiteral; - - if (literal != null && literal.Text == ListItemContinuation) - paragraph.Add(new TextLiteral(content)); - else - paragraph.Add(new TextLiteral(" " + content)); - } - } - } - - public override void VisitParam(Param param) - { - // TODO: add to docs. Omit for moment. - } - - public override void VisitPara(Para para) - { - var paragraph = _labeledListItem.LastOrDefault() as Paragraph; - paragraph?.Add(new TextLiteral(ListItemContinuation)); - base.VisitPara(para); - } - - public override void VisitC(C code) - { - var content = EncloseInMarks(code.Content.Trim()); - if (!_labeledListItem.Any()) - { - _labeledListItem.Add(new Paragraph(content)); - } - else - { - var paragraph = _labeledListItem.Last() as Paragraph; - if (paragraph == null) - _labeledListItem.Add(new Paragraph(content)); - else - paragraph.Add(new TextLiteral(" " + content)); - } - } - - public override void VisitSee(See see) - { - var content = EncloseInMarks(ExtractLastTokenAndFillGenericParameters((see.Cref ?? see.Content).Trim())); - if (!_labeledListItem.Any()) - { - _labeledListItem.Add(new Paragraph(content)); - } - else - { - var paragraph = _labeledListItem.Last() as Paragraph; - - if (paragraph == null) - _labeledListItem.Add(new Paragraph(content)); - else - paragraph.Add(new TextLiteral(" " + content)); - } - } - - private string ExtractLastTokenAndFillGenericParameters(string value) - { - if (value == null) - return string.Empty; - - var endOfToken = value.IndexOf("(", StringComparison.Ordinal); - if (endOfToken == -1) - endOfToken = value.Length; - - var index = 0; - - for (int i = 0; i < value.Length; i++) - { - if (value[i] == '.') - index = i + 1; - else if (value[i] == '(') - break; - } - - var length = endOfToken - index; - var lastToken = value.Substring(index, length); - - return lastToken.ReplaceArityWithGenericSignature(); - } - - private string EncloseInMarks(string value) => $"`{value}`"; - - public override void VisitMember(Member member) - { - if (member.Info != null) - { - if (member.Info.DeclaringType == _type && - member.Info.MemberType.HasFlag(MemberTypes.Method)) - { - var methodInfo = member.Info as MethodInfo; - - if (methodInfo != null && methodInfo.IsPublic) - { - if (_labeledListItem != null) - LabeledListItems.Add(_labeledListItem); - - _labeledListItem = new LabeledListItem(EncloseInMarks(methodInfo.Name), 0); - base.VisitMember(member); - } - } - } - } - } -} \ No newline at end of file + /// + /// Visits XML Documentation file to build an AsciiDoc + /// collection of labeled list items to include in documentation + /// + /// + public class XmlDocsVisitor : Visitor + { + // AsciiDocNet does not currently have a type for list item continuations, so mimic here + // for the moment + private const string ListItemContinuation = "\r\n+\r\n"; + private readonly Type _type; + private LabeledListItem _labeledListItem; + + public XmlDocsVisitor(Type type) => _type = type; + + public List LabeledListItems { get; } = new List(); + + public override void VisitText(Text text) + { + var content = text.Content.Trim(); + if (!_labeledListItem.Any()) + _labeledListItem.Add(new Paragraph(content)); + else + { + var paragraph = _labeledListItem.Last() as Paragraph; + + if (paragraph == null) + _labeledListItem.Add(new Paragraph(content)); + else + { + var literal = paragraph.Last() as TextLiteral; + + if (literal != null && literal.Text == ListItemContinuation) + paragraph.Add(new TextLiteral(content)); + else + paragraph.Add(new TextLiteral(" " + content)); + } + } + } + + public override void VisitParam(Param param) + { + // TODO: add to docs. Omit for moment. + } + + public override void VisitPara(Para para) + { + var paragraph = _labeledListItem.LastOrDefault() as Paragraph; + paragraph?.Add(new TextLiteral(ListItemContinuation)); + base.VisitPara(para); + } + + public override void VisitC(C code) + { + var content = EncloseInMarks(code.Content.Trim()); + if (!_labeledListItem.Any()) + _labeledListItem.Add(new Paragraph(content)); + else + { + var paragraph = _labeledListItem.Last() as Paragraph; + if (paragraph == null) + _labeledListItem.Add(new Paragraph(content)); + else + paragraph.Add(new TextLiteral(" " + content)); + } + } + + public override void VisitSee(See see) + { + var content = EncloseInMarks(ExtractLastTokenAndFillGenericParameters((see.Cref ?? see.Content).Trim())); + if (!_labeledListItem.Any()) + _labeledListItem.Add(new Paragraph(content)); + else + { + var paragraph = _labeledListItem.Last() as Paragraph; + + if (paragraph == null) + _labeledListItem.Add(new Paragraph(content)); + else + paragraph.Add(new TextLiteral(" " + content)); + } + } + + private string ExtractLastTokenAndFillGenericParameters(string value) + { + if (value == null) + return string.Empty; + + var endOfToken = value.IndexOf("(", StringComparison.Ordinal); + if (endOfToken == -1) + endOfToken = value.Length; + + var index = 0; + + for (var i = 0; i < value.Length; i++) + { + if (value[i] == '.') + index = i + 1; + else if (value[i] == '(') + break; + } + + var length = endOfToken - index; + var lastToken = value.Substring(index, length); + + return lastToken.ReplaceArityWithGenericSignature(); + } + + private string EncloseInMarks(string value) => $"`{value}`"; + + public override void VisitMember(Member member) + { + if (member.Info != null) + { + if (member.Info.DeclaringType == _type && + member.Info.MemberType.HasFlag(MemberTypes.Method)) + { + var methodInfo = member.Info as MethodInfo; + + if (methodInfo != null && methodInfo.IsPublic) + { + if (_labeledListItem != null) + LabeledListItems.Add(_labeledListItem); + + _labeledListItem = new LabeledListItem(EncloseInMarks(methodInfo.Name), 0); + base.VisitMember(member); + } + } + } + } + } +} diff --git a/src/Elasticsearch.Net/Auditing/Audit.cs b/src/Elasticsearch.Net/Auditing/Audit.cs index 8a2bff34d33..5caeebec06e 100644 --- a/src/Elasticsearch.Net/Auditing/Audit.cs +++ b/src/Elasticsearch.Net/Auditing/Audit.cs @@ -2,42 +2,47 @@ namespace Elasticsearch.Net { - /// - /// An audit of a request made - /// - public class Audit + /// + /// An audit of a request made + /// + public class Audit { - /// - /// The type of audit event - /// - public AuditEvent Event { get; internal set; } - /// - /// The start date and time of the audit - /// - public DateTime Started { get; } - /// - /// The end date and time of the audit - /// - public DateTime Ended { get; internal set; } - /// - /// The node on which the request was made - /// - public Node Node { get; internal set; } - /// - /// The path of the request - /// - public string Path { get; internal set; } - /// - /// The exception for the audit, if there was one. - /// - public Exception Exception { get; internal set; } - public Audit(AuditEvent type, DateTime started) { - this.Event = type; - this.Started = started; + Event = type; + Started = started; } + /// + /// The end date and time of the audit + /// + public DateTime Ended { get; internal set; } + + /// + /// The type of audit event + /// + public AuditEvent Event { get; internal set; } + + /// + /// The exception for the audit, if there was one. + /// + public Exception Exception { get; internal set; } + + /// + /// The node on which the request was made + /// + public Node Node { get; internal set; } + + /// + /// The path of the request + /// + public string Path { get; internal set; } + + /// + /// The start date and time of the audit + /// + public DateTime Started { get; } + public override string ToString() { var took = Ended - Started; diff --git a/src/Elasticsearch.Net/Auditing/Auditable.cs b/src/Elasticsearch.Net/Auditing/Auditable.cs index 5924cfd74bf..40bc3e75158 100644 --- a/src/Elasticsearch.Net/Auditing/Auditable.cs +++ b/src/Elasticsearch.Net/Auditing/Auditable.cs @@ -5,26 +5,38 @@ namespace Elasticsearch.Net { internal class Auditable : IDisposable { - readonly IDateTimeProvider _dateTimeProvider; private readonly Audit _audit; - - public Node Node { set { this._audit.Node = value; } } - public AuditEvent Event { set { this._audit.Event = value; } } - public Exception Exception { set { this._audit.Exception = value; } } - public string Path { set { this._audit.Path = value; } } + private readonly IDateTimeProvider _dateTimeProvider; public Auditable(AuditEvent type, List auditTrail, IDateTimeProvider dateTimeProvider) { - this._dateTimeProvider = dateTimeProvider; + _dateTimeProvider = dateTimeProvider; var started = _dateTimeProvider.Now(); - this._audit = new Audit(type, started); - auditTrail.Add(this._audit); + _audit = new Audit(type, started); + auditTrail.Add(_audit); + } + + public AuditEvent Event + { + set => _audit.Event = value; } - public void Dispose() + public Exception Exception { - this._audit.Ended = this._dateTimeProvider.Now(); + set => _audit.Exception = value; } + + public Node Node + { + set => _audit.Node = value; + } + + public string Path + { + set => _audit.Path = value; + } + + public void Dispose() => _audit.Ended = _dateTimeProvider.Now(); } -} \ No newline at end of file +} diff --git a/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs b/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs index 84ebb0a40db..c758acb9873 100644 --- a/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs +++ b/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs @@ -23,26 +23,20 @@ namespace Elasticsearch.Net /// public class ConnectionConfiguration : ConnectionConfiguration { - internal static bool IsCurlHandler { get; } = - #if DOTNETCORE - typeof(HttpClientHandler).Assembly().GetType("System.Net.Http.CurlHandler") != null; - #else - false; - #endif - public static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(1); public static readonly TimeSpan DefaultPingTimeout = TimeSpan.FromSeconds(2); public static readonly TimeSpan DefaultPingTimeoutOnSSL = TimeSpan.FromSeconds(5); + public static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(1); public static readonly int DefaultConnectionLimit = IsCurlHandler ? Environment.ProcessorCount : 80; + /// /// ConnectionConfiguration allows you to control how ElasticLowLevelClient behaves and where/how it connects /// to elasticsearch /// /// The root of the elasticsearch node we want to connect to. Defaults to http://localhost:9200 - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] public ConnectionConfiguration(Uri uri = null) - : this(new SingleNodeConnectionPool(uri ?? new Uri("http://localhost:9200"))) - { } + : this(new SingleNodeConnectionPool(uri ?? new Uri("http://localhost:9200"))) { } /// /// ConnectionConfiguration allows you to control how ElasticLowLevelClient behaves and where/how it connects @@ -51,24 +45,27 @@ public ConnectionConfiguration(Uri uri = null) /// A connection pool implementation that'll tell the client what nodes are available public ConnectionConfiguration(IConnectionPool connectionPool) // ReSharper disable once IntroduceOptionalParameters.Global - : this(connectionPool, null, null) - { } + : this(connectionPool, null, null) { } public ConnectionConfiguration(IConnectionPool connectionPool, IConnection connection) // ReSharper disable once IntroduceOptionalParameters.Global - : this(connectionPool, connection, null) - { } + : this(connectionPool, connection, null) { } public ConnectionConfiguration(IConnectionPool connectionPool, IElasticsearchSerializer serializer) - : this(connectionPool, null, serializer) - { } + : this(connectionPool, null, serializer) { } // ReSharper disable once MemberCanBePrivate.Global // eventhough we use don't use this we very much would like to expose this constructor public ConnectionConfiguration(IConnectionPool connectionPool, IConnection connection, IElasticsearchSerializer serializer) - : base(connectionPool, connection, serializer) - { } + : base(connectionPool, connection, serializer) { } + + internal static bool IsCurlHandler { get; } = +#if DOTNETCORE + typeof(HttpClientHandler).Assembly().GetType("System.Net.Http.CurlHandler") != null; + #else + false; +#endif } [Browsable(false)] @@ -76,141 +73,147 @@ public ConnectionConfiguration(IConnectionPool connectionPool, IConnection conne public abstract class ConnectionConfiguration : IConnectionConfigurationValues, IHideObjectMembers where T : ConnectionConfiguration { + private readonly IConnection _connection; + + private readonly IConnectionPool _connectionPool; + + private readonly NameValueCollection _headers = new NameValueCollection(); + + private readonly NameValueCollection _queryString = new NameValueCollection(); private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); - SemaphoreSlim IConnectionConfigurationValues.BootstrapLock => this._semaphore; - private TimeSpan _requestTimeout; - TimeSpan IConnectionConfigurationValues.RequestTimeout => _requestTimeout; + private BasicAuthenticationCredentials _basicAuthCredentials; - private TimeSpan? _pingTimeout; - TimeSpan? IConnectionConfigurationValues.PingTimeout => _pingTimeout; + private X509CertificateCollection _clientCertificates; + private Action _completedRequestHandler = DefaultCompletedRequestHandler; + + private int _connectionLimit; private TimeSpan? _deadTimeout; - TimeSpan? IConnectionConfigurationValues.DeadTimeout => _deadTimeout; - private TimeSpan? _maxDeadTimeout; - TimeSpan? IConnectionConfigurationValues.MaxDeadTimeout => _maxDeadTimeout; + private bool _disableAutomaticProxyDetection = false; - private TimeSpan? _maxRetryTimeout; - TimeSpan? IConnectionConfigurationValues.MaxRetryTimeout => _maxRetryTimeout; + private bool _disableDirectStreaming = false; - private TimeSpan? _keepAliveTime; - TimeSpan? IConnectionConfigurationValues.KeepAliveTime => _keepAliveTime; + private bool _disablePings; + + private bool _enableHttpCompression; + + private bool _enableHttpPipelining = true; private TimeSpan? _keepAliveInterval; - TimeSpan? IConnectionConfigurationValues.KeepAliveInterval => _keepAliveInterval; - private string _proxyUsername; - string IConnectionConfigurationValues.ProxyUsername => _proxyUsername; + private TimeSpan? _keepAliveTime; - private string _proxyPassword; - string IConnectionConfigurationValues.ProxyPassword => _proxyPassword; + private TimeSpan? _maxDeadTimeout; - private bool _disablePings; - bool IConnectionConfigurationValues.DisablePings => _disablePings; + private int? _maxRetries; - private string _proxyAddress; - string IConnectionConfigurationValues.ProxyAddress => _proxyAddress; + private TimeSpan? _maxRetryTimeout; + + private Func _nodePredicate = DefaultNodePredicate; + private Action _onRequestDataCreated = DefaultRequestDataCreated; + + private TimeSpan? _pingTimeout; private bool _prettyJson; - bool IConnectionConfigurationValues.PrettyJson => _prettyJson; - private bool _disableDirectStreaming = false; - bool IConnectionConfigurationValues.DisableDirectStreaming => _disableDirectStreaming; + private string _proxyAddress; - private bool _disableAutomaticProxyDetection = false; - bool IConnectionConfigurationValues.DisableAutomaticProxyDetection => _disableAutomaticProxyDetection; + private string _proxyPassword; - private int? _maxRetries; - int? IConnectionConfigurationValues.MaxRetries => _maxRetries; + private string _proxyUsername; - private int _connectionLimit; - int IConnectionConfigurationValues.ConnectionLimit => _connectionLimit; + private TimeSpan _requestTimeout; - private bool _sniffOnStartup; - bool IConnectionConfigurationValues.SniffsOnStartup => _sniffOnStartup; + private Func _serverCertificateValidationCallback; - private bool _sniffOnConnectionFault; - bool IConnectionConfigurationValues.SniffsOnConnectionFault => _sniffOnConnectionFault; + private IReadOnlyCollection _skipDeserializationForStatusCodes = new ReadOnlyCollection(new int[] { }); private TimeSpan? _sniffLifeSpan; - TimeSpan? IConnectionConfigurationValues.SniffInformationLifeSpan => _sniffLifeSpan; - private bool _enableHttpCompression; - bool IConnectionConfigurationValues.EnableHttpCompression => _enableHttpCompression; + private bool _sniffOnConnectionFault; - private bool _enableHttpPipelining = true; - bool IConnectionConfigurationValues.HttpPipeliningEnabled => _enableHttpPipelining; + private bool _sniffOnStartup; private bool _throwExceptions; - bool IConnectionConfigurationValues.ThrowExceptions => _throwExceptions; - private IReadOnlyCollection _skipDeserializationForStatusCodes = new ReadOnlyCollection(new int[] {}); - IReadOnlyCollection IConnectionConfigurationValues.SkipDeserializationForStatusCodes => _skipDeserializationForStatusCodes; + private readonly ElasticsearchUrlFormatter _urlFormatter; - private IMemoryStreamFactory _memoryStreamFactory = new RecyclableMemoryStreamFactory(); - IMemoryStreamFactory IConnectionConfigurationValues.MemoryStreamFactory => _memoryStreamFactory; + protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection connection, IElasticsearchSerializer requestResponseSerializer) + { + _connectionPool = connectionPool; + _connection = connection ?? new HttpConnection(); + UseThisRequestResponseSerializer = requestResponseSerializer ?? new LowLevelRequestResponseSerializer(); + + _connectionLimit = ConnectionConfiguration.DefaultConnectionLimit; + _requestTimeout = ConnectionConfiguration.DefaultTimeout; + _sniffOnConnectionFault = true; + _sniffOnStartup = true; + _sniffLifeSpan = TimeSpan.FromHours(1); + if (_connectionPool.SupportsReseeding) + _nodePredicate = DefaultReseedableNodePredicate; + + _urlFormatter = new ElasticsearchUrlFormatter(this); + } - private static void DefaultCompletedRequestHandler(IApiCallDetails response) { } - Action _completedRequestHandler = DefaultCompletedRequestHandler; - Action IConnectionConfigurationValues.OnRequestCompleted => _completedRequestHandler; + protected IElasticsearchSerializer UseThisRequestResponseSerializer { get; set; } + BasicAuthenticationCredentials IConnectionConfigurationValues.BasicAuthenticationCredentials => _basicAuthCredentials; + SemaphoreSlim IConnectionConfigurationValues.BootstrapLock => _semaphore; + X509CertificateCollection IConnectionConfigurationValues.ClientCertificates => _clientCertificates; + IConnection IConnectionConfigurationValues.Connection => _connection; + int IConnectionConfigurationValues.ConnectionLimit => _connectionLimit; + IConnectionPool IConnectionConfigurationValues.ConnectionPool => _connectionPool; + TimeSpan? IConnectionConfigurationValues.DeadTimeout => _deadTimeout; + bool IConnectionConfigurationValues.DisableAutomaticProxyDetection => _disableAutomaticProxyDetection; + bool IConnectionConfigurationValues.DisableDirectStreaming => _disableDirectStreaming; + bool IConnectionConfigurationValues.DisablePings => _disablePings; + bool IConnectionConfigurationValues.EnableHttpCompression => _enableHttpCompression; + NameValueCollection IConnectionConfigurationValues.Headers => _headers; + bool IConnectionConfigurationValues.HttpPipeliningEnabled => _enableHttpPipelining; + TimeSpan? IConnectionConfigurationValues.KeepAliveInterval => _keepAliveInterval; + TimeSpan? IConnectionConfigurationValues.KeepAliveTime => _keepAliveTime; + TimeSpan? IConnectionConfigurationValues.MaxDeadTimeout => _maxDeadTimeout; + int? IConnectionConfigurationValues.MaxRetries => _maxRetries; + TimeSpan? IConnectionConfigurationValues.MaxRetryTimeout => _maxRetryTimeout; + IMemoryStreamFactory IConnectionConfigurationValues.MemoryStreamFactory { get; } = new RecyclableMemoryStreamFactory(); - private static void DefaultRequestDataCreated(RequestData response) { } - private Action _onRequestDataCreated = DefaultRequestDataCreated; + Func IConnectionConfigurationValues.NodePredicate => _nodePredicate; + Action IConnectionConfigurationValues.OnRequestCompleted => _completedRequestHandler; Action IConnectionConfigurationValues.OnRequestDataCreated => _onRequestDataCreated; + TimeSpan? IConnectionConfigurationValues.PingTimeout => _pingTimeout; + bool IConnectionConfigurationValues.PrettyJson => _prettyJson; + string IConnectionConfigurationValues.ProxyAddress => _proxyAddress; + string IConnectionConfigurationValues.ProxyPassword => _proxyPassword; + string IConnectionConfigurationValues.ProxyUsername => _proxyUsername; + NameValueCollection IConnectionConfigurationValues.QueryStringParameters => _queryString; + IElasticsearchSerializer IConnectionConfigurationValues.RequestResponseSerializer => UseThisRequestResponseSerializer; + TimeSpan IConnectionConfigurationValues.RequestTimeout => _requestTimeout; - private Func _serverCertificateValidationCallback; - Func IConnectionConfigurationValues.ServerCertificateValidationCallback => _serverCertificateValidationCallback; - - private X509CertificateCollection _clientCertificates; - X509CertificateCollection IConnectionConfigurationValues.ClientCertificates => _clientCertificates; + Func IConnectionConfigurationValues.ServerCertificateValidationCallback => + _serverCertificateValidationCallback; - private ElasticsearchUrlFormatter _urlFormatter; + IReadOnlyCollection IConnectionConfigurationValues.SkipDeserializationForStatusCodes => _skipDeserializationForStatusCodes; + TimeSpan? IConnectionConfigurationValues.SniffInformationLifeSpan => _sniffLifeSpan; + bool IConnectionConfigurationValues.SniffsOnConnectionFault => _sniffOnConnectionFault; + bool IConnectionConfigurationValues.SniffsOnStartup => _sniffOnStartup; + bool IConnectionConfigurationValues.ThrowExceptions => _throwExceptions; ElasticsearchUrlFormatter IConnectionConfigurationValues.UrlFormatter => _urlFormatter; + void IDisposable.Dispose() => DisposeManagedResources(); + + private static void DefaultCompletedRequestHandler(IApiCallDetails response) { } + + private static void DefaultRequestDataCreated(RequestData response) { } + /// - /// The default predicate for implementations that return true for + /// The default predicate for implementations that return true for + /// /// in which case master only nodes are excluded from API calls. /// private static bool DefaultReseedableNodePredicate(Node node) => !node.MasterOnlyNode; - private static bool DefaultNodePredicate(Node node) => true; - private Func _nodePredicate = DefaultNodePredicate; - Func IConnectionConfigurationValues.NodePredicate => _nodePredicate; - - private readonly NameValueCollection _queryString = new NameValueCollection(); - NameValueCollection IConnectionConfigurationValues.QueryStringParameters => _queryString; - - private readonly NameValueCollection _headers = new NameValueCollection(); - NameValueCollection IConnectionConfigurationValues.Headers => _headers; - - BasicAuthenticationCredentials _basicAuthCredentials; - BasicAuthenticationCredentials IConnectionConfigurationValues.BasicAuthenticationCredentials => _basicAuthCredentials; - protected IElasticsearchSerializer UseThisRequestResponseSerializer { get; set; } - IElasticsearchSerializer IConnectionConfigurationValues.RequestResponseSerializer => UseThisRequestResponseSerializer; - - private readonly IConnectionPool _connectionPool; - IConnectionPool IConnectionConfigurationValues.ConnectionPool => _connectionPool; - - private readonly IConnection _connection; - IConnection IConnectionConfigurationValues.Connection => _connection; - - protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection connection, IElasticsearchSerializer requestResponseSerializer) - { - this._connectionPool = connectionPool; - this._connection = connection ?? new HttpConnection(); - this.UseThisRequestResponseSerializer = requestResponseSerializer ?? new LowLevelRequestResponseSerializer(); - - this._connectionLimit = ConnectionConfiguration.DefaultConnectionLimit; - this._requestTimeout = ConnectionConfiguration.DefaultTimeout; - this._sniffOnConnectionFault = true; - this._sniffOnStartup = true; - this._sniffLifeSpan = TimeSpan.FromHours(1); - if (this._connectionPool.SupportsReseeding) - this._nodePredicate = DefaultReseedableNodePredicate; - - this._urlFormatter = new ElasticsearchUrlFormatter(this); - } + private static bool DefaultNodePredicate(Node node) => true; private T Assign(Action> assigner) => Fluent.Assign((T)this, assigner); @@ -224,39 +227,49 @@ protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection co /// For Desktop CLR, sets ServicePointManager.SetTcpKeepAlive /// /// Specifies the timeout with no activity until the first keep-alive packet is sent. - /// Specifies the interval between when successive keep-alive packets are sent if no acknowledgement is received. + /// + /// Specifies the interval between when successive keep-alive packets are sent if no acknowledgement is + /// received. + /// public T EnableTcpKeepAlive(TimeSpan keepAliveTime, TimeSpan keepAliveInterval) => - Assign(a => { this._keepAliveTime = keepAliveTime; this._keepAliveInterval = keepAliveInterval; }); + Assign(a => + { + _keepAliveTime = keepAliveTime; + _keepAliveInterval = keepAliveInterval; + }); /// /// The maximum number of retries for a given request, /// public T MaximumRetries(int maxRetries) => Assign(a => a._maxRetries = maxRetries); - /// - /// Limits the number of concurrent connections that can be opened to an endpoint. Defaults to 80. - /// For Desktop CLR, this setting applies to the DefaultConnectionLimit property on the ServicePointManager object when creating ServicePoint objects, affecting the default implementation. - /// For Core CLR, this setting applies to the MaxConnectionsPerServer property on the HttpClientHandler instances used by the HttpClient inside the default implementation - /// - /// The connection limit, a value lower then 0 will cause the connection limit not to be set at all - public T ConnectionLimit(int connectionLimit) - { - return Assign(a => a._connectionLimit = connectionLimit); - } + /// + /// Limits the number of concurrent connections that can be opened to an endpoint. Defaults to 80. + /// + /// For Desktop CLR, this setting applies to the DefaultConnectionLimit property on the ServicePointManager object when creating + /// ServicePoint objects, affecting the default implementation. + /// + /// + /// For Core CLR, this setting applies to the MaxConnectionsPerServer property on the HttpClientHandler instances used by the HttpClient + /// inside the default implementation + /// + /// + /// The connection limit, a value lower then 0 will cause the connection limit not to be set at all + public T ConnectionLimit(int connectionLimit) => Assign(a => a._connectionLimit = connectionLimit); - /// - /// Enables resniffing of the cluster when a call fails, if the connection pool supports reseeding. Defaults to true - /// - public T SniffOnConnectionFault(bool sniffsOnConnectionFault = true) => Assign(a => a._sniffOnConnectionFault = sniffsOnConnectionFault); + /// + /// Enables resniffing of the cluster when a call fails, if the connection pool supports reseeding. Defaults to true + /// + public T SniffOnConnectionFault(bool sniffsOnConnectionFault = true) => Assign(a => a._sniffOnConnectionFault = sniffsOnConnectionFault); - /// - /// Enables sniffing on first usage of a connection pool if that pool supports reseeding. Defaults to true - /// - public T SniffOnStartup(bool sniffsOnStartup = true) => Assign(a => a._sniffOnStartup = sniffsOnStartup); + /// + /// Enables sniffing on first usage of a connection pool if that pool supports reseeding. Defaults to true + /// + public T SniffOnStartup(bool sniffsOnStartup = true) => Assign(a => a._sniffOnStartup = sniffsOnStartup); /// /// Set the duration after which a cluster state is considered stale and a sniff should be performed again. - /// An has to signal it supports reseeding, otherwise sniffing will never happen. + /// An has to signal it supports reseeding, otherwise sniffing will never happen. /// Defaults to 1 hour. /// Set to null to disable completely. Sniffing will only ever happen on ConnectionPools that return true for SupportsReseeding /// @@ -290,28 +303,30 @@ public T ConnectionLimit(int connectionLimit) public T DisablePing(bool disable = true) => Assign(a => a._disablePings = disable); /// - /// A collection of query string parameters that will be sent with every request. Useful in situations where you always need to pass a parameter e.g. an API key. + /// A collection of query string parameters that will be sent with every request. Useful in situations where you always need to pass a + /// parameter e.g. an API key. /// public T GlobalQueryStringParameters(NameValueCollection queryStringParameters) => Assign(a => a._queryString.Add(queryStringParameters)); /// - /// A collection of headers that will be sent with every request. Useful in situations where you always need to pass a header e.g. a custom auth header + /// A collection of headers that will be sent with every request. Useful in situations where you always need to pass a header e.g. a custom + /// auth header /// public T GlobalHeaders(NameValueCollection headers) => Assign(a => a._headers.Add(headers)); - /// - /// Sets the default timeout in milliseconds for each request to Elasticsearch. Defaults to 60 seconds. - /// NOTE: You can set this to a high value here, and specify a timeout on Elasticsearch's side. - /// - /// time out in milliseconds - public T RequestTimeout(TimeSpan timeout) => Assign(a => a._requestTimeout = timeout); + /// + /// Sets the default timeout in milliseconds for each request to Elasticsearch. Defaults to 60 seconds. + /// NOTE: You can set this to a high value here, and specify a timeout on Elasticsearch's side. + /// + /// time out in milliseconds + public T RequestTimeout(TimeSpan timeout) => Assign(a => a._requestTimeout = timeout); - /// - /// Sets the default ping timeout in milliseconds for ping requests, which are used - /// to determine whether a node is alive. Pings should fail as fast as possible. - /// - /// The ping timeout in milliseconds defaults to 1000, or 2000 if using SSL. - public T PingTimeout(TimeSpan timeout) => Assign(a => a._pingTimeout = timeout); + /// + /// Sets the default ping timeout in milliseconds for ping requests, which are used + /// to determine whether a node is alive. Pings should fail as fast as possible. + /// + /// The ping timeout in milliseconds defaults to 1000, or 2000 if using SSL. + public T PingTimeout(TimeSpan timeout) => Assign(a => a._pingTimeout = timeout); /// /// Sets the default dead timeout factor when a node has been marked dead. @@ -322,18 +337,18 @@ public T ConnectionLimit(int connectionLimit) /// /// Sets the maximum time a node can be marked dead. - /// Different implementations of may choose a different default. + /// Different implementations of may choose a different default. /// /// The timeout in milliseconds public T MaxDeadTimeout(TimeSpan timeout) => Assign(a => a._maxDeadTimeout = timeout); - /// - /// Limits the total runtime, including retries, separately from - /// - /// When not specified, defaults to , which itself defaults to 60 seconds - /// - /// - public T MaxRetryTimeout(TimeSpan maxRetryTimeout) => Assign(a => a._maxRetryTimeout = maxRetryTimeout); + /// + /// Limits the total runtime, including retries, separately from + /// + /// When not specified, defaults to , which itself defaults to 60 seconds + /// + /// + public T MaxRetryTimeout(TimeSpan maxRetryTimeout) => Assign(a => a._maxRetryTimeout = maxRetryTimeout); /// /// If your connection has to go through proxy, use this method to specify the proxy url @@ -341,9 +356,9 @@ public T ConnectionLimit(int connectionLimit) public T Proxy(Uri proxyAdress, string username, string password) { proxyAdress.ThrowIfNull(nameof(proxyAdress)); - this._proxyAddress = proxyAdress.ToString(); - this._proxyUsername = username; - this._proxyPassword = password; + _proxyAddress = proxyAdress.ToString(); + _proxyUsername = username; + _proxyPassword = password; return (T)this; } @@ -354,11 +369,11 @@ public T Proxy(Uri proxyAdress, string username, string password) /// public T PrettyJson(bool b = true) => Assign(a => { - this._prettyJson = b; + _prettyJson = b; const string key = "pretty"; - if (!b && this._queryString[key] != null) this._queryString.Remove(key); - else if (b && this._queryString[key] == null) - this.GlobalQueryStringParameters(new NameValueCollection { { key, "true" } }); + if (!b && _queryString[key] != null) _queryString.Remove(key); + else if (b && _queryString[key] == null) + GlobalQueryStringParameters(new NameValueCollection { { key, "true" } }); }); /// @@ -369,20 +384,22 @@ public T PrettyJson(bool b = true) => Assign(a => public T IncludeServerStackTraceOnError(bool b = true) => Assign(a => { const string key = "error_trace"; - if (!b && this._queryString[key] != null) this._queryString.Remove(key); - else if (b && this._queryString[key] == null) - this.GlobalQueryStringParameters(new NameValueCollection { { key, "true" } }); + if (!b && _queryString[key] != null) _queryString.Remove(key); + else if (b && _queryString[key] == null) + GlobalQueryStringParameters(new NameValueCollection { { key, "true" } }); }); /// - /// Ensures the response bytes are always available on the - /// IMPORTANT: Depending on the registered serializer, - /// this may cause the response to be buffered in memory first, potentially affecting performance. + /// Ensures the response bytes are always available on the + /// + /// IMPORTANT: Depending on the registered serializer, + /// this may cause the response to be buffered in memory first, potentially affecting performance. + /// /// public T DisableDirectStreaming(bool b = true) => Assign(a => a._disableDirectStreaming = b); /// - /// Registers an that is called when a response is received from Elasticsearch. + /// Registers an that is called when a response is received from Elasticsearch. /// This can be useful for implementing custom logging. /// Multiple callbacks can be registered by calling this multiple times /// @@ -390,7 +407,7 @@ public T OnRequestCompleted(Action handler) => Assign(a => a._completedRequestHandler += handler ?? DefaultCompletedRequestHandler); /// - /// Registers an that is called when is created. + /// Registers an that is called when is created. /// Multiple callbacks can be registered by calling this multiple times /// public T OnRequestDataCreated(Action handler) => @@ -413,15 +430,19 @@ public T BasicAuthentication(string userName, string password) => public T EnableHttpPipelining(bool enabled = true) => Assign(a => a._enableHttpPipelining = enabled); /// - /// Register a predicate to select which nodes that you want to execute API calls on. Note that sniffing requests omit this predicate and always execute on all nodes. - /// When using an implementation that supports reseeding of nodes, this will default to omitting master only node from regular API calls. - /// When using static or single node connection pooling it is assumed the list of node you instantiate the client with should be taken verbatim. + /// Register a predicate to select which nodes that you want to execute API calls on. Note that sniffing requests omit this predicate and + /// always execute on all nodes. + /// When using an implementation that supports reseeding of nodes, this will default to omitting master only + /// node from regular API calls. + /// When using static or single node connection pooling it is assumed the list of node you instantiate the client with should be taken + /// verbatim. /// /// Return true if you want the node to be used for API calls public T NodePredicate(Func predicate) { - if (predicate == null) return (T) this; - this._nodePredicate = predicate; + if (predicate == null) return (T)this; + + _nodePredicate = predicate; return (T)this; } @@ -437,13 +458,13 @@ public T NodePredicate(Func predicate) /// public T EnableDebugMode(Action onRequestCompleted = null) { - this._disableDirectStreaming = true; - this.PrettyJson(true); - this.IncludeServerStackTraceOnError(true); + _disableDirectStreaming = true; + PrettyJson(true); + IncludeServerStackTraceOnError(true); - var originalCompletedRequestHandler = this._completedRequestHandler; + var originalCompletedRequestHandler = _completedRequestHandler; var debugCompletedRequestHandler = onRequestCompleted ?? (d => Debug.WriteLine(d.DebugInformation)); - this._completedRequestHandler = d => + _completedRequestHandler = d => { originalCompletedRequestHandler?.Invoke(d); debugCompletedRequestHandler?.Invoke(d); @@ -462,39 +483,37 @@ public T ServerCertificateValidationCallback(Func /// Use the following certificates to authenticate all HTTP requests. You can also set them on individual - /// request using + /// request using /// public T ClientCertificates(X509CertificateCollection certificates) => Assign(a => a._clientCertificates = certificates); /// /// Use the following certificate to authenticate all HTTP requests. You can also set them on individual - /// request using + /// request using /// public T ClientCertificate(X509Certificate certificate) => Assign(a => a._clientCertificates = new X509Certificate2Collection { certificate }); /// /// Use the following certificate to authenticate all HTTP requests. You can also set them on individual - /// request using + /// request using /// public T ClientCertificate(string certificatePath) => Assign(a => a._clientCertificates = new X509Certificate2Collection { new X509Certificate(certificatePath) }); /// - /// Configure the client to skip deserialization of certain status codes e.g: you run elasticsearch behind a proxy that returns a HTML for 401, 500 + /// Configure the client to skip deserialization of certain status codes e.g: you run elasticsearch behind a proxy that returns a HTML for 401, + /// 500 /// public T SkipDeserializationForStatusCodes(params int[] statusCodes) => Assign(a => a._skipDeserializationForStatusCodes = new ReadOnlyCollection(statusCodes)); - void IDisposable.Dispose() => this.DisposeManagedResources(); - protected virtual void DisposeManagedResources() { - this._connectionPool?.Dispose(); - this._connection?.Dispose(); - this._semaphore?.Dispose(); + _connectionPool?.Dispose(); + _connection?.Dispose(); + _semaphore?.Dispose(); } } } - diff --git a/src/Elasticsearch.Net/Configuration/IConnectionConfigurationValues.cs b/src/Elasticsearch.Net/Configuration/IConnectionConfigurationValues.cs index 8c346085854..53656c79ac4 100644 --- a/src/Elasticsearch.Net/Configuration/IConnectionConfigurationValues.cs +++ b/src/Elasticsearch.Net/Configuration/IConnectionConfigurationValues.cs @@ -9,30 +9,39 @@ namespace Elasticsearch.Net { public interface IConnectionConfigurationValues : IDisposable { + /// + /// Basic access authorization credentials to specify with all requests. + /// + BasicAuthenticationCredentials BasicAuthenticationCredentials { get; } + /// Provides a semaphoreslim to transport implementations that need to limit access to a resource SemaphoreSlim BootstrapLock { get; } - /// Provides a memory stream factory - IMemoryStreamFactory MemoryStreamFactory { get; } - - /// The connection pool to use when talking with Elasticsearch - IConnectionPool ConnectionPool { get; } + /// + /// Use the following certificates to authenticate all HTTP requests. You can also set them on individual + /// request using + /// + X509CertificateCollection ClientCertificates { get; } /// The connection implementation to use when talking with Elasticsearch IConnection Connection { get; } - /// The serializer to use to serialize requests and deserialize responses - IElasticsearchSerializer RequestResponseSerializer { get; } - /// - /// The timeout in milliseconds for each request to Elasticsearch + /// Limits the number of concurrent connections that can be opened to an endpoint. Defaults to 80 (see + /// ). + /// + /// For Desktop CLR, this setting applies to the DefaultConnectionLimit property on the ServicePointManager object when creating + /// ServicePoint objects, affecting the default implementation. + /// + /// + /// For Core CLR, this setting applies to the MaxConnectionsPerServer property on the HttpClientHandler instances used by the HttpClient + /// inside the default implementation + /// /// - TimeSpan RequestTimeout { get; } + int ConnectionLimit { get; } - /// - /// The timeout in milliseconds to use for ping requests, which are issued to determine whether a node is alive - /// - TimeSpan? PingTimeout { get; } + /// The connection pool to use when talking with Elasticsearch + IConnectionPool ConnectionPool { get; } /// /// The time to put dead nodes out of rotation (this will be multiplied by the number of times they've been dead) @@ -40,30 +49,17 @@ public interface IConnectionConfigurationValues : IDisposable TimeSpan? DeadTimeout { get; } /// - /// The maximum ammount of time a node is allowed to marked dead - /// - TimeSpan? MaxDeadTimeout { get; } - - /// - /// Limits the total runtime including retries separately from - ///
-		/// When not specified defaults to  which itself defaults to 60 seconds
-		/// 
- ///
- TimeSpan? MaxRetryTimeout { get; } - - /// - /// When a retryable exception occurs or status code is returned this controls the maximum - /// amount of times we should retry the call to elasticsearch + /// Disabled proxy detection on the webrequest, in some cases this may speed up the first connection + /// your appdomain makes, in other cases it will actually increase the time for the first connection. + /// No silver bullet! use with care! /// - int? MaxRetries { get; } + bool DisableAutomaticProxyDetection { get; } /// - /// Limits the number of concurrent connections that can be opened to an endpoint. Defaults to 80 (see ). - /// For Desktop CLR, this setting applies to the DefaultConnectionLimit property on the ServicePointManager object when creating ServicePoint objects, affecting the default implementation. - /// For Core CLR, this setting applies to the MaxConnectionsPerServer property on the HttpClientHandler instances used by the HttpClient inside the default implementation + /// When set to true will disable (de)serializing directly to the request and response stream and return a byte[] + /// copy of the raw request and response on elasticsearch calls. Defaults to false /// - int ConnectionLimit { get; } + bool DisableDirectStreaming { get; } /// /// This signals that we do not want to send initial pings to unknown/previously dead nodes @@ -78,128 +74,143 @@ public interface IConnectionConfigurationValues : IDisposable bool EnableHttpCompression { get; } /// - /// When set will force all connections through this proxy + /// Try to send these headers for every request /// - string ProxyAddress { get; } + NameValueCollection Headers { get; } /// - /// The username for the proxy, when configured + /// By default the client enables http pipelining as elasticsearch 2.0 defaults to true as well /// - string ProxyUsername { get; } + bool HttpPipeliningEnabled { get; } /// - /// The password for the proxy, when configured + /// KeepAliveInterval - specifies the interval, in milliseconds, between + /// when successive keep-alive packets are sent if no acknowledgement is + /// received. /// - string ProxyPassword { get; } + TimeSpan? KeepAliveInterval { get; } /// - /// Forces all requests to have ?pretty=true, causing elasticsearch to return formatted json. - /// Also forces the client to send out formatted json. Defaults to false + /// KeepAliveTime - specifies the timeout, in milliseconds, with no + /// activity until the first keep-alive packet is sent. /// - bool PrettyJson { get; } + TimeSpan? KeepAliveTime { get; } /// - /// When set to true will disable (de)serializing directly to the request and response stream and return a byte[] - /// copy of the raw request and response on elasticsearch calls. Defaults to false + /// The maximum ammount of time a node is allowed to marked dead /// - bool DisableDirectStreaming { get; } + TimeSpan? MaxDeadTimeout { get; } /// - /// Disabled proxy detection on the webrequest, in some cases this may speed up the first connection - /// your appdomain makes, in other cases it will actually increase the time for the first connection. - /// No silver bullet! use with care! + /// When a retryable exception occurs or status code is returned this controls the maximum + /// amount of times we should retry the call to elasticsearch /// - bool DisableAutomaticProxyDetection { get; } + int? MaxRetries { get; } /// - /// By default the client enables http pipelining as elasticsearch 2.0 defaults to true as well + /// Limits the total runtime including retries separately from + ///
+		/// When not specified defaults to  which itself defaults to 60 seconds
+		/// 
///
- bool HttpPipeliningEnabled { get; } + TimeSpan? MaxRetryTimeout { get; } + + /// Provides a memory stream factory + IMemoryStreamFactory MemoryStreamFactory { get; } /// - /// Instead of following a c/go like error checking on response.IsValid always throw an exception - /// on the client when a call resulted in an exception on either the client or the Elasticsearch server. - /// Reasons for such exceptions could be search parser errors, index missing exceptions, etc... + /// Register a predicate to select which nodes that you want to execute API calls on. Note that sniffing requests omit this predicate and + /// always execute on all nodes. + /// When using an implementation that supports reseeding of nodes, this will default to omitting master only + /// node from regular API calls. + /// When using static or single node connection pooling it is assumed the list of node you instantiate the client with should be taken + /// verbatim. /// - bool ThrowExceptions { get; } + Func NodePredicate { get; } /// - /// Sniff the cluster state immediatly on startup + /// Allows you to register a callback every time a an API call is returned /// - bool SniffsOnStartup { get; } + Action OnRequestCompleted { get; } /// - /// Force a new sniff for the cluster state everytime a connection dies + /// An action to run when the for a request has been + /// created. /// - bool SniffsOnConnectionFault { get; } + Action OnRequestDataCreated { get; } /// - /// Force a new sniff for the cluster when the cluster state information is older than - /// the specified timespan + /// The timeout in milliseconds to use for ping requests, which are issued to determine whether a node is alive /// - TimeSpan? SniffInformationLifeSpan { get; } + TimeSpan? PingTimeout { get; } /// - /// Append these query string parameters automatically to every request + /// Forces all requests to have ?pretty=true, causing elasticsearch to return formatted json. + /// Also forces the client to send out formatted json. Defaults to false /// - NameValueCollection QueryStringParameters { get; } + bool PrettyJson { get; } /// - /// Try to send these headers for every request + /// When set will force all connections through this proxy /// - NameValueCollection Headers { get; } + string ProxyAddress { get; } /// - /// Allows you to register a callback every time a an API call is returned + /// The password for the proxy, when configured /// - Action OnRequestCompleted { get; } + string ProxyPassword { get; } /// - /// Basic access authorization credentials to specify with all requests. + /// The username for the proxy, when configured /// - BasicAuthenticationCredentials BasicAuthenticationCredentials { get; } + string ProxyUsername { get; } /// - /// An action to run when the for a request has been - /// created. + /// Append these query string parameters automatically to every request /// - Action OnRequestDataCreated { get; } + NameValueCollection QueryStringParameters { get; } + + /// The serializer to use to serialize requests and deserialize responses + IElasticsearchSerializer RequestResponseSerializer { get; } /// - /// KeepAliveTime - specifies the timeout, in milliseconds, with no - /// activity until the first keep-alive packet is sent. + /// The timeout in milliseconds for each request to Elasticsearch /// - TimeSpan? KeepAliveTime { get; } + TimeSpan RequestTimeout { get; } /// - /// KeepAliveInterval - specifies the interval, in milliseconds, between - /// when successive keep-alive packets are sent if no acknowledgement is - /// received. + /// Register a ServerCertificateValidationCallback per request /// - TimeSpan? KeepAliveInterval { get; } + Func ServerCertificateValidationCallback { get; } /// - /// Register a ServerCertificateValidationCallback per request + /// Configure the client to skip deserialization of certain status codes e.g: you run elasticsearch behind a proxy that returns an unexpected + /// json format /// - Func ServerCertificateValidationCallback { get; } + IReadOnlyCollection SkipDeserializationForStatusCodes { get; } /// - /// Register a predicate to select which nodes that you want to execute API calls on. Note that sniffing requests omit this predicate and always execute on all nodes. - /// When using an implementation that supports reseeding of nodes, this will default to omitting master only node from regular API calls. - /// When using static or single node connection pooling it is assumed the list of node you instantiate the client with should be taken verbatim. + /// Force a new sniff for the cluster when the cluster state information is older than + /// the specified timespan /// - Func NodePredicate { get; } + TimeSpan? SniffInformationLifeSpan { get; } /// - /// Use the following certificates to authenticate all HTTP requests. You can also set them on individual - /// request using + /// Force a new sniff for the cluster state everytime a connection dies /// - X509CertificateCollection ClientCertificates { get; } + bool SniffsOnConnectionFault { get; } /// - /// Configure the client to skip deserialization of certain status codes e.g: you run elasticsearch behind a proxy that returns an unexpected json format + /// Sniff the cluster state immediatly on startup /// - IReadOnlyCollection SkipDeserializationForStatusCodes { get; } + bool SniffsOnStartup { get; } + + /// + /// Instead of following a c/go like error checking on response.IsValid always throw an exception + /// on the client when a call resulted in an exception on either the client or the Elasticsearch server. + /// Reasons for such exceptions could be search parser errors, index missing exceptions, etc... + /// + bool ThrowExceptions { get; } ElasticsearchUrlFormatter UrlFormatter { get; } } diff --git a/src/Elasticsearch.Net/Configuration/RequestConfiguration.cs b/src/Elasticsearch.Net/Configuration/RequestConfiguration.cs index 460474b88f1..f90d00d14e1 100644 --- a/src/Elasticsearch.Net/Configuration/RequestConfiguration.cs +++ b/src/Elasticsearch.Net/Configuration/RequestConfiguration.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading; @@ -9,40 +8,41 @@ namespace Elasticsearch.Net public interface IRequestConfiguration { /// - /// The timeout for this specific request, takes precedence over the global timeout settings + /// Force a different Accept header on the request /// - TimeSpan? RequestTimeout { get; set; } + string Accept { get; set; } /// - /// The ping timeout for this specific request + /// Treat the following statuses (on top of the 200 range) NOT as error. /// - TimeSpan? PingTimeout { get; set; } + IEnumerable AllowedStatusCodes { get; set; } /// - /// Force a different Content-Type header on the request + /// Basic access authorization credentials to specify with this request. + /// Overrides any credentials that are set at the global IConnectionSettings level. /// - string ContentType { get; set; } + BasicAuthenticationCredentials BasicAuthenticationCredentials { get; set; } /// - /// Associate an Id with this user-initiated task, such that it can be located in the cluster task list. - /// Valid only for Elasticsearch 6.2.0+ + /// Use the following client certificates to authenticate this single request /// - string OpaqueId { get; set; } + X509CertificateCollection ClientCertificates { get; set; } /// - /// Force a different Accept header on the request + /// Force a different Content-Type header on the request /// - string Accept { get; set; } + string ContentType { get; set; } /// - /// This will override whatever is set on the connection configuration or whatever default the connectionpool has. + /// Whether to buffer the request and response bytes for the call /// - int? MaxRetries { get; set; } + bool? DisableDirectStreaming { get; set; } /// - /// This will force the operation on the specified node, this will bypass any configured connection pool and will no retry. + /// Under no circumstance do a ping before the actual call. If a node was previously dead a small ping with + /// low connect timeout will be tried first in normal circumstances /// - Uri ForceNode { get; set; } + bool? DisablePing { get; set; } /// /// Forces no sniffing to occur on the request no matter what configuration is in place @@ -51,42 +51,41 @@ public interface IRequestConfiguration bool? DisableSniff { get; set; } /// - /// Under no circumstance do a ping before the actual call. If a node was previously dead a small ping with - /// low connect timeout will be tried first in normal circumstances + /// Whether or not this request should be pipelined. http://en.wikipedia.org/wiki/HTTP_pipelining defaults to true /// - bool? DisablePing { get; set; } + bool EnableHttpPipelining { get; set; } /// - /// Whether to buffer the request and response bytes for the call + /// This will force the operation on the specified node, this will bypass any configured connection pool and will no retry. /// - bool? DisableDirectStreaming { get; set; } + Uri ForceNode { get; set; } /// - /// Treat the following statuses (on top of the 200 range) NOT as error. + /// This will override whatever is set on the connection configuration or whatever default the connectionpool has. /// - IEnumerable AllowedStatusCodes { get; set; } + int? MaxRetries { get; set; } /// - /// Basic access authorization credentials to specify with this request. - /// Overrides any credentials that are set at the global IConnectionSettings level. + /// Associate an Id with this user-initiated task, such that it can be located in the cluster task list. + /// Valid only for Elasticsearch 6.2.0+ /// - BasicAuthenticationCredentials BasicAuthenticationCredentials { get; set; } + string OpaqueId { get; set; } /// - /// Whether or not this request should be pipelined. http://en.wikipedia.org/wiki/HTTP_pipelining defaults to true + /// The ping timeout for this specific request /// - bool EnableHttpPipelining { get; set; } + TimeSpan? PingTimeout { get; set; } /// - /// Submit the request on behalf in the context of a different shield user - ///
https://www.elastic.co/guide/en/shield/current/submitting-requests-for-other-users.html
+		/// The timeout for this specific request, takes precedence over the global timeout settings
 		/// 
- string RunAs { get; set; } + TimeSpan? RequestTimeout { get; set; } /// - /// Use the following client certificates to authenticate this single request + /// Submit the request on behalf in the context of a different shield user + ///
https://www.elastic.co/guide/en/shield/current/submitting-requests-for-other-users.html
 		/// 
- X509CertificateCollection ClientCertificates { get; set; } + string RunAs { get; set; } /// /// Instead of following a c/go like error checking on response.IsValid always throw an exception @@ -98,51 +97,34 @@ public interface IRequestConfiguration public class RequestConfiguration : IRequestConfiguration { - public TimeSpan? RequestTimeout { get; set; } - public TimeSpan? PingTimeout { get; set; } - public string ContentType { get; set; } - public string OpaqueId { get; set; } public string Accept { get; set; } - public int? MaxRetries { get; set; } - public Uri ForceNode { get; set; } - public bool? DisableSniff { get; set; } - public bool? DisablePing { get; set; } - public bool? DisableDirectStreaming { get; set; } public IEnumerable AllowedStatusCodes { get; set; } public BasicAuthenticationCredentials BasicAuthenticationCredentials { get; set; } - public bool EnableHttpPipelining { get; set; } = true; public CancellationToken CancellationToken { get; set; } + + public X509CertificateCollection ClientCertificates { get; set; } + public string ContentType { get; set; } + public bool? DisableDirectStreaming { get; set; } + public bool? DisablePing { get; set; } + public bool? DisableSniff { get; set; } + public bool EnableHttpPipelining { get; set; } = true; + public Uri ForceNode { get; set; } + public int? MaxRetries { get; set; } + public string OpaqueId { get; set; } + public TimeSpan? PingTimeout { get; set; } + public TimeSpan? RequestTimeout { get; set; } + /// /// Submit the request on behalf in the context of a different user /// https://www.elastic.co/guide/en/shield/current/submitting-requests-for-other-users.html /// public string RunAs { get; set; } - public X509CertificateCollection ClientCertificates { get; set; } public bool ThrowExceptions { get; set; } } public class RequestConfigurationDescriptor : IRequestConfiguration { - private IRequestConfiguration Self => this; - TimeSpan? IRequestConfiguration.RequestTimeout { get; set; } - TimeSpan? IRequestConfiguration.PingTimeout { get; set; } - string IRequestConfiguration.ContentType { get; set; } - string IRequestConfiguration.OpaqueId { get; set; } - string IRequestConfiguration.Accept { get; set; } - - int? IRequestConfiguration.MaxRetries { get; set; } - Uri IRequestConfiguration.ForceNode { get; set; } - bool? IRequestConfiguration.DisableSniff { get; set; } - bool? IRequestConfiguration.DisablePing { get; set; } - bool? IRequestConfiguration.DisableDirectStreaming { get; set; } - IEnumerable IRequestConfiguration.AllowedStatusCodes { get; set; } - BasicAuthenticationCredentials IRequestConfiguration.BasicAuthenticationCredentials { get; set; } - bool IRequestConfiguration.EnableHttpPipelining { get; set; } = true; - string IRequestConfiguration.RunAs { get; set; } - X509CertificateCollection IRequestConfiguration.ClientCertificates { get; set; } - bool IRequestConfiguration.ThrowExceptions { get; set; } - public RequestConfigurationDescriptor(IRequestConfiguration config) { Self.RequestTimeout = config?.RequestTimeout; @@ -162,9 +144,28 @@ public RequestConfigurationDescriptor(IRequestConfiguration config) Self.OpaqueId = config?.OpaqueId; } + string IRequestConfiguration.Accept { get; set; } + IEnumerable IRequestConfiguration.AllowedStatusCodes { get; set; } + BasicAuthenticationCredentials IRequestConfiguration.BasicAuthenticationCredentials { get; set; } + X509CertificateCollection IRequestConfiguration.ClientCertificates { get; set; } + string IRequestConfiguration.ContentType { get; set; } + bool? IRequestConfiguration.DisableDirectStreaming { get; set; } + bool? IRequestConfiguration.DisablePing { get; set; } + bool? IRequestConfiguration.DisableSniff { get; set; } + bool IRequestConfiguration.EnableHttpPipelining { get; set; } = true; + Uri IRequestConfiguration.ForceNode { get; set; } + + int? IRequestConfiguration.MaxRetries { get; set; } + string IRequestConfiguration.OpaqueId { get; set; } + TimeSpan? IRequestConfiguration.PingTimeout { get; set; } + TimeSpan? IRequestConfiguration.RequestTimeout { get; set; } + string IRequestConfiguration.RunAs { get; set; } + private IRequestConfiguration Self => this; + bool IRequestConfiguration.ThrowExceptions { get; set; } + /// /// Submit the request on behalf in the context of a different shield user - ///
https://www.elastic.co/guide/en/shield/current/submitting-requests-for-other-users.html
+		/// 
https://www.elastic.co/guide/en/shield/current/submitting-requests-for-other-users.html
 		/// 
public RequestConfigurationDescriptor RunAs(string username) { @@ -278,11 +279,10 @@ public RequestConfigurationDescriptor ClientCertificates(X509CertificateCollecti /// Use the following client certificate to authenticate this request to Elasticsearch public RequestConfigurationDescriptor ClientCertificate(X509Certificate certificate) => - this.ClientCertificates(new X509Certificate2Collection { certificate }); + ClientCertificates(new X509Certificate2Collection { certificate }); /// Use the following client certificate to authenticate this request to Elasticsearch public RequestConfigurationDescriptor ClientCertificate(string certificatePath) => - this.ClientCertificates(new X509Certificate2Collection {new X509Certificate(certificatePath)}); - + ClientCertificates(new X509Certificate2Collection { new X509Certificate(certificatePath) }); } } diff --git a/src/Elasticsearch.Net/Configuration/Security/BasicAuthenticationCredentials.cs b/src/Elasticsearch.Net/Configuration/Security/BasicAuthenticationCredentials.cs index 04b195e0a91..2a3b4b0478f 100644 --- a/src/Elasticsearch.Net/Configuration/Security/BasicAuthenticationCredentials.cs +++ b/src/Elasticsearch.Net/Configuration/Security/BasicAuthenticationCredentials.cs @@ -2,10 +2,9 @@ { public class BasicAuthenticationCredentials { - public string Username { get; set; } - public string Password { get; set; } + public string Username { get; set; } - public override string ToString() => $"{this.Username}:{this.Password}"; + public override string ToString() => $"{Username}:{Password}"; } } diff --git a/src/Elasticsearch.Net/Connection/CertificateValidations.cs b/src/Elasticsearch.Net/Connection/CertificateValidations.cs index 0a6038dcbd3..c7ee0af7c13 100644 --- a/src/Elasticsearch.Net/Connection/CertificateValidations.cs +++ b/src/Elasticsearch.Net/Connection/CertificateValidations.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Concurrent; -using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; @@ -28,12 +26,14 @@ public static class CertificateValidations /// generate the nodes certificates with. This callback expects the CA to be part of the chain as intermediate CA. ///
/// The ca certificate used to generate the nodes certificate - /// Custom CA are never trusted by default unless they are in the machines trusted store, set this to true + /// + /// Custom CA are never trusted by default unless they are in the machines trusted store, set this to true /// if you've added the CA to the machines trusted store. In which case UntrustedRoot should not be accepted. /// /// By default we do not check revocation, it is however recommended to check this (either offline or online). public static Func AuthorityPartOfChain( - X509Certificate caCertificate, bool trustRoot = true, X509RevocationMode revocationMode = X509RevocationMode.NoCheck) => + X509Certificate caCertificate, bool trustRoot = true, X509RevocationMode revocationMode = X509RevocationMode.NoCheck + ) => (sender, cert, chain, errors) => errors == SslPolicyErrors.None || ValidIntermediateCa(caCertificate, cert, chain, trustRoot, revocationMode); @@ -45,30 +45,33 @@ public static Func Au /// the CA in the certificate chain. ///
/// The ca certificate used to generate the nodes certificate - /// Custom CA are never trusted by default unless they are in the machines trusted store, set this to true + /// + /// Custom CA are never trusted by default unless they are in the machines trusted store, set this to true /// if you've added the CA to the machines trusted store. In which case UntrustedRoot should not be accepted. /// /// By default we do not check revocation, it is however recommended to check this (either offline or online). public static Func AuthorityIsRoot( - X509Certificate caCertificate, bool trustRoot = true, X509RevocationMode revocationMode = X509RevocationMode.NoCheck) => + X509Certificate caCertificate, bool trustRoot = true, X509RevocationMode revocationMode = X509RevocationMode.NoCheck + ) => (sender, cert, chain, errors) => errors == SslPolicyErrors.None || ValidRootCa(caCertificate, cert, chain, trustRoot, revocationMode); private static X509Certificate2 to2(X509Certificate certificate) { - #if DOTNETCORE +#if DOTNETCORE return new X509Certificate2(certificate.Export(X509ContentType.Cert)); #else - return new X509Certificate2(certificate); - #endif + return new X509Certificate2(certificate); +#endif } private static bool ValidRootCa(X509Certificate caCertificate, X509Certificate certificate, X509Chain chain, bool trustRoot, - X509RevocationMode revocationMode) + X509RevocationMode revocationMode + ) { var ca = to2(caCertificate); - var privateChain = new X509Chain {ChainPolicy = {RevocationMode = revocationMode}}; + var privateChain = new X509Chain { ChainPolicy = { RevocationMode = revocationMode } }; privateChain.ChainPolicy.ExtraStore.Add(ca); privateChain.Build(to2(certificate)); @@ -78,20 +81,22 @@ private static bool ValidRootCa(X509Certificate caCertificate, X509Certificate c //custom CA's that are not in the machine trusted store will always have this status //by setting trustRoot = true (default) we skip this error if (chainStatus.Status == X509ChainStatusFlags.UntrustedRoot && trustRoot) continue; + //trustRoot is false so we expected our CA to be in the machines trusted store if (chainStatus.Status == X509ChainStatusFlags.UntrustedRoot) return false; + //otherwise if the chain has any error of any sort return false if (chainStatus.Status != X509ChainStatusFlags.NoError) return false; } return true; - } private static bool ValidIntermediateCa(X509Certificate caCertificate, X509Certificate certificate, X509Chain chain, bool trustRoot, - X509RevocationMode revocationMode) + X509RevocationMode revocationMode + ) { var ca = to2(caCertificate); - var privateChain = new X509Chain {ChainPolicy = {RevocationMode = revocationMode}}; + var privateChain = new X509Chain { ChainPolicy = { RevocationMode = revocationMode } }; privateChain.ChainPolicy.ExtraStore.Add(ca); privateChain.Build(to2(certificate)); @@ -104,8 +109,10 @@ private static bool ValidIntermediateCa(X509Certificate caCertificate, X509Certi //custom CA's that are not in the machine trusted store will always have this status //by setting trustRoot = true (default) we skip this error if (chainStatus.Status == X509ChainStatusFlags.UntrustedRoot && trustRoot) continue; + //trustRoot is false so we expected our CA to be in the machines trusted store if (chainStatus.Status == X509ChainStatusFlags.UntrustedRoot) return false; + //otherwise if the chain has any error of any sort return false if (chainStatus.Status != X509ChainStatusFlags.NoError) return false; } @@ -121,6 +128,7 @@ private static bool ValidIntermediateCa(X509Certificate caCertificate, X509Certi //mis aligned certificate chain, return false so we do not accept this certificate if (c != cPrivate) return false; + i++; } return found; diff --git a/src/Elasticsearch.Net/Connection/ClientCertificate.cs b/src/Elasticsearch.Net/Connection/ClientCertificate.cs index 8ab6541d8a4..be85d0121f9 100644 --- a/src/Elasticsearch.Net/Connection/ClientCertificate.cs +++ b/src/Elasticsearch.Net/Connection/ClientCertificate.cs @@ -29,7 +29,6 @@ THE SOFTWARE. */ using System; -using System.Diagnostics; using System.IO; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; @@ -62,6 +61,7 @@ private static RSACryptoServiceProvider DecodeRsaPrivateKey(byte[] privkey) twobytes = binr.ReadUInt16(); if (twobytes != 0x0102) return null; //version number + var bt = binr.ReadByte(); if (bt != 0x00) return null; @@ -109,7 +109,7 @@ private static int GetSizeOfIntegerToReadNext(BinaryReader br) case 0x82: var highbyte = br.ReadByte(); var lowbyte = br.ReadByte(); - byte[] modint = {lowbyte, highbyte, 0x00, 0x00}; + byte[] modint = { lowbyte, highbyte, 0x00, 0x00 }; count = BitConverter.ToInt32(modint, 0); break; default: diff --git a/src/Elasticsearch.Net/Connection/HttpConnection.cs b/src/Elasticsearch.Net/Connection/HttpConnection.cs index f951ca13592..6fef2976838 100644 --- a/src/Elasticsearch.Net/Connection/HttpConnection.cs +++ b/src/Elasticsearch.Net/Connection/HttpConnection.cs @@ -3,7 +3,7 @@ namespace Elasticsearch.Net { - /// The default IConnection implementation. Uses on the current .NET desktop framework. + /// The default IConnection implementation. Uses on the current .NET desktop framework. public class HttpConnection : HttpWebRequestConnection { } } #endif diff --git a/src/Elasticsearch.Net/Connection/HttpMethod.cs b/src/Elasticsearch.Net/Connection/HttpMethod.cs index d13ee52a0c8..c1ad63a9552 100644 --- a/src/Elasticsearch.Net/Connection/HttpMethod.cs +++ b/src/Elasticsearch.Net/Connection/HttpMethod.cs @@ -8,12 +8,16 @@ public enum HttpMethod { [EnumMember(Value = "GET")] GET, + [EnumMember(Value = "POST")] POST, + [EnumMember(Value = "PUT")] PUT, + [EnumMember(Value = "DELETE")] DELETE, + [EnumMember(Value = "HEAD")] HEAD } diff --git a/src/Elasticsearch.Net/Connection/HttpWebRequestConnection.cs b/src/Elasticsearch.Net/Connection/HttpWebRequestConnection.cs index 61b53c7bf86..c8755d2f9c9 100644 --- a/src/Elasticsearch.Net/Connection/HttpWebRequestConnection.cs +++ b/src/Elasticsearch.Net/Connection/HttpWebRequestConnection.cs @@ -16,22 +16,135 @@ namespace Elasticsearch.Net #endif public class HttpWebRequestConnection : IConnection { - internal static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null; - static HttpWebRequestConnection() { //Not available under mono if (!IsMono) HttpWebRequest.DefaultMaximumErrorResponseLength = -1; } + internal static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null; + + public virtual TResponse Request(RequestData requestData) + where TResponse : class, IElasticsearchResponse, new() + { + int? statusCode = null; + IEnumerable warnings = null; + Stream responseStream = null; + Exception ex = null; + string mimeType = null; + try + { + var request = CreateHttpWebRequest(requestData); + var data = requestData.PostData; + + if (data != null) + { + using (var stream = request.GetRequestStream()) + { + if (requestData.HttpCompression) + using (var zipStream = new GZipStream(stream, CompressionMode.Compress)) + data.Write(zipStream, requestData.ConnectionSettings); + else + data.Write(stream, requestData.ConnectionSettings); + } + } + requestData.MadeItToResponse = true; + + //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx + //Either the stream or the response object needs to be closed but not both although it won't + //throw any errors if both are closed atleast one of them has to be Closed. + //Since we expose the stream we let closing the stream determining when to close the connection + var response = (HttpWebResponse)request.GetResponse(); + HandleResponse(response, out statusCode, out responseStream, out mimeType); + + //response.Headers.HasKeys() can return false even if response.Headers.AllKeys has values. + if (response.SupportsHeaders && response.Headers.Count > 0 && response.Headers.AllKeys.Contains("Warning")) + warnings = response.Headers.GetValues("Warning"); + } + catch (WebException e) + { + ex = e; + if (e.Response is HttpWebResponse response) + HandleResponse(response, out statusCode, out responseStream, out mimeType); + } + responseStream = responseStream ?? Stream.Null; + return ResponseBuilder.ToResponse(requestData, ex, statusCode, warnings, responseStream, mimeType); + } + + public virtual async Task RequestAsync(RequestData requestData, + CancellationToken cancellationToken + ) + where TResponse : class, IElasticsearchResponse, new() + { + Action unregisterWaitHandle = null; + int? statusCode = null; + IEnumerable warnings = null; + Stream responseStream = null; + Exception ex = null; + string mimeType = null; + try + { + var data = requestData.PostData; + var request = CreateHttpWebRequest(requestData); + using (cancellationToken.Register(() => request.Abort())) + { + if (data != null) + { + var apmGetRequestStreamTask = + Task.Factory.FromAsync(request.BeginGetRequestStream, r => request.EndGetRequestStream(r), null); + unregisterWaitHandle = RegisterApmTaskTimeout(apmGetRequestStreamTask, request, requestData); + + using (var stream = await apmGetRequestStreamTask.ConfigureAwait(false)) + { + if (requestData.HttpCompression) + using (var zipStream = new GZipStream(stream, CompressionMode.Compress)) + await data.WriteAsync(zipStream, requestData.ConnectionSettings, cancellationToken).ConfigureAwait(false); + else + await data.WriteAsync(stream, requestData.ConnectionSettings, cancellationToken).ConfigureAwait(false); + } + unregisterWaitHandle?.Invoke(); + } + requestData.MadeItToResponse = true; + //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx + //Either the stream or the response object needs to be closed but not both although it won't + //throw any errors if both are closed atleast one of them has to be Closed. + //Since we expose the stream we let closing the stream determining when to close the connection + + var apmGetResponseTask = Task.Factory.FromAsync(request.BeginGetResponse, r => request.EndGetResponse(r), null); + unregisterWaitHandle = RegisterApmTaskTimeout(apmGetResponseTask, request, requestData); + + var response = (HttpWebResponse)await apmGetResponseTask.ConfigureAwait(false); + HandleResponse(response, out statusCode, out responseStream, out mimeType); + if (response.SupportsHeaders && response.Headers.HasKeys() && response.Headers.AllKeys.Contains("Warning")) + warnings = response.Headers.GetValues("Warning"); + } + } + catch (WebException e) + { + ex = e; + if (e.Response is HttpWebResponse response) + HandleResponse(response, out statusCode, out responseStream, out mimeType); + } + finally + { + unregisterWaitHandle?.Invoke(); + } + responseStream = responseStream ?? Stream.Null; + return await ResponseBuilder.ToResponseAsync + (requestData, ex, statusCode, warnings, responseStream, mimeType, cancellationToken) + .ConfigureAwait(false); + } + + void IDisposable.Dispose() => DisposeManagedResources(); + protected virtual HttpWebRequest CreateHttpWebRequest(RequestData requestData) { - var request = this.CreateWebRequest(requestData); - this.SetBasicAuthenticationIfNeeded(request, requestData); - this.SetProxyIfNeeded(request, requestData); - this.SetServerCertificateValidationCallBackIfNeeded(request, requestData); - this.SetClientCertificates(request, requestData); - this.AlterServicePoint(request.ServicePoint, requestData); + var request = CreateWebRequest(requestData); + SetBasicAuthenticationIfNeeded(request, requestData); + SetProxyIfNeeded(request, requestData); + SetServerCertificateValidationCallBackIfNeeded(request, requestData); + SetClientCertificates(request, requestData); + AlterServicePoint(request.ServicePoint, requestData); return request; } @@ -56,7 +169,7 @@ protected virtual void SetServerCertificateValidationCallBackIfNeeded(HttpWebReq protected virtual HttpWebRequest CreateWebRequest(RequestData requestData) { - var request = (HttpWebRequest) WebRequest.Create(requestData.Uri); + var request = (HttpWebRequest)WebRequest.Create(requestData.Uri); request.Accept = requestData.Accept; request.ContentType = requestData.RequestMimeType; @@ -78,7 +191,7 @@ protected virtual HttpWebRequest CreateWebRequest(RequestData requestData) if (requestData.Headers != null && requestData.Headers.HasKeys()) request.Headers.Add(requestData.Headers); - var timeout = (int) requestData.RequestTimeout.TotalMilliseconds; + var timeout = (int)requestData.RequestTimeout.TotalMilliseconds; request.Timeout = timeout; request.ReadWriteTimeout = timeout; @@ -87,7 +200,7 @@ protected virtual HttpWebRequest CreateWebRequest(RequestData requestData) //see: https://github.com/elasticsearch/elasticsearch-net/issues/562 var m = requestData.Method.GetStringValue(); request.Method = m; - if (m != "HEAD" && m != "GET" && (requestData.PostData == null)) + if (m != "HEAD" && m != "GET" && requestData.PostData == null) request.ContentLength = 0; return request; @@ -136,53 +249,6 @@ protected virtual void SetBasicAuthenticationIfNeeded(HttpWebRequest request, Re request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userInfo)); } - public virtual TResponse Request(RequestData requestData) - where TResponse : class, IElasticsearchResponse, new() - { - int? statusCode = null; - IEnumerable warnings = null; - Stream responseStream = null; - Exception ex = null; - string mimeType = null; - try - { - var request = this.CreateHttpWebRequest(requestData); - var data = requestData.PostData; - - if (data != null) - { - using (var stream = request.GetRequestStream()) - { - if (requestData.HttpCompression) - using (var zipStream = new GZipStream(stream, CompressionMode.Compress)) - data.Write(zipStream, requestData.ConnectionSettings); - else - data.Write(stream, requestData.ConnectionSettings); - } - } - requestData.MadeItToResponse = true; - - //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx - //Either the stream or the response object needs to be closed but not both although it won't - //throw any errors if both are closed atleast one of them has to be Closed. - //Since we expose the stream we let closing the stream determining when to close the connection - var response = (HttpWebResponse) request.GetResponse(); - HandleResponse(response, out statusCode, out responseStream, out mimeType); - - //response.Headers.HasKeys() can return false even if response.Headers.AllKeys has values. - if (response.SupportsHeaders && response.Headers.Count > 0 && response.Headers.AllKeys.Contains("Warning")) - warnings = response.Headers.GetValues("Warning"); - } - catch (WebException e) - { - ex = e; - if (e.Response is HttpWebResponse response) - HandleResponse(response, out statusCode, out responseStream, out mimeType); - } - responseStream = responseStream ?? Stream.Null; - return ResponseBuilder.ToResponse(requestData, ex, statusCode, warnings, responseStream, mimeType); - } - /// /// Registers an APM async task cancellation on the threadpool @@ -199,74 +265,13 @@ private static Action RegisterApmTaskTimeout(IAsyncResult result, WebRequest req private static void TimeoutCallback(object state, bool timedOut) { if (!timedOut) return; - (state as WebRequest)?.Abort(); - } - public virtual async Task RequestAsync(RequestData requestData, - CancellationToken cancellationToken) - where TResponse : class, IElasticsearchResponse, new() - { - Action unregisterWaitHandle = null; - int? statusCode = null; - IEnumerable warnings = null; - Stream responseStream = null; - Exception ex = null; - string mimeType = null; - try - { - var data = requestData.PostData; - var request = this.CreateHttpWebRequest(requestData); - using (cancellationToken.Register(() => request.Abort())) - { - if (data != null) - { - var apmGetRequestStreamTask = Task.Factory.FromAsync(request.BeginGetRequestStream, r => request.EndGetRequestStream(r), null); - unregisterWaitHandle = RegisterApmTaskTimeout(apmGetRequestStreamTask, request, requestData); - - using (var stream = await apmGetRequestStreamTask.ConfigureAwait(false)) - { - if (requestData.HttpCompression) - using (var zipStream = new GZipStream(stream, CompressionMode.Compress)) - await data.WriteAsync(zipStream, requestData.ConnectionSettings, cancellationToken).ConfigureAwait(false); - else - await data.WriteAsync(stream, requestData.ConnectionSettings, cancellationToken).ConfigureAwait(false); - } - unregisterWaitHandle?.Invoke(); - } - requestData.MadeItToResponse = true; - //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx - //Either the stream or the response object needs to be closed but not both although it won't - //throw any errors if both are closed atleast one of them has to be Closed. - //Since we expose the stream we let closing the stream determining when to close the connection - - var apmGetResponseTask = Task.Factory.FromAsync(request.BeginGetResponse, r => request.EndGetResponse(r), null); - unregisterWaitHandle = RegisterApmTaskTimeout(apmGetResponseTask, request, requestData); - - var response = (HttpWebResponse) (await apmGetResponseTask.ConfigureAwait(false)); - HandleResponse(response, out statusCode, out responseStream, out mimeType); - if (response.SupportsHeaders && response.Headers.HasKeys() && response.Headers.AllKeys.Contains("Warning")) - warnings = response.Headers.GetValues("Warning"); - } - } - catch (WebException e) - { - ex = e; - if (e.Response is HttpWebResponse response) - HandleResponse(response, out statusCode, out responseStream, out mimeType); - } - finally - { - unregisterWaitHandle?.Invoke(); - } - responseStream = responseStream ?? Stream.Null; - return await ResponseBuilder.ToResponseAsync - (requestData, ex, statusCode, warnings, responseStream, mimeType, cancellationToken) - .ConfigureAwait(false); + (state as WebRequest)?.Abort(); } private static void HandleResponse(HttpWebResponse response, out int? statusCode, out Stream responseStream, out string mimeType) { - statusCode = (int) response.StatusCode; + statusCode = (int)response.StatusCode; responseStream = response.GetResponseStream(); mimeType = response.ContentType; // https://github.com/elastic/elasticsearch-net/issues/2311 @@ -274,8 +279,6 @@ private static void HandleResponse(HttpWebResponse response, out int? statusCode if (responseStream == null || responseStream == Stream.Null) response.Dispose(); } - void IDisposable.Dispose() => this.DisposeManagedResources(); - protected virtual void DisposeManagedResources() { } } } diff --git a/src/Elasticsearch.Net/Connection/InMemoryConnection.cs b/src/Elasticsearch.Net/Connection/InMemoryConnection.cs index 65957d91ccd..9f1abc0d37d 100644 --- a/src/Elasticsearch.Net/Connection/InMemoryConnection.cs +++ b/src/Elasticsearch.Net/Connection/InMemoryConnection.cs @@ -9,20 +9,17 @@ namespace Elasticsearch.Net { public class InMemoryConnection : IConnection { + internal static readonly byte[] EmptyBody = Encoding.UTF8.GetBytes(""); + private readonly string _contentType; + private readonly Exception _exception; private readonly byte[] _responseBody; private readonly int _statusCode; - private readonly Exception _exception; - private readonly string _contentType; - internal static readonly byte[] EmptyBody = Encoding.UTF8.GetBytes(""); /// /// Every request will succeed with this overload, note that it won't actually return mocked responses /// so using this overload might fail if you are using it to test high level bits that need to deserialize the response. /// - public InMemoryConnection() - { - _statusCode = 200; - } + public InMemoryConnection() => _statusCode = 200; public InMemoryConnection(byte[] responseBody, int statusCode = 200, Exception exception = null, string contentType = RequestData.MimeType) { @@ -32,15 +29,19 @@ public InMemoryConnection(byte[] responseBody, int statusCode = 200, Exception e _contentType = contentType; } - public virtual Task RequestAsync(RequestData requestData, CancellationToken cancellationToken) + public virtual TResponse Request(RequestData requestData) where TResponse : class, IElasticsearchResponse, new() => - this.ReturnConnectionStatusAsync(requestData, cancellationToken); + ReturnConnectionStatus(requestData); - public virtual TResponse Request(RequestData requestData) + public virtual Task RequestAsync(RequestData requestData, CancellationToken cancellationToken) where TResponse : class, IElasticsearchResponse, new() => - this.ReturnConnectionStatus(requestData); + ReturnConnectionStatusAsync(requestData, cancellationToken); - protected TResponse ReturnConnectionStatus(RequestData requestData, byte[] responseBody = null, int? statusCode = null, string contentType = null) + void IDisposable.Dispose() => DisposeManagedResources(); + + protected TResponse ReturnConnectionStatus(RequestData requestData, byte[] responseBody = null, int? statusCode = null, + string contentType = null + ) where TResponse : class, IElasticsearchResponse, new() { var body = responseBody ?? _responseBody; @@ -58,12 +59,14 @@ protected TResponse ReturnConnectionStatus(RequestData requestData, b } requestData.MadeItToResponse = true; - var sc = statusCode ?? this._statusCode; - Stream s = (body != null) ? requestData.MemoryStreamFactory.Create(body) : requestData.MemoryStreamFactory.Create(EmptyBody); + var sc = statusCode ?? _statusCode; + Stream s = body != null ? requestData.MemoryStreamFactory.Create(body) : requestData.MemoryStreamFactory.Create(EmptyBody); return ResponseBuilder.ToResponse(requestData, _exception, sc, null, s, contentType ?? _contentType ?? RequestData.MimeType); } - protected async Task ReturnConnectionStatusAsync(RequestData requestData, CancellationToken cancellationToken, byte[] responseBody = null, int? statusCode = null, string contentType = null) + protected async Task ReturnConnectionStatusAsync(RequestData requestData, CancellationToken cancellationToken, + byte[] responseBody = null, int? statusCode = null, string contentType = null + ) where TResponse : class, IElasticsearchResponse, new() { var body = responseBody ?? _responseBody; @@ -81,14 +84,13 @@ protected async Task ReturnConnectionStatusAsync(RequestDa } requestData.MadeItToResponse = true; - var sc = statusCode ?? this._statusCode; - Stream s = (body != null) ? requestData.MemoryStreamFactory.Create(body) : requestData.MemoryStreamFactory.Create(EmptyBody); - return await ResponseBuilder.ToResponseAsync(requestData, _exception, sc, null, s, contentType ?? _contentType, cancellationToken) + var sc = statusCode ?? _statusCode; + Stream s = body != null ? requestData.MemoryStreamFactory.Create(body) : requestData.MemoryStreamFactory.Create(EmptyBody); + return await ResponseBuilder + .ToResponseAsync(requestData, _exception, sc, null, s, contentType ?? _contentType, cancellationToken) .ConfigureAwait(false); } - void IDisposable.Dispose() => DisposeManagedResources(); - protected virtual void DisposeManagedResources() { } } } diff --git a/src/Elasticsearch.Net/ConnectionPool/IConnectionPool.cs b/src/Elasticsearch.Net/ConnectionPool/IConnectionPool.cs index 1fee6bb77aa..cfba082d7a7 100644 --- a/src/Elasticsearch.Net/ConnectionPool/IConnectionPool.cs +++ b/src/Elasticsearch.Net/ConnectionPool/IConnectionPool.cs @@ -6,11 +6,9 @@ namespace Elasticsearch.Net public interface IConnectionPool : IDisposable { /// - /// Returns a read only view of all the nodes in the cluster, which might involve creating copies of nodes e.g - /// if you are using . - /// If you do not need an isolated copy of the nodes, please read to completion + /// The last time that this instance was updated /// - IReadOnlyCollection Nodes { get; } + DateTime LastUpdate { get; } /// /// Returns the default maximum retries for the connection pool implementation. @@ -20,9 +18,17 @@ public interface IConnectionPool : IDisposable int MaxRetries { get; } /// - /// Whether reseeding with new nodes is supported + /// Returns a read only view of all the nodes in the cluster, which might involve creating copies of nodes e.g + /// if you are using . + /// If you do not need an isolated copy of the nodes, please read to completion /// - bool SupportsReseeding { get; } + IReadOnlyCollection Nodes { get; } + + /// + /// Whether a sniff is seen on startup. The implementation is + /// responsible for setting this in a thread safe fashion. + /// + bool SniffedOnStartup { get; set; } /// /// Whether pinging is supported @@ -30,21 +36,15 @@ public interface IConnectionPool : IDisposable bool SupportsPinging { get; } /// - /// The last time that this instance was updated + /// Whether reseeding with new nodes is supported /// - DateTime LastUpdate { get; } + bool SupportsReseeding { get; } /// /// Whether SSL/TLS is being used /// bool UsingSsl { get; } - /// - /// Whether a sniff is seen on startup. The implementation is - /// responsible for setting this in a thread safe fashion. - /// - bool SniffedOnStartup { get; set; } - /// /// Creates a view over the nodes, with changing starting positions, that wraps over on each call /// e.g Thread A might get 1,2,3,4,5 and thread B will get 2,3,4,5,1. @@ -56,6 +56,5 @@ public interface IConnectionPool : IDisposable /// Reseeds the nodes. The implementation is responsible for thread safety /// void Reseed(IEnumerable nodes); - } } diff --git a/src/Elasticsearch.Net/ConnectionPool/Node.cs b/src/Elasticsearch.Net/ConnectionPool/Node.cs index bef75f36839..cf7d2c5e1af 100644 --- a/src/Elasticsearch.Net/ConnectionPool/Node.cs +++ b/src/Elasticsearch.Net/ConnectionPool/Node.cs @@ -6,89 +6,100 @@ namespace Elasticsearch.Net { public class Node : IEquatable { + private static readonly IReadOnlyDictionary EmptySettings = + new ReadOnlyDictionary(new Dictionary()); + public Node(Uri uri) { //this makes sure that elasticsearch paths stay relative to the path passed in //http://my-saas-provider.com/instance if (!uri.OriginalString.EndsWith("/", StringComparison.Ordinal)) uri = new Uri(uri.OriginalString + "/"); - this.Uri = uri; - this.IsAlive = true; - this.HoldsData = true; - this.MasterEligible = true; - this.IsResurrected = true; + Uri = uri; + IsAlive = true; + HoldsData = true; + MasterEligible = true; + IsResurrected = true; } - public Uri Uri { get; } + public bool ClientNode => !MasterEligible && !HoldsData; - /// When set this signals the transport that a ping before first usage would be wise - public bool IsResurrected { get; set; } + /// When marked dead this reflects the date that the node has to be taken out of rotation till + public DateTime DeadUntil { get; private set; } - /// Whether HTTP is enabled on the node or not - public bool HttpEnabled { get; set; } = true; + /// The number of failed attempts trying to use this node, resets when a node is marked alive + public int FailedAttempts { get; private set; } /// Indicates whether this node holds data, defaults to true when unknown/unspecified public bool HoldsData { get; set; } - /// Indicates whether this node is master eligible, defaults to true when unknown/unspecified - public bool MasterEligible { get; set; } + /// Whether HTTP is enabled on the node or not + public bool HttpEnabled { get; set; } = true; + + /// The id of the node, defaults to null when unknown/unspecified + public string Id { get; set; } /// Indicates whether this node is allowed to run ingest pipelines, defaults to true when unknown/unspecified public bool IngestEnabled { get; set; } - public bool MasterOnlyNode => this.MasterEligible && !this.HoldsData; + public virtual bool IsAlive { get; private set; } - public bool ClientNode => !this.MasterEligible && !this.HoldsData; + /// When set this signals the transport that a ping before first usage would be wise + public bool IsResurrected { get; set; } - /// The id of the node, defaults to null when unknown/unspecified - public string Id { get; set; } + /// Indicates whether this node is master eligible, defaults to true when unknown/unspecified + public bool MasterEligible { get; set; } + + public bool MasterOnlyNode => MasterEligible && !HoldsData; /// The name of the node, defaults to null when unknown/unspecified public string Name { get; set; } - private static readonly IReadOnlyDictionary EmptySettings = new ReadOnlyDictionary(new Dictionary()); public IReadOnlyDictionary Settings { get; set; } = EmptySettings; - /// The number of failed attempts trying to use this node, resets when a node is marked alive - public int FailedAttempts { get; private set; } + public Uri Uri { get; } - /// When marked dead this reflects the date that the node has to be taken out of rotation till - public DateTime DeadUntil { get; private set; } + //a Node is only unique by its Uri + public bool Equals(Node other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; - public virtual bool IsAlive { get; private set; } + return Uri == other.Uri; + } public void MarkDead(DateTime untill) { - this.FailedAttempts++; - this.IsAlive = false; - this.IsResurrected = false; - this.DeadUntil = untill; + FailedAttempts++; + IsAlive = false; + IsResurrected = false; + DeadUntil = untill; } public void MarkAlive() { - this.FailedAttempts = 0; - this.IsAlive = true; - this.IsResurrected = false; - this.DeadUntil = default(DateTime); + FailedAttempts = 0; + IsAlive = true; + IsResurrected = false; + DeadUntil = default(DateTime); } - public Uri CreatePath(string path) => new Uri(this.Uri, path); + public Uri CreatePath(string path) => new Uri(Uri, path); public Node Clone() => - new Node(this.Uri) + new Node(Uri) { - IsResurrected = this.IsResurrected, - Id = this.Id, - Name = this.Name, - HoldsData = this.HoldsData, - MasterEligible = this.MasterEligible, - FailedAttempts = this.FailedAttempts, - DeadUntil = this.DeadUntil, - IsAlive = this.IsAlive, - Settings = this.Settings, - IngestEnabled = this.IngestEnabled, - HttpEnabled = this.HttpEnabled + IsResurrected = IsResurrected, + Id = Id, + Name = Name, + HoldsData = HoldsData, + MasterEligible = MasterEligible, + FailedAttempts = FailedAttempts, + DeadUntil = DeadUntil, + IsAlive = IsAlive, + Settings = Settings, + IngestEnabled = IngestEnabled, + HttpEnabled = HttpEnabled }; @@ -99,22 +110,15 @@ public Node Clone() => public static implicit operator Node(Uri uri) => new Node(uri); - //a Node is only unique by its Uri - public bool Equals(Node other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return this.Uri == other.Uri; - } - public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; + if (obj.GetType() != GetType()) return false; + return Equals((Node)obj); } - public override int GetHashCode() => this.Uri.GetHashCode(); + public override int GetHashCode() => Uri.GetHashCode(); } } diff --git a/src/Elasticsearch.Net/ConnectionPool/SingleNodeConnectionPool.cs b/src/Elasticsearch.Net/ConnectionPool/SingleNodeConnectionPool.cs index 62986860d33..98db354aedc 100644 --- a/src/Elasticsearch.Net/ConnectionPool/SingleNodeConnectionPool.cs +++ b/src/Elasticsearch.Net/ConnectionPool/SingleNodeConnectionPool.cs @@ -8,43 +8,47 @@ namespace Elasticsearch.Net /// public class SingleNodeConnectionPool : IConnectionPool { - /// - public int MaxRetries => 0; + /// + public SingleNodeConnectionPool(Uri uri, IDateTimeProvider dateTimeProvider = null) + { + var node = new Node(uri); + UsingSsl = node.Uri.Scheme == "https"; + Nodes = new List { node }; + LastUpdate = (dateTimeProvider ?? DateTimeProvider.Default).Now(); + } - /// - public bool SupportsReseeding => false; + /// + public DateTime LastUpdate { get; } - /// - public bool SupportsPinging => false; + /// + public int MaxRetries => 0; - /// - public void Reseed(IEnumerable nodes) { } //ignored + /// + public IReadOnlyCollection Nodes { get; } - /// - public bool UsingSsl { get; } + /// + public bool SniffedOnStartup + { + get => true; + set { } + } - /// - public bool SniffedOnStartup { get => true; set { } } + /// + public bool SupportsPinging => false; - /// - public IReadOnlyCollection Nodes { get; } + /// + public bool SupportsReseeding => false; - /// - public DateTime LastUpdate { get; } + /// + public bool UsingSsl { get; } - /// - public SingleNodeConnectionPool(Uri uri, IDateTimeProvider dateTimeProvider = null) - { - var node = new Node(uri); - this.UsingSsl = node.Uri.Scheme == "https"; - this.Nodes = new List { node }; - this.LastUpdate = (dateTimeProvider ?? DateTimeProvider.Default).Now(); - } + /// + public IEnumerable CreateView(Action audit = null) => Nodes; - /// - public IEnumerable CreateView(Action audit = null) => this.Nodes; + /// + public void Reseed(IEnumerable nodes) { } //ignored - void IDisposable.Dispose() => this.DisposeManagedResources(); + void IDisposable.Dispose() => DisposeManagedResources(); protected virtual void DisposeManagedResources() { } } diff --git a/src/Elasticsearch.Net/ConnectionPool/SniffingConnectionPool.cs b/src/Elasticsearch.Net/ConnectionPool/SniffingConnectionPool.cs index 251dcf308db..2838b55b8d8 100644 --- a/src/Elasticsearch.Net/ConnectionPool/SniffingConnectionPool.cs +++ b/src/Elasticsearch.Net/ConnectionPool/SniffingConnectionPool.cs @@ -9,15 +9,8 @@ public class SniffingConnectionPool : StaticConnectionPool { private readonly ReaderWriterLockSlim _readerWriter = new ReaderWriterLockSlim(); - /// - public override bool SupportsReseeding => true; - - /// - public override bool SupportsPinging => true; - public SniffingConnectionPool(IEnumerable uris, bool randomize = true, IDateTimeProvider dateTimeProvider = null) - : base(uris, randomize, dateTimeProvider) - { } + : base(uris, randomize, dateTimeProvider) { } public SniffingConnectionPool(IEnumerable nodes, bool randomize = true, IDateTimeProvider dateTimeProvider = null) : base(nodes, randomize, dateTimeProvider) { } @@ -25,7 +18,7 @@ public SniffingConnectionPool(IEnumerable nodes, bool randomize = true, ID public SniffingConnectionPool(IEnumerable nodes, Func nodeScorer, IDateTimeProvider dateTimeProvider = null) : base(nodes, nodeScorer, dateTimeProvider) { } - /// + /// public override IReadOnlyCollection Nodes { get @@ -34,55 +27,61 @@ public override IReadOnlyCollection Nodes { //since internalnodes can be changed after returning we return //a completely new list of cloned nodes - this._readerWriter.EnterReadLock(); - return this.InternalNodes.Select(n => n.Clone()).ToList(); + _readerWriter.EnterReadLock(); + return InternalNodes.Select(n => n.Clone()).ToList(); } finally { - this._readerWriter.ExitReadLock(); + _readerWriter.ExitReadLock(); } } } - /// + /// + public override bool SupportsPinging => true; + + /// + public override bool SupportsReseeding => true; + + /// public override void Reseed(IEnumerable nodes) { if (!nodes.HasAny()) return; try { - this._readerWriter.EnterWriteLock(); - var sortedNodes = this.SortNodes(nodes) + _readerWriter.EnterWriteLock(); + var sortedNodes = SortNodes(nodes) .DistinctBy(n => n.Uri) .ToList(); - this.InternalNodes = sortedNodes; - this.GlobalCursor = -1; - this.LastUpdate = this.DateTimeProvider.Now(); + InternalNodes = sortedNodes; + GlobalCursor = -1; + LastUpdate = DateTimeProvider.Now(); } finally { - this._readerWriter.ExitWriteLock(); + _readerWriter.ExitWriteLock(); } } - /// + /// public override IEnumerable CreateView(Action audit = null) { - this._readerWriter.EnterReadLock(); + _readerWriter.EnterReadLock(); try { return base.CreateView(audit); } finally { - this._readerWriter.ExitReadLock(); + _readerWriter.ExitReadLock(); } } protected override void DisposeManagedResources() { - this._readerWriter?.Dispose(); + _readerWriter?.Dispose(); base.DisposeManagedResources(); } } diff --git a/src/Elasticsearch.Net/ConnectionPool/StaticConnectionPool.cs b/src/Elasticsearch.Net/ConnectionPool/StaticConnectionPool.cs index 11b8028b794..ce632a190f7 100644 --- a/src/Elasticsearch.Net/ConnectionPool/StaticConnectionPool.cs +++ b/src/Elasticsearch.Net/ConnectionPool/StaticConnectionPool.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Threading; @@ -8,79 +7,74 @@ namespace Elasticsearch.Net { public class StaticConnectionPool : IConnectionPool { + protected int GlobalCursor = -1; private readonly Func _nodeScorer; - protected IDateTimeProvider DateTimeProvider { get; } - protected Random Random { get; } = new Random(); - protected bool Randomize { get; } - - protected List InternalNodes { get; set; } - - protected List AliveNodes - { - get - { - var now = DateTimeProvider.Now(); - return this.InternalNodes - .Where(n => n.IsAlive || n.DeadUntil <= now) - .ToList(); - } - } - - /// - public virtual IReadOnlyCollection Nodes => this.InternalNodes; - - /// - public int MaxRetries => this.InternalNodes.Count - 1; - - /// - public virtual bool SupportsReseeding => false; - /// - public virtual bool SupportsPinging => true; - - /// - public virtual void Reseed(IEnumerable nodes) { } //ignored - - /// - public bool UsingSsl { get; } - - /// - public bool SniffedOnStartup { get; set; } - - /// - public DateTime LastUpdate { get; protected set; } public StaticConnectionPool(IEnumerable uris, bool randomize = true, IDateTimeProvider dateTimeProvider = null) - : this(uris.Select(uri => new Node(uri)), randomize, dateTimeProvider) - { } + : this(uris.Select(uri => new Node(uri)), randomize, dateTimeProvider) { } public StaticConnectionPool(IEnumerable nodes, bool randomize = true, IDateTimeProvider dateTimeProvider = null) - : this(nodes, null, dateTimeProvider) - { - this.Randomize = randomize; - } + : this(nodes, null, dateTimeProvider) => Randomize = randomize; //this constructor is protected because nodeScorer only makes sense on subclasses that support reseeding //otherwise just manually sort `nodes` before instantiating. protected StaticConnectionPool(IEnumerable nodes, Func nodeScorer, IDateTimeProvider dateTimeProvider = null) { nodes.ThrowIfEmpty(nameof(nodes)); - this.DateTimeProvider = dateTimeProvider ?? Elasticsearch.Net.DateTimeProvider.Default; + DateTimeProvider = dateTimeProvider ?? Net.DateTimeProvider.Default; var nn = nodes.ToList(); var uris = nn.Select(n => n.Uri).ToList(); if (uris.Select(u => u.Scheme).Distinct().Count() > 1) throw new ArgumentException("Trying to instantiate a connection pool with mixed URI Schemes"); - this.UsingSsl = uris.Any(uri => uri.Scheme == "https"); + UsingSsl = uris.Any(uri => uri.Scheme == "https"); - this._nodeScorer = nodeScorer; - this.InternalNodes = this.SortNodes(nn) + _nodeScorer = nodeScorer; + InternalNodes = SortNodes(nn) .DistinctBy(n => n.Uri) .ToList(); - this.LastUpdate = this.DateTimeProvider.Now(); + LastUpdate = DateTimeProvider.Now(); } - protected int GlobalCursor = -1; + /// + public DateTime LastUpdate { get; protected set; } + + /// + public int MaxRetries => InternalNodes.Count - 1; + + /// + public virtual IReadOnlyCollection Nodes => InternalNodes; + + /// + public bool SniffedOnStartup { get; set; } + + /// + public virtual bool SupportsPinging => true; + + /// + public virtual bool SupportsReseeding => false; + + /// + public bool UsingSsl { get; } + + protected List AliveNodes + { + get + { + var now = DateTimeProvider.Now(); + return InternalNodes + .Where(n => n.IsAlive || n.DeadUntil <= now) + .ToList(); + } + } + + protected IDateTimeProvider DateTimeProvider { get; } + + protected List InternalNodes { get; set; } + protected Random Random { get; } = new Random(); + protected bool Randomize { get; } + /// /// Creates a view of all the live nodes with changing starting positions that wraps over on each call /// e.g Thread A might get 1,2,3,4,5 and thread B will get 2,3,4,5,1. @@ -88,28 +82,32 @@ protected StaticConnectionPool(IEnumerable nodes, Func nodeSc /// public virtual IEnumerable CreateView(Action audit = null) { - var nodes = this.AliveNodes; + var nodes = AliveNodes; var globalCursor = Interlocked.Increment(ref GlobalCursor); if (nodes.Count == 0) { //could not find a suitable node retrying on first node off globalCursor - yield return this.RetryInternalNodes(globalCursor, audit); + yield return RetryInternalNodes(globalCursor, audit); + yield break; } var localCursor = globalCursor % nodes.Count; - foreach (var aliveNode in SelectAliveNodes(localCursor, nodes, audit)) - { - yield return aliveNode; - } + foreach (var aliveNode in SelectAliveNodes(localCursor, nodes, audit)) yield return aliveNode; } + /// + public virtual void Reseed(IEnumerable nodes) { } //ignored + + + void IDisposable.Dispose() => DisposeManagedResources(); + protected virtual Node RetryInternalNodes(int globalCursor, Action audit = null) { audit?.Invoke(AuditEvent.AllNodesDead, null); - var node = this.InternalNodes[globalCursor % this.InternalNodes.Count]; + var node = InternalNodes[globalCursor % InternalNodes.Count]; node.IsResurrected = true; audit?.Invoke(AuditEvent.Resurrection, node); @@ -134,12 +132,9 @@ protected virtual IEnumerable SelectAliveNodes(int cursor, List aliv } protected IOrderedEnumerable SortNodes(IEnumerable nodes) => - this._nodeScorer != null + _nodeScorer != null ? nodes.OrderByDescending(_nodeScorer) - : nodes.OrderBy(n => this.Randomize ? this.Random.Next() : 1); - - - void IDisposable.Dispose() => this.DisposeManagedResources(); + : nodes.OrderBy(n => Randomize ? Random.Next() : 1); protected virtual void DisposeManagedResources() { } } diff --git a/src/Elasticsearch.Net/ConnectionPool/StickyConnectionPool.cs b/src/Elasticsearch.Net/ConnectionPool/StickyConnectionPool.cs index e0c54324f94..134e0fb2068 100644 --- a/src/Elasticsearch.Net/ConnectionPool/StickyConnectionPool.cs +++ b/src/Elasticsearch.Net/ConnectionPool/StickyConnectionPool.cs @@ -7,33 +7,32 @@ namespace Elasticsearch.Net public class StickyConnectionPool : StaticConnectionPool { public StickyConnectionPool(IEnumerable uris, IDateTimeProvider dateTimeProvider = null) - : base(uris, false, dateTimeProvider) - { } + : base(uris, false, dateTimeProvider) { } public StickyConnectionPool(IEnumerable nodes, IDateTimeProvider dateTimeProvider = null) - : base(nodes, false, dateTimeProvider) - { } + : base(nodes, false, dateTimeProvider) { } public override IEnumerable CreateView(Action audit = null) { - var nodes = this.AliveNodes; + var nodes = AliveNodes; if (nodes.Count == 0) { - var globalCursor = Interlocked.Increment(ref this.GlobalCursor); + var globalCursor = Interlocked.Increment(ref GlobalCursor); //could not find a suitable node retrying on first node off globalCursor - yield return this.RetryInternalNodes(globalCursor, audit); + yield return RetryInternalNodes(globalCursor, audit); + yield break; } // If the cursor is greater than the default then it's been // set already but we now have a live node so we should reset it - if (this.GlobalCursor > -1) - Interlocked.Exchange(ref this.GlobalCursor, -1); + if (GlobalCursor > -1) + Interlocked.Exchange(ref GlobalCursor, -1); var localCursor = 0; - foreach (var aliveNode in this.SelectAliveNodes(localCursor, nodes, audit)) + foreach (var aliveNode in SelectAliveNodes(localCursor, nodes, audit)) yield return aliveNode; } diff --git a/src/Elasticsearch.Net/ConnectionPool/StickySniffingConnectionPool.cs b/src/Elasticsearch.Net/ConnectionPool/StickySniffingConnectionPool.cs index f243fab61f7..eebe9d560a5 100644 --- a/src/Elasticsearch.Net/ConnectionPool/StickySniffingConnectionPool.cs +++ b/src/Elasticsearch.Net/ConnectionPool/StickySniffingConnectionPool.cs @@ -7,35 +7,36 @@ namespace Elasticsearch.Net { public class StickySniffingConnectionPool : SniffingConnectionPool { - public override bool SupportsPinging => true; - public override bool SupportsReseeding => true; - public StickySniffingConnectionPool(IEnumerable uris, Func nodeScorer, IDateTimeProvider dateTimeProvider = null) : base(uris.Select(uri => new Node(uri)), nodeScorer ?? DefaultNodeScore, dateTimeProvider) { } public StickySniffingConnectionPool(IEnumerable nodes, Func nodeScorer, IDateTimeProvider dateTimeProvider = null) : base(nodes, nodeScorer ?? DefaultNodeScore, dateTimeProvider) { } + public override bool SupportsPinging => true; + public override bool SupportsReseeding => true; + public override IEnumerable CreateView(Action audit = null) { - var nodes = this.AliveNodes; + var nodes = AliveNodes; if (nodes.Count == 0) { - var globalCursor = Interlocked.Increment(ref this.GlobalCursor); + var globalCursor = Interlocked.Increment(ref GlobalCursor); //could not find a suitable node retrying on first node off globalCursor - yield return this.RetryInternalNodes(globalCursor, audit); + yield return RetryInternalNodes(globalCursor, audit); + yield break; } // If the cursor is greater than the default then it's been // set already but we now have a live node so we should reset it - if (this.GlobalCursor > -1) - Interlocked.Exchange(ref this.GlobalCursor, -1); + if (GlobalCursor > -1) + Interlocked.Exchange(ref GlobalCursor, -1); var localCursor = 0; - foreach (var aliveNode in this.SelectAliveNodes(localCursor, nodes, audit)) + foreach (var aliveNode in SelectAliveNodes(localCursor, nodes, audit)) yield return aliveNode; } diff --git a/src/Elasticsearch.Net/CrossPlatform/TypeExtensions.cs b/src/Elasticsearch.Net/CrossPlatform/TypeExtensions.cs index 6a071038273..560e9d47cc0 100644 --- a/src/Elasticsearch.Net/CrossPlatform/TypeExtensions.cs +++ b/src/Elasticsearch.Net/CrossPlatform/TypeExtensions.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Threading.Tasks; namespace Elasticsearch.Net { @@ -25,7 +22,7 @@ internal static bool AssignableFrom(this Type type, Type from) return type.IsAssignableFrom(from); #endif } - + internal static Assembly Assembly(this Type type) { #if DOTNETCORE diff --git a/src/Elasticsearch.Net/Domain/IHideObjectMembers.cs b/src/Elasticsearch.Net/Domain/IHideObjectMembers.cs index ddcaafb47ed..6db4acf4f25 100644 --- a/src/Elasticsearch.Net/Domain/IHideObjectMembers.cs +++ b/src/Elasticsearch.Net/Domain/IHideObjectMembers.cs @@ -6,7 +6,7 @@ namespace Elasticsearch.Net { /// - /// Helper interface used to hide the base members from the fluent API to make it much cleaner + /// Helper interface used to hide the base members from the fluent API to make it much cleaner /// in Visual Studio intellisense. /// /// Created by Daniel Cazzulino http://www.clariusconsulting.net/blogs/kzu/archive/2008/03/10/58301.aspx @@ -15,32 +15,31 @@ namespace Elasticsearch.Net public interface IHideObjectMembers { /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] bool Equals(object obj); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] int GetHashCode(); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] Type GetType(); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] string ToString(); } - } diff --git a/src/Elasticsearch.Net/Domain/RequestParameters/IRequestParameters.cs b/src/Elasticsearch.Net/Domain/RequestParameters/IRequestParameters.cs index c095ef5de01..3463c5bc012 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters/IRequestParameters.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters/IRequestParameters.cs @@ -9,24 +9,24 @@ public interface IRequestParameters HttpMethod DefaultHttpMethod { get; } /// - /// The querystring that should be appended to the path of the request + /// A method that can be set on the request to take ownership of creating the response object. + /// When set this will be called instead of the internal .Deserialize(); /// - Dictionary QueryString { get; set; } + Func DeserializationOverride { get; set; } /// - /// A method that can be set on the request to take ownership of creating the response object. - /// When set this will be called instead of the internal .Deserialize(); + /// The querystring that should be appended to the path of the request /// - Func DeserializationOverride { get; set; } + Dictionary QueryString { get; set; } /// /// Configuration for this specific request, i.e disable sniffing, custom timeouts etcetera. /// IRequestConfiguration RequestConfiguration { get; set; } - /// Sets a query string param. If is null and the parameter exists it will be removed + /// Sets a query string param. If is null and the parameter exists it will be removed /// The query string parameter to add - /// The value to set, if null removes from the query string if it exists + /// The value to set, if null removes from the query string if it exists void SetQueryString(string name, object value); bool ContainsQueryString(string name); diff --git a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Patched.cs b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Patched.cs index 0950f52954b..8966d2ca6f4 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Patched.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Patched.cs @@ -6,6 +6,7 @@ public partial class ForceMergeRequestParameters { [Obsolete("Removed in Elasticsearch 6.2. Will be removed in NEST 7.x. Calling this is a no-op.")] public string OperationThreading { get; set; } + [Obsolete("Removed in Elasticsearch 6.2. Will be removed in NEST 7.x. Calling this is a no-op.")] public bool? WaitForMerge { get; set; } } diff --git a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.cs b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.cs index 72df06e51c4..0cc8d5a7f4d 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.cs @@ -12,46 +12,50 @@ namespace Elasticsearch.Net /// public abstract class RequestParameters : IRequestParameters where T : RequestParameters { - private IRequestParameters Self => this; + public abstract HttpMethod DefaultHttpMethod { get; } public Func DeserializationOverride { get; set; } - public IRequestConfiguration RequestConfiguration { get; set; } - - public abstract HttpMethod DefaultHttpMethod { get; } public Dictionary QueryString { get; set; } = new Dictionary(); + public IRequestConfiguration RequestConfiguration { get; set; } + private IRequestParameters Self => this; - //These exists solely so the generated code can call these shortened methods - protected TOut Q(string name) => this.GetQueryStringValue(name); - protected void Q(string name, object value) => this.SetQueryString(name, value); - - /// - public void SetQueryString(string name, object value) - { - if (value == null) this.RemoveQueryString(name); - else Self.QueryString[name] = value; - } - private void RemoveQueryString(string name) - { - if (!Self.QueryString.ContainsKey(name)) return; - Self.QueryString.Remove(name); - } /// public bool ContainsQueryString(string name) => Self.QueryString != null && Self.QueryString.ContainsKey(name); /// public TOut GetQueryStringValue(string name) { - if (!this.ContainsQueryString(name)) + if (!ContainsQueryString(name)) return default(TOut); + var value = Self.QueryString[name]; if (value == null) return default(TOut); + return (TOut)value; } /// public string GetResolvedQueryStringValue(string n, IConnectionConfigurationValues s) => CreateString(GetQueryStringValue(n), s); - } + /// + public void SetQueryString(string name, object value) + { + if (value == null) RemoveQueryString(name); + else Self.QueryString[name] = value; + } + + //These exists solely so the generated code can call these shortened methods + protected TOut Q(string name) => GetQueryStringValue(name); + + protected void Q(string name, object value) => SetQueryString(name, value); + + private void RemoveQueryString(string name) + { + if (!Self.QueryString.ContainsKey(name)) return; + + Self.QueryString.Remove(name); + } + } } diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.Patched.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.Patched.cs index 097782a0a64..e401fc0b300 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.Patched.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.Patched.cs @@ -7,30 +7,46 @@ namespace Elasticsearch.Net { public partial class ElasticLowLevelClient { - ///GET on /_xpack/migration/deprecations http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html - ///A func that allows you to describe the querystring parameters & request specific connection settings. + /// GET on /_xpack/migration/deprecations + /// http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html + /// + /// A func that allows you to describe the querystring parameters & request specific connection settings. [Obsolete("Use XpackMigrationDeprecations")] public TResponse XpackDeprecationInfo(DeprecationInfoRequestParameters requestParameters = null) - where TResponse : class, IElasticsearchResponse, new() => this.DoRequest(GET, Url($"_xpack/migration/deprecations"), null, _params(requestParameters)); + where TResponse : class, IElasticsearchResponse, new() => + DoRequest(GET, Url($"_xpack/migration/deprecations"), null, _params(requestParameters)); - ///GET on /_xpack/migration/deprecations http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html - ///A func that allows you to describe the querystring parameters & request specific connection settings. - [Obsolete("Use XpackMigrationDeprecationsAsync")] - public Task XpackDeprecationInfoAsync(DeprecationInfoRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) - where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(GET, Url($"_xpack/migration/deprecations"), ctx, null, _params(requestParameters)); - - ///GET on /{index}/_xpack/migration/deprecations http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html - ///Index pattern - ///A func that allows you to describe the querystring parameters & request specific connection settings. + /// GET on /{index}/_xpack/migration/deprecations + /// http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html + /// + /// Index pattern + /// A func that allows you to describe the querystring parameters & request specific connection settings. [Obsolete("Use XpackMigrationDeprecations")] public TResponse XpackDeprecationInfo(string index, DeprecationInfoRequestParameters requestParameters = null) - where TResponse : class, IElasticsearchResponse, new() => this.DoRequest(GET, Url($"{index.NotNull("index")}/_xpack/migration/deprecations"), null, _params(requestParameters)); + where TResponse : class, IElasticsearchResponse, new() => DoRequest(GET, + Url($"{index.NotNull("index")}/_xpack/migration/deprecations"), null, _params(requestParameters)); + + /// GET on /_xpack/migration/deprecations + /// http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html + /// + /// A func that allows you to describe the querystring parameters & request specific connection settings. + [Obsolete("Use XpackMigrationDeprecationsAsync")] + public Task XpackDeprecationInfoAsync(DeprecationInfoRequestParameters requestParameters = null, + CancellationToken ctx = default(CancellationToken) + ) + where TResponse : class, IElasticsearchResponse, new() => + DoRequestAsync(GET, Url($"_xpack/migration/deprecations"), ctx, null, _params(requestParameters)); - ///GET on /{index}/_xpack/migration/deprecations http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html - ///Index pattern - ///A func that allows you to describe the querystring parameters & request specific connection settings. + /// GET on /{index}/_xpack/migration/deprecations + /// http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html + /// + /// Index pattern + /// A func that allows you to describe the querystring parameters & request specific connection settings. [Obsolete("Use XpackMigrationDeprecationsAsync")] - public Task XpackDeprecationInfoAsync(string index, DeprecationInfoRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) - where TResponse : class, IElasticsearchResponse, new() => this.DoRequestAsync(GET, Url($"{index.NotNull("index")}/_xpack/migration/deprecations"), ctx, null, _params(requestParameters)); + public Task XpackDeprecationInfoAsync(string index, DeprecationInfoRequestParameters requestParameters = null, + CancellationToken ctx = default(CancellationToken) + ) + where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync(GET, + Url($"{index.NotNull("index")}/_xpack/migration/deprecations"), ctx, null, _params(requestParameters)); } } diff --git a/src/Elasticsearch.Net/ElasticLowLevelClient.cs b/src/Elasticsearch.Net/ElasticLowLevelClient.cs index c8999297cfd..07dcf2e0342 100644 --- a/src/Elasticsearch.Net/ElasticLowLevelClient.cs +++ b/src/Elasticsearch.Net/ElasticLowLevelClient.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; @@ -11,18 +12,14 @@ public partial class ElasticLowLevelClient : IElasticLowLevelClient { private readonly ElasticsearchUrlFormatter _formatter; - public IConnectionConfigurationValues Settings => this.Transport.Settings; - public IElasticsearchSerializer Serializer => this.Transport.Settings.RequestResponseSerializer; - - protected ITransport Transport { get; set; } - /// Instantiate a new low level elasticsearch client to http://localhost:9200 - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] public ElasticLowLevelClient() : this(new Transport(new ConnectionConfiguration())) { } /// Instantiate a new low level elasticsearch client using the specified settings - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] - public ElasticLowLevelClient(IConnectionConfigurationValues settings) : this(new Transport(settings ?? new ConnectionConfiguration())) { } + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] + public ElasticLowLevelClient(IConnectionConfigurationValues settings) : this( + new Transport(settings ?? new ConnectionConfiguration())) { } /// /// Instantiate a new low level elasticsearch client explicitly specifying a custom transport setup @@ -33,10 +30,26 @@ public ElasticLowLevelClient(ITransport transpor transport.Settings.ThrowIfNull(nameof(transport.Settings)); transport.Settings.RequestResponseSerializer.ThrowIfNull(nameof(transport.Settings.RequestResponseSerializer)); - this.Transport = transport; - this._formatter = this.Transport.Settings.UrlFormatter; + Transport = transport; + _formatter = Transport.Settings.UrlFormatter; } + public IElasticsearchSerializer Serializer => Transport.Settings.RequestResponseSerializer; + + public IConnectionConfigurationValues Settings => Transport.Settings; + + protected ITransport Transport { get; set; } + + public TResponse DoRequest(HttpMethod method, string path, PostData data = null, IRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new() => + Transport.Request(method, path, data, requestParameters); + + public Task DoRequestAsync(HttpMethod method, string path, CancellationToken cancellationToken, PostData data = null, + IRequestParameters requestParameters = null + ) + where TResponse : class, IElasticsearchResponse, new() => + Transport.RequestAsync(method, path, cancellationToken, data, requestParameters); + private string Url(FormattableString formattable) => formattable.ToString(_formatter); private TRequestParams _params(TRequestParams requestParams, string contentType = null, string accept = null) @@ -47,20 +60,13 @@ private TRequestParams _params(TRequestParams requestParams, str requestParams = requestParams ?? new TRequestParams(); //The properties are set here on RequestConfiguration here because they are not nullable (fixed in master). if (requestParams.RequestConfiguration == null) - requestParams.RequestConfiguration = new RequestConfiguration { EnableHttpPipelining = Settings.HttpPipeliningEnabled, ThrowExceptions = Settings.ThrowExceptions }; + requestParams.RequestConfiguration = new RequestConfiguration + { EnableHttpPipelining = Settings.HttpPipeliningEnabled, ThrowExceptions = Settings.ThrowExceptions }; if (!contentType.IsNullOrEmpty() && requestParams.RequestConfiguration.ContentType.IsNullOrEmpty()) requestParams.RequestConfiguration.ContentType = contentType; if (!accept.IsNullOrEmpty() && requestParams.RequestConfiguration.Accept.IsNullOrEmpty()) requestParams.RequestConfiguration.Accept = accept; return requestParams; } - - public TResponse DoRequest(HttpMethod method, string path, PostData data = null, IRequestParameters requestParameters = null) - where TResponse : class, IElasticsearchResponse, new() => - this.Transport.Request(method, path, data, requestParameters); - - public Task DoRequestAsync(HttpMethod method, string path, CancellationToken cancellationToken, PostData data = null, IRequestParameters requestParameters = null) - where TResponse : class, IElasticsearchResponse, new() => - this.Transport.RequestAsync(method, path, cancellationToken, data, requestParameters); } } diff --git a/src/Elasticsearch.Net/Exceptions/ElasticsearchClientException.cs b/src/Elasticsearch.Net/Exceptions/ElasticsearchClientException.cs index 4ec7ed8d282..fdc39731964 100644 --- a/src/Elasticsearch.Net/Exceptions/ElasticsearchClientException.cs +++ b/src/Elasticsearch.Net/Exceptions/ElasticsearchClientException.cs @@ -7,24 +7,10 @@ namespace Elasticsearch.Net { public class ElasticsearchClientException : Exception { - public PipelineFailure? FailureReason { get; } - - public RequestData Request { get; internal set; } - - public IApiCallDetails Response { get; internal set; } - - public List AuditTrail { get; internal set; } - - public ElasticsearchClientException(string message) : base(message) - { - this.FailureReason = PipelineFailure.Unexpected; - } + public ElasticsearchClientException(string message) : base(message) => FailureReason = PipelineFailure.Unexpected; public ElasticsearchClientException(PipelineFailure failure, string message, Exception innerException) - : base(message, innerException) - { - FailureReason = failure; - } + : base(message, innerException) => FailureReason = failure; public ElasticsearchClientException(PipelineFailure failure, string message, IApiCallDetails apiCall) : this(message) @@ -34,25 +20,27 @@ public ElasticsearchClientException(PipelineFailure failure, string message, IAp AuditTrail = apiCall?.AuditTrail; } + public List AuditTrail { get; internal set; } + public string DebugInformation { get { var sb = new StringBuilder(); var failureReason = FailureReason.GetStringValue(); - if (this.FailureReason == PipelineFailure.Unexpected && (this.AuditTrail.HasAny())) - { - failureReason = "Unrecoverable/Unexpected " + this.AuditTrail.Last().Event.GetStringValue(); - } - var path = Request.Uri != null ? Request.Uri.ToString() : Request.PathAndQuery + " on an empty node, likely a node predicate on ConnectionSettings not matching ANY nodes"; + if (FailureReason == PipelineFailure.Unexpected && AuditTrail.HasAny()) + failureReason = "Unrecoverable/Unexpected " + AuditTrail.Last().Event.GetStringValue(); + var path = Request.Uri != null + ? Request.Uri.ToString() + : Request.PathAndQuery + " on an empty node, likely a node predicate on ConnectionSettings not matching ANY nodes"; sb.AppendLine($"# FailureReason: {failureReason} while attempting {Request.Method.GetStringValue()} on {path}"); - if (this.Response != null) - ResponseStatics.DebugInformationBuilder(this.Response, sb); + if (Response != null) + ResponseStatics.DebugInformationBuilder(Response, sb); else { - ResponseStatics.DebugAuditTrail(this.AuditTrail, sb); - ResponseStatics.DebugAuditTrailExceptions(this.AuditTrail, sb); + ResponseStatics.DebugAuditTrail(AuditTrail, sb); + ResponseStatics.DebugAuditTrailExceptions(AuditTrail, sb); } if (InnerException != null) { @@ -60,11 +48,16 @@ public string DebugInformation sb.AppendLine(InnerException.ToString()); } sb.AppendLine($"# Exception:"); - sb.AppendLine(this.ToString()); + sb.AppendLine(ToString()); return sb.ToString(); } } + public PipelineFailure? FailureReason { get; } + + public RequestData Request { get; internal set; } + + public IApiCallDetails Response { get; internal set; } } } diff --git a/src/Elasticsearch.Net/Exceptions/UnexpectedElasticsearchClientException.cs b/src/Elasticsearch.Net/Exceptions/UnexpectedElasticsearchClientException.cs index 9b4ead04f80..b2a799b4a18 100644 --- a/src/Elasticsearch.Net/Exceptions/UnexpectedElasticsearchClientException.cs +++ b/src/Elasticsearch.Net/Exceptions/UnexpectedElasticsearchClientException.cs @@ -5,12 +5,10 @@ namespace Elasticsearch.Net { public class UnexpectedElasticsearchClientException : ElasticsearchClientException { - public List SeenExceptions { get; set; } - public UnexpectedElasticsearchClientException(Exception killerException, List seenExceptions) - : base(PipelineFailure.Unexpected, killerException?.Message ?? "An unexpected exception occurred.", killerException) - { - this.SeenExceptions = seenExceptions; - } + : base(PipelineFailure.Unexpected, killerException?.Message ?? "An unexpected exception occurred.", killerException) => + SeenExceptions = seenExceptions; + + public List SeenExceptions { get; set; } } } diff --git a/src/Elasticsearch.Net/Extensions/EnumExtensions.cs b/src/Elasticsearch.Net/Extensions/EnumExtensions.cs index 58cb4dec1aa..3eca9eec8e7 100644 --- a/src/Elasticsearch.Net/Extensions/EnumExtensions.cs +++ b/src/Elasticsearch.Net/Extensions/EnumExtensions.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Elasticsearch.Net { diff --git a/src/Elasticsearch.Net/Extensions/Extensions.cs b/src/Elasticsearch.Net/Extensions/Extensions.cs index f8e9d5e24a0..00f0329c811 100644 --- a/src/Elasticsearch.Net/Extensions/Extensions.cs +++ b/src/Elasticsearch.Net/Extensions/Extensions.cs @@ -14,10 +14,7 @@ internal static class Extensions internal static string Utf8String(this byte[] bytes) => bytes == null ? null : Encoding.UTF8.GetString(bytes, 0, bytes.Length); #endif - internal static byte[] Utf8Bytes(this string s) - { - return s.IsNullOrEmpty() ? null : Encoding.UTF8.GetBytes(s); - } + internal static byte[] Utf8Bytes(this string s) => s.IsNullOrEmpty() ? null : Encoding.UTF8.GetBytes(s); internal static string ToCamelCase(this string s) { @@ -27,7 +24,7 @@ internal static string ToCamelCase(this string s) if (!char.IsUpper(s[0])) return s; - string camelCase = char.ToLowerInvariant(s[0]).ToString(); + var camelCase = char.ToLowerInvariant(s[0]).ToString(); if (s.Length > 1) camelCase += s.Substring(1); @@ -39,6 +36,7 @@ internal static string NotNull(this string @object, string parameterName) @object.ThrowIfNull(parameterName); if (string.IsNullOrWhiteSpace(@object)) throw new ArgumentException("String argument is empty", parameterName); + return @object; } @@ -54,15 +52,14 @@ internal static void ThrowIfEmpty(this IEnumerable @object, string paramet if (!@object.Any()) throw new ArgumentException("Argument can not be an empty collection", parameterName); } - internal static bool HasAny(this IEnumerable list) - { - return list != null && list.Any(); - } + + internal static bool HasAny(this IEnumerable list) => list != null && list.Any(); internal static Exception AsAggregateOrFirst(this IEnumerable exceptions) { - var es= exceptions as Exception[] ?? exceptions?.ToArray(); + var es = exceptions as Exception[] ?? exceptions?.ToArray(); if (es == null || es.Length == 0) return null; + return es.Length == 1 ? es[0] : new AggregateException(es); } @@ -71,15 +68,11 @@ internal static void ThrowIfNull(this T value, string name) if (value == null) throw new ArgumentNullException(name); } - internal static bool IsNullOrEmpty(this string value) - { - return string.IsNullOrEmpty(value); - } - internal static IEnumerable DistinctBy(this IEnumerable items, Func property) - { - return items.GroupBy(property).Select(x => x.First()); - } + internal static bool IsNullOrEmpty(this string value) => string.IsNullOrEmpty(value); + + internal static IEnumerable DistinctBy(this IEnumerable items, Func property) => + items.GroupBy(property).Select(x => x.First()); private static readonly long _week = (long)TimeSpan.FromDays(7).TotalMilliseconds; private static readonly long _day = (long)TimeSpan.FromDays(1).TotalMilliseconds; @@ -126,6 +119,5 @@ internal static string ToTimeUnit(this TimeSpan timeSpan) return factor.ToString("0.##", CultureInfo.InvariantCulture) + interval; } - } } diff --git a/src/Elasticsearch.Net/Extensions/Fluent.cs b/src/Elasticsearch.Net/Extensions/Fluent.cs index 4ca8e2e7a6c..0387c501335 100644 --- a/src/Elasticsearch.Net/Extensions/Fluent.cs +++ b/src/Elasticsearch.Net/Extensions/Fluent.cs @@ -11,5 +11,4 @@ internal static TDescriptor Assign(TDescriptor self, Ac return self; } } - -} \ No newline at end of file +} diff --git a/src/Elasticsearch.Net/Extensions/TypeExtensions.cs b/src/Elasticsearch.Net/Extensions/TypeExtensions.cs index 9ea0a809368..32d4411e0bd 100644 --- a/src/Elasticsearch.Net/Extensions/TypeExtensions.cs +++ b/src/Elasticsearch.Net/Extensions/TypeExtensions.cs @@ -16,7 +16,8 @@ internal static class TypeExtensions private static readonly ConcurrentDictionary> CachedActivators = new ConcurrentDictionary>(); - internal static T CreateInstance(this Type t, params object[] args) => (T) t.CreateInstance(args); + + internal static T CreateInstance(this Type t, params object[] args) => (T)t.CreateInstance(args); internal static object CreateInstance(this Type t, params object[] args) { @@ -27,18 +28,20 @@ internal static object CreateInstance(this Type t, params object[] args) var generic = GetActivatorMethodInfo.MakeGenericMethod(t); var constructors = from c in t.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) - let p = c.GetParameters() - let k = string.Join(",", p.Select(a => a.ParameterType.Name)) - where p.Length == args.Length - select c; + let p = c.GetParameters() + let k = string.Join(",", p.Select(a => a.ParameterType.Name)) + where p.Length == args.Length + select c; var ctor = constructors.FirstOrDefault(); if (ctor == null) throw new Exception($"Cannot create an instance of {t.FullName} because it has no constructor taking {args.Length} arguments"); - activator = (ObjectActivator) generic.Invoke(null, new[] {ctor}); + + activator = (ObjectActivator)generic.Invoke(null, new[] { ctor }); CachedActivators.TryAdd(key, activator); return activator(args); } + internal static bool IsValueType(this Type type) { #if DOTNETCORE @@ -61,7 +64,7 @@ private static ObjectActivator GetActivator(ConstructorInfo ctor) //pick each arg from the params array //and create a typed expression of them - for (int i = 0; i < paramsInfo.Length; i++) + for (var i = 0; i < paramsInfo.Length; i++) { var index = Expression.Constant(i); var paramType = paramsInfo[i].ParameterType; @@ -82,7 +85,7 @@ private static ObjectActivator GetActivator(ConstructorInfo ctor) var lambda = Expression.Lambda(typeof(ObjectActivator), newExp, param); //compile it - var compiled = (ObjectActivator) lambda.Compile(); + var compiled = (ObjectActivator)lambda.Compile(); return compiled; } } diff --git a/src/Elasticsearch.Net/Extensions/X509CertificateExtensions.cs b/src/Elasticsearch.Net/Extensions/X509CertificateExtensions.cs index 7e14e1e292a..8501764507c 100644 --- a/src/Elasticsearch.Net/Extensions/X509CertificateExtensions.cs +++ b/src/Elasticsearch.Net/Extensions/X509CertificateExtensions.cs @@ -1,4 +1,6 @@ -using System.Security.Cryptography.X509Certificates; +#if DOTNETCORE +using System.Security.Cryptography.X509Certificates; +#endif namespace Elasticsearch.Net { @@ -35,6 +37,5 @@ private static string EncodeHexString(byte[] sArray) } #endif - } } diff --git a/src/Elasticsearch.Net/GlobalSuppressions.cs b/src/Elasticsearch.Net/GlobalSuppressions.cs index 8dac84cb514..9acff261cb6 100644 Binary files a/src/Elasticsearch.Net/GlobalSuppressions.cs and b/src/Elasticsearch.Net/GlobalSuppressions.cs differ diff --git a/src/Elasticsearch.Net/IElasticLowLevelClient.Patched.cs b/src/Elasticsearch.Net/IElasticLowLevelClient.Patched.cs index ee8d54c5ffc..cf13493a0da 100644 --- a/src/Elasticsearch.Net/IElasticLowLevelClient.Patched.cs +++ b/src/Elasticsearch.Net/IElasticLowLevelClient.Patched.cs @@ -6,26 +6,40 @@ namespace Elasticsearch.Net { public partial interface IElasticLowLevelClient { - ///GET on /_xpack/migration/deprecations http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html - ///A func that allows you to describe the querystring parameters & request specific connection settings. + /// GET on /_xpack/migration/deprecations + /// http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html + /// + /// A func that allows you to describe the querystring parameters & request specific connection settings. [Obsolete("Use XpackMigrationDeprecations")] - TResponse XpackDeprecationInfo(DeprecationInfoRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); + TResponse XpackDeprecationInfo(DeprecationInfoRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new(); - ///GET on /_xpack/migration/deprecations http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html - ///A func that allows you to describe the querystring parameters & request specific connection settings. + /// GET on /_xpack/migration/deprecations + /// http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html + /// + /// A func that allows you to describe the querystring parameters & request specific connection settings. [Obsolete("Use XpackMigrationDeprecationsAsync")] - Task XpackDeprecationInfoAsync(DeprecationInfoRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); + Task XpackDeprecationInfoAsync(DeprecationInfoRequestParameters requestParameters = null, + CancellationToken ctx = default(CancellationToken) + ) where TResponse : class, IElasticsearchResponse, new(); - ///GET on /{index}/_xpack/migration/deprecations http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html - ///Index pattern - ///A func that allows you to describe the querystring parameters & request specific connection settings. + /// GET on /{index}/_xpack/migration/deprecations + /// http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html + /// + /// Index pattern + /// A func that allows you to describe the querystring parameters & request specific connection settings. [Obsolete("Use XpackMigrationDeprecations")] - TResponse XpackDeprecationInfo(string index, DeprecationInfoRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new(); + TResponse XpackDeprecationInfo(string index, DeprecationInfoRequestParameters requestParameters = null) + where TResponse : class, IElasticsearchResponse, new(); - ///GET on /{index}/_xpack/migration/deprecations http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html - ///Index pattern - ///A func that allows you to describe the querystring parameters & request specific connection settings. + /// GET on /{index}/_xpack/migration/deprecations + /// http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html + /// + /// Index pattern + /// A func that allows you to describe the querystring parameters & request specific connection settings. [Obsolete("Use XpackMigrationDeprecationsAsync")] - Task XpackDeprecationInfoAsync(string index, DeprecationInfoRequestParameters requestParameters = null, CancellationToken ctx = default(CancellationToken)) where TResponse : class, IElasticsearchResponse, new(); + Task XpackDeprecationInfoAsync(string index, DeprecationInfoRequestParameters requestParameters = null, + CancellationToken ctx = default(CancellationToken) + ) where TResponse : class, IElasticsearchResponse, new(); } } diff --git a/src/Elasticsearch.Net/IElasticLowLevelClient.cs b/src/Elasticsearch.Net/IElasticLowLevelClient.cs index 203a4081b64..d1ee69d5984 100644 --- a/src/Elasticsearch.Net/IElasticLowLevelClient.cs +++ b/src/Elasticsearch.Net/IElasticLowLevelClient.cs @@ -26,7 +26,9 @@ TResponse DoRequest(HttpMethod method, string path, PostData data = n /// The body of the request, string and byte[] are posted as is other types will be serialized to JSON /// Optionally configure request specific timeouts, headers /// A task of ElasticsearchResponse of T where T represents the JSON response body - Task DoRequestAsync(HttpMethod method, string path, CancellationToken cancellationToken, PostData data = null, IRequestParameters requestParameters = null) + Task DoRequestAsync(HttpMethod method, string path, CancellationToken cancellationToken, PostData data = null, + IRequestParameters requestParameters = null + ) where TResponse : class, IElasticsearchResponse, new(); } } diff --git a/src/Elasticsearch.Net/Properties/ClsCompliancy.cs b/src/Elasticsearch.Net/Properties/ClsCompliancy.cs index 6139b4fad9e..8c114539a19 100644 --- a/src/Elasticsearch.Net/Properties/ClsCompliancy.cs +++ b/src/Elasticsearch.Net/Properties/ClsCompliancy.cs @@ -1,4 +1,3 @@ using System; [assembly: CLSCompliant(true)] - diff --git a/src/Elasticsearch.Net/Providers/DateTimeProvider.cs b/src/Elasticsearch.Net/Providers/DateTimeProvider.cs index 3e586f0b59b..32321bc45ff 100644 --- a/src/Elasticsearch.Net/Providers/DateTimeProvider.cs +++ b/src/Elasticsearch.Net/Providers/DateTimeProvider.cs @@ -4,13 +4,10 @@ namespace Elasticsearch.Net { public class DateTimeProvider : IDateTimeProvider { + public static readonly DateTimeProvider Default = new DateTimeProvider(); private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(60); private static readonly TimeSpan MaximumTimeout = TimeSpan.FromMinutes(30); - public static readonly DateTimeProvider Default = new DateTimeProvider(); - - public virtual DateTime Now() => DateTime.UtcNow; - public virtual DateTime DeadTime(int attempts, TimeSpan? timeoutFactor, TimeSpan? maxDeadTimeout) { var timeout = timeoutFactor.GetValueOrDefault(DefaultTimeout); @@ -18,5 +15,7 @@ public virtual DateTime DeadTime(int attempts, TimeSpan? timeoutFactor, TimeSpan var milliSeconds = Math.Min(timeout.TotalMilliseconds * 2 * Math.Pow(2, attempts * 0.5 - 1), maxTimeout.TotalMilliseconds); return Now().AddMilliseconds(milliSeconds); } + + public virtual DateTime Now() => DateTime.UtcNow; } -} \ No newline at end of file +} diff --git a/src/Elasticsearch.Net/Providers/IDateTimeProvider.cs b/src/Elasticsearch.Net/Providers/IDateTimeProvider.cs index 12b66b33df3..dbf3b601d6e 100644 --- a/src/Elasticsearch.Net/Providers/IDateTimeProvider.cs +++ b/src/Elasticsearch.Net/Providers/IDateTimeProvider.cs @@ -5,6 +5,7 @@ namespace Elasticsearch.Net public interface IDateTimeProvider { DateTime Now(); + DateTime DeadTime(int attempts, TimeSpan? timeoutFactor, TimeSpan? maxDeadTimeout); } -} \ No newline at end of file +} diff --git a/src/Elasticsearch.Net/Providers/IRequestPipelineFactory.cs b/src/Elasticsearch.Net/Providers/IRequestPipelineFactory.cs index f5fb12df976..39c92bcfb58 100644 --- a/src/Elasticsearch.Net/Providers/IRequestPipelineFactory.cs +++ b/src/Elasticsearch.Net/Providers/IRequestPipelineFactory.cs @@ -2,12 +2,16 @@ { public interface IRequestPipelineFactory { - IRequestPipeline Create(IConnectionConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider, IMemoryStreamFactory memorystreamFactory, IRequestParameters requestParameters); + IRequestPipeline Create(IConnectionConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider, + IMemoryStreamFactory memorystreamFactory, IRequestParameters requestParameters + ); } public class RequestPipelineFactory : IRequestPipelineFactory { - public IRequestPipeline Create(IConnectionConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider, IMemoryStreamFactory memorystreamFactory, IRequestParameters requestParameters) => + public IRequestPipeline Create(IConnectionConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider, + IMemoryStreamFactory memorystreamFactory, IRequestParameters requestParameters + ) => new RequestPipeline(configurationValues, dateTimeProvider, memorystreamFactory, requestParameters); - } -} \ No newline at end of file + } +} diff --git a/src/Elasticsearch.Net/Providers/MemoryStreamFactory.cs b/src/Elasticsearch.Net/Providers/MemoryStreamFactory.cs index 7b6c8d0d2da..c5a0254f572 100644 --- a/src/Elasticsearch.Net/Providers/MemoryStreamFactory.cs +++ b/src/Elasticsearch.Net/Providers/MemoryStreamFactory.cs @@ -3,17 +3,17 @@ namespace Elasticsearch.Net { /// - /// A factory for creating memory streams using instances of + /// A factory for creating memory streams using instances of /// public class MemoryStreamFactory : IMemoryStreamFactory { /// - /// Creates a memory stream using + /// Creates a memory stream using /// public MemoryStream Create() => new MemoryStream(); /// - /// Creates a memory stream using with the bytes written to the stream + /// Creates a memory stream using with the bytes written to the stream /// public MemoryStream Create(byte[] bytes) => new MemoryStream(bytes); } diff --git a/src/Elasticsearch.Net/Providers/RecyclableMemoryStream.cs b/src/Elasticsearch.Net/Providers/RecyclableMemoryStream.cs index 7a37bcef3b1..3032e3cee89 100644 --- a/src/Elasticsearch.Net/Providers/RecyclableMemoryStream.cs +++ b/src/Elasticsearch.Net/Providers/RecyclableMemoryStream.cs @@ -32,33 +32,29 @@ namespace Elasticsearch.Net { /// - /// MemoryStream implementation that deals with pooling and managing memory streams which use potentially large - /// buffers. + /// MemoryStream implementation that deals with pooling and managing memory streams which use potentially large + /// buffers. /// /// - /// This class works in tandem with the RecylableMemoryStreamManager to supply MemoryStream - /// objects to callers, while avoiding these specific problems: - /// 1. LOH allocations - since all large buffers are pooled, they will never incur a Gen2 GC - /// 2. Memory waste - A standard memory stream doubles its size when it runs out of room. This - /// leads to continual memory growth as each stream approaches the maximum allowed size. - /// 3. Memory copying - Each time a MemoryStream grows, all the bytes are copied into new buffers. - /// This implementation only copies the bytes when GetBuffer is called. - /// 4. Memory fragmentation - By using homogeneous buffer sizes, it ensures that blocks of memory - /// can be easily reused. - /// - /// The stream is implemented on top of a series of uniformly-sized blocks. As the stream's length grows, - /// additional blocks are retrieved from the memory manager. It is these blocks that are pooled, not the stream - /// object itself. - /// - /// The biggest wrinkle in this implementation is when GetBuffer() is called. This requires a single - /// contiguous buffer. If only a single block is in use, then that block is returned. If multiple blocks - /// are in use, we retrieve a larger buffer from the memory manager. These large buffers are also pooled, - /// split by size--they are multiples of a chunk size (1 MB by default). - /// - /// Once a large buffer is assigned to the stream the blocks are NEVER again used for this stream. All operations take place on the - /// large buffer. The large buffer can be replaced by a larger buffer from the pool as needed. All blocks and large buffers - /// are maintained in the stream until the stream is disposed (unless AggressiveBufferReturn is enabled in the stream manager). - /// + /// This class works in tandem with the RecylableMemoryStreamManager to supply MemoryStream + /// objects to callers, while avoiding these specific problems: + /// 1. LOH allocations - since all large buffers are pooled, they will never incur a Gen2 GC + /// 2. Memory waste - A standard memory stream doubles its size when it runs out of room. This + /// leads to continual memory growth as each stream approaches the maximum allowed size. + /// 3. Memory copying - Each time a MemoryStream grows, all the bytes are copied into new buffers. + /// This implementation only copies the bytes when GetBuffer is called. + /// 4. Memory fragmentation - By using homogeneous buffer sizes, it ensures that blocks of memory + /// can be easily reused. + /// The stream is implemented on top of a series of uniformly-sized blocks. As the stream's length grows, + /// additional blocks are retrieved from the memory manager. It is these blocks that are pooled, not the stream + /// object itself. + /// The biggest wrinkle in this implementation is when GetBuffer() is called. This requires a single + /// contiguous buffer. If only a single block is in use, then that block is returned. If multiple blocks + /// are in use, we retrieve a larger buffer from the memory manager. These large buffers are also pooled, + /// split by size--they are multiples of a chunk size (1 MB by default). + /// Once a large buffer is assigned to the stream the blocks are NEVER again used for this stream. All operations take place on the + /// large buffer. The large buffer can be replaced by a larger buffer from the pool as needed. All blocks and large buffers + /// are maintained in the stream until the stream is disposed (unless AggressiveBufferReturn is enabled in the stream manager). /// internal class RecyclableMemoryStream : MemoryStream { @@ -91,51 +87,16 @@ internal class RecyclableMemoryStream : MemoryStream /// This is only set by GetBuffer() if the necessary buffer is larger than a single block size, or on /// construction if the caller immediately requests a single large buffer. /// - /// If this field is non-null, it contains the concatenation of the bytes found in the individual + /// + /// If this field is non-null, it contains the concatenation of the bytes found in the individual /// blocks. Once it is created, this (or a larger) largeBuffer will be used for the life of the stream. /// private byte[] _largeBuffer; - /// - /// Unique identifier for this stream across it's entire lifetime - /// - /// Object has been disposed - internal Guid Id - { - get - { - this.CheckDisposed(); - return this._id; - } - } - - /// - /// A temporary identifier for the current usage of this stream. - /// - /// Object has been disposed - internal string Tag - { - get - { - this.CheckDisposed(); - return this._tag; - } - } + private int length; - /// - /// Gets the memory manager being used by this stream. - /// - /// Object has been disposed - internal RecyclableMemoryStreamManager MemoryManager - { - get - { - this.CheckDisposed(); - return this._memoryManager; - } - } + private int position; - #region Constructors /// /// Allocate a new RecyclableMemoryStream object. /// @@ -166,101 +127,52 @@ public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, strin /// The memory manager /// A string identifying this stream for logging and debugging purposes /// The initial requested size to prevent future allocations - /// An initial buffer to use. This buffer will be owned by the stream and returned to the memory manager upon Dispose. + /// + /// An initial buffer to use. This buffer will be owned by the stream and returned to the memory manager upon + /// Dispose. + /// internal RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string tag, int requestedSize, - byte[] initialLargeBuffer) + byte[] initialLargeBuffer + ) : base(EmptyArray) { - this._memoryManager = memoryManager; - this._id = Guid.NewGuid(); - this._tag = tag; + _memoryManager = memoryManager; + _id = Guid.NewGuid(); + _tag = tag; - if (requestedSize < memoryManager.BlockSize) - { - requestedSize = memoryManager.BlockSize; - } + if (requestedSize < memoryManager.BlockSize) requestedSize = memoryManager.BlockSize; if (initialLargeBuffer == null) - { - this.EnsureCapacity(requestedSize); - } + EnsureCapacity(requestedSize); else - { - this._largeBuffer = initialLargeBuffer; - } - } - #endregion - - #region Dispose and Finalize - ~RecyclableMemoryStream() - { - this.Dispose(false); + _largeBuffer = initialLargeBuffer; } /// - /// Returns the memory used by this stream back to the pool. + /// Whether the stream can currently read /// - /// Whether we're disposing (true), or being called by the finalizer (false) - [SuppressMessage("Microsoft.Usage", "CA1816:CallGCSuppressFinalizeCorrectly", - Justification = "We have different disposal semantics, so SuppressFinalize is in a different spot.")] - protected override void Dispose(bool disposing) - { - if (Interlocked.CompareExchange(ref this._disposedState, 1, 0) != 0) - { - return; - } + public override bool CanRead => !Disposed; - if (disposing) - { - GC.SuppressFinalize(this); - } - else - { -#if !DOTNETCORE - if (AppDomain.CurrentDomain.IsFinalizingForUnload()) - { - // If we're being finalized because of a shutdown, don't go any further. - // We have no idea what's already been cleaned up. Triggering events may cause - // a crash. - base.Dispose(disposing); - return; - } -#endif - } - - if (this._largeBuffer != null) - { - this._memoryManager.ReturnLargeBuffer(this._largeBuffer, this._tag); - } - - if (this._dirtyBuffers != null) - { - foreach (var buffer in this._dirtyBuffers) - { - this._memoryManager.ReturnLargeBuffer(buffer, this._tag); - } - } - - this._memoryManager.ReturnBlocks(this._blocks, this._tag); - this._blocks.Clear(); + /// + /// Whether the stream can currently seek + /// + public override bool CanSeek => !Disposed; - base.Dispose(disposing); - } + /// + /// Always false + /// + public override bool CanTimeout => false; /// - /// Equivalent to Dispose + /// Whether the stream can currently write /// - public override void Close() - { - this.Dispose(true); - } - #endregion + public override bool CanWrite => !Disposed; - #region MemoryStream overrides /// /// Gets or sets the capacity /// - /// Capacity is always in multiples of the memory manager's block size, unless + /// + /// Capacity is always in multiples of the memory manager's block size, unless /// the large buffer is in use. Capacity never decreases during a stream's lifetime. /// Explicitly setting the capacity to a lower value than the current value will have no effect. /// This is because the buffers are all pooled by chunks and there's little reason to @@ -271,24 +183,19 @@ public override int Capacity { get { - this.CheckDisposed(); - if (this._largeBuffer != null) - { - return this._largeBuffer.Length; - } + CheckDisposed(); + if (_largeBuffer != null) return _largeBuffer.Length; - long size = (long)this._blocks.Count * this._memoryManager.BlockSize; + var size = (long)_blocks.Count * _memoryManager.BlockSize; return (int)Math.Min(int.MaxValue, size); } set { - this.CheckDisposed(); - this.EnsureCapacity(value); + CheckDisposed(); + EnsureCapacity(value); } } - private int length; - /// /// Gets the number of bytes written to this stream. /// @@ -297,13 +204,11 @@ public override long Length { get { - this.CheckDisposed(); - return this.length; + CheckDisposed(); + return length; } } - private int position; - /// /// Gets the current position in the stream /// @@ -312,86 +217,142 @@ public override long Position { get { - this.CheckDisposed(); - return this.position; + CheckDisposed(); + return position; } set { - this.CheckDisposed(); - if (value < 0) - { - throw new ArgumentOutOfRangeException("value", "value must be non-negative"); - } + CheckDisposed(); + if (value < 0) throw new ArgumentOutOfRangeException("value", "value must be non-negative"); - if (value > MaxStreamLength) - { - throw new ArgumentOutOfRangeException("value", "value cannot be more than " + MaxStreamLength); - } + if (value > MaxStreamLength) throw new ArgumentOutOfRangeException("value", "value cannot be more than " + MaxStreamLength); - this.position = (int)value; + position = (int)value; } } /// - /// Whether the stream can currently read + /// Unique identifier for this stream across it's entire lifetime /// - public override bool CanRead => !this.Disposed; + /// Object has been disposed + internal Guid Id + { + get + { + CheckDisposed(); + return _id; + } + } /// - /// Whether the stream can currently seek + /// Gets the memory manager being used by this stream. /// - public override bool CanSeek => !this.Disposed; + /// Object has been disposed + internal RecyclableMemoryStreamManager MemoryManager + { + get + { + CheckDisposed(); + return _memoryManager; + } + } /// - /// Always false + /// A temporary identifier for the current usage of this stream. /// - public override bool CanTimeout => false; + /// Object has been disposed + internal string Tag + { + get + { + CheckDisposed(); + return _tag; + } + } + + private bool Disposed => Interlocked.Read(ref _disposedState) != 0; + + ~RecyclableMemoryStream() => Dispose(false); /// - /// Whether the stream can currently write + /// Returns the memory used by this stream back to the pool. + /// + /// Whether we're disposing (true), or being called by the finalizer (false) + [SuppressMessage("Microsoft.Usage", "CA1816:CallGCSuppressFinalizeCorrectly", + Justification = "We have different disposal semantics, so SuppressFinalize is in a different spot.")] + protected override void Dispose(bool disposing) + { + if (Interlocked.CompareExchange(ref _disposedState, 1, 0) != 0) return; + + if (disposing) + GC.SuppressFinalize(this); + else + { +#if !DOTNETCORE + if (AppDomain.CurrentDomain.IsFinalizingForUnload()) + { + // If we're being finalized because of a shutdown, don't go any further. + // We have no idea what's already been cleaned up. Triggering events may cause + // a crash. + base.Dispose(disposing); + return; + } +#endif + } + + if (_largeBuffer != null) _memoryManager.ReturnLargeBuffer(_largeBuffer, _tag); + + if (_dirtyBuffers != null) + foreach (var buffer in _dirtyBuffers) + _memoryManager.ReturnLargeBuffer(buffer, _tag); + + _memoryManager.ReturnBlocks(_blocks, _tag); + _blocks.Clear(); + + base.Dispose(disposing); + } + + /// + /// Equivalent to Dispose /// - public override bool CanWrite => !this.Disposed; + public override void Close() => Dispose(true); /// /// Returns a single buffer containing the contents of the stream. /// The buffer may be longer than the stream length. /// /// A byte[] buffer - /// IMPORTANT: Doing a Write() after calling GetBuffer() invalidates the buffer. The old buffer is held onto - /// until Dispose is called, but the next time GetBuffer() is called, a new buffer from the pool will be required. + /// + /// IMPORTANT: Doing a Write() after calling GetBuffer() invalidates the buffer. The old buffer is held onto + /// until Dispose is called, but the next time GetBuffer() is called, a new buffer from the pool will be required. + /// /// Object has been disposed public override byte[] GetBuffer() { - this.CheckDisposed(); + CheckDisposed(); - if (this._largeBuffer != null) - { - return this._largeBuffer; - } + if (_largeBuffer != null) return _largeBuffer; - if (this._blocks.Count == 1) - { - return this._blocks[0]; - } + if (_blocks.Count == 1) return _blocks[0]; // Buffer needs to reflect the capacity, not the length, because // it's possible that people will manipulate the buffer directly // and set the length afterward. Capacity sets the expectation // for the size of the buffer. - var newBuffer = this._memoryManager.GetLargeBuffer(this.Capacity, this._tag); + var newBuffer = _memoryManager.GetLargeBuffer(Capacity, _tag); // InternalRead will check for existence of largeBuffer, so make sure we // don't set it until after we've copied the data. - this.InternalRead(newBuffer, 0, this.length, 0); - this._largeBuffer = newBuffer; + InternalRead(newBuffer, 0, length, 0); + _largeBuffer = newBuffer; - if (this._blocks.Count > 0 && this._memoryManager.AggressiveBufferReturn) + if (_blocks.Count > 0 && _memoryManager.AggressiveBufferReturn) { - this._memoryManager.ReturnBlocks(this._blocks, this._tag); - this._blocks.Clear(); + _memoryManager.ReturnBlocks(_blocks, _tag); + _blocks.Clear(); } - return this._largeBuffer; + return _largeBuffer; } /// @@ -404,10 +365,10 @@ public override byte[] GetBuffer() [Obsolete("This method has degraded performance vs. GetBuffer and should be avoided.")] public override byte[] ToArray() { - this.CheckDisposed(); - var newBuffer = new byte[this.Length]; + CheckDisposed(); + var newBuffer = new byte[Length]; - this.InternalRead(newBuffer, 0, this.length, 0); + InternalRead(newBuffer, 0, length, 0); return newBuffer; } #pragma warning restore CS0809 @@ -423,10 +384,7 @@ public override byte[] ToArray() /// offset or count is less than 0 /// offset subtracted from the buffer length is less than count /// Object has been disposed - public override int Read(byte[] buffer, int offset, int count) - { - return this.SafeRead(buffer, offset, count, ref this.position); - } + public override int Read(byte[] buffer, int offset, int count) => SafeRead(buffer, offset, count, ref position); /// /// Reads from the specified position into the provided buffer @@ -442,28 +400,16 @@ public override int Read(byte[] buffer, int offset, int count) /// Object has been disposed public int SafeRead(byte[] buffer, int offset, int count, ref int streamPosition) { - this.CheckDisposed(); - if (buffer == null) - { - throw new ArgumentNullException(nameof(buffer)); - } + CheckDisposed(); + if (buffer == null) throw new ArgumentNullException(nameof(buffer)); - if (offset < 0) - { - throw new ArgumentOutOfRangeException(nameof(offset), "offset cannot be negative"); - } + if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset), "offset cannot be negative"); - if (count < 0) - { - throw new ArgumentOutOfRangeException(nameof(count), "count cannot be negative"); - } + if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), "count cannot be negative"); - if (offset + count > buffer.Length) - { - throw new ArgumentException("buffer length must be at least offset + count"); - } + if (offset + count > buffer.Length) throw new ArgumentException("buffer length must be at least offset + count"); - int amountRead = this.InternalRead(buffer, offset, count, streamPosition); + var amountRead = InternalRead(buffer, offset, count, streamPosition); streamPosition += amountRead; return amountRead; } @@ -480,56 +426,39 @@ public int SafeRead(byte[] buffer, int offset, int count, ref int streamPosition /// Object has been disposed public override void Write(byte[] buffer, int offset, int count) { - this.CheckDisposed(); - if (buffer == null) - { - throw new ArgumentNullException(nameof(buffer)); - } + CheckDisposed(); + if (buffer == null) throw new ArgumentNullException(nameof(buffer)); if (offset < 0) - { throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset must be in the range of 0 - buffer.Length-1"); - } - if (count < 0) - { - throw new ArgumentOutOfRangeException(nameof(count), count, "count must be non-negative"); - } + if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), count, "count must be non-negative"); - if (count + offset > buffer.Length) - { - throw new ArgumentException("count must be greater than buffer.Length - offset"); - } + if (count + offset > buffer.Length) throw new ArgumentException("count must be greater than buffer.Length - offset"); - int blockSize = this._memoryManager.BlockSize; - long end = (long)this.position + count; + var blockSize = _memoryManager.BlockSize; + var end = (long)position + count; // Check for overflow - if (end > MaxStreamLength) - { - throw new IOException("Maximum capacity exceeded"); - } + if (end > MaxStreamLength) throw new IOException("Maximum capacity exceeded"); - long requiredBuffers = (end + blockSize - 1) / blockSize; + var requiredBuffers = (end + blockSize - 1) / blockSize; - if (requiredBuffers * blockSize > MaxStreamLength) - { - throw new IOException("Maximum capacity exceeded"); - } + if (requiredBuffers * blockSize > MaxStreamLength) throw new IOException("Maximum capacity exceeded"); - this.EnsureCapacity((int)end); + EnsureCapacity((int)end); - if (this._largeBuffer == null) + if (_largeBuffer == null) { - int bytesRemaining = count; - int bytesWritten = 0; - var blockAndOffset = this.GetBlockAndRelativeOffset(this.position); + var bytesRemaining = count; + var bytesWritten = 0; + var blockAndOffset = GetBlockAndRelativeOffset(position); while (bytesRemaining > 0) { - byte[] currentBlock = this._blocks[blockAndOffset.Block]; - int remainingInBlock = blockSize - blockAndOffset.Offset; - int amountToWriteInBlock = Math.Min(remainingInBlock, bytesRemaining); + var currentBlock = _blocks[blockAndOffset.Block]; + var remainingInBlock = blockSize - blockAndOffset.Offset; + var amountToWriteInBlock = Math.Min(remainingInBlock, bytesRemaining); Buffer.BlockCopy(buffer, offset + bytesWritten, currentBlock, blockAndOffset.Offset, amountToWriteInBlock); @@ -542,20 +471,15 @@ public override void Write(byte[] buffer, int offset, int count) } } else - { - Buffer.BlockCopy(buffer, offset, this._largeBuffer, this.position, count); - } - this.position = (int)end; - this.length = Math.Max(this.position, this.length); + Buffer.BlockCopy(buffer, offset, _largeBuffer, position, count); + position = (int)end; + length = Math.Max(position, length); } /// /// Returns a useful string for debugging. This should not normally be called in actual production code. /// - public override string ToString() - { - return $"Id = {this.Id}, Tag = {this.Tag}, Length = {this.Length:N0} bytes"; - } + public override string ToString() => $"Id = {Id}, Tag = {Tag}, Length = {Length:N0} bytes"; /// /// Writes a single byte to the current position in the stream. @@ -564,31 +488,26 @@ public override string ToString() /// Object has been disposed public override void WriteByte(byte value) { - this.CheckDisposed(); - int end = this.position + 1; + CheckDisposed(); + var end = position + 1; // Check for overflow - if (end > MaxStreamLength) - { - throw new IOException("Maximum capacity exceeded"); - } + if (end > MaxStreamLength) throw new IOException("Maximum capacity exceeded"); - this.EnsureCapacity(end); - if (this._largeBuffer == null) + EnsureCapacity(end); + if (_largeBuffer == null) { - var blockSize = this._memoryManager.BlockSize; - var block = this.position / blockSize; - var offset = this.position - block * blockSize; - var currentBlock = this._blocks[block]; + var blockSize = _memoryManager.BlockSize; + var block = position / blockSize; + var offset = position - block * blockSize; + var currentBlock = _blocks[block]; currentBlock[offset] = value; } else - { - this._largeBuffer[this.position] = value; - } + _largeBuffer[position] = value; - this.position = end; - this.length = Math.Max(this.position, this.length); + position = end; + length = Math.Max(position, length); } /// @@ -596,10 +515,7 @@ public override void WriteByte(byte value) /// /// The byte at the current position, or -1 if the position is at the end of the stream. /// Object has been disposed - public override int ReadByte() - { - return this.SafeReadByte(ref this.position); - } + public override int ReadByte() => SafeReadByte(ref position); /// /// Reads a single byte from the specified position in the stream. @@ -609,21 +525,17 @@ public override int ReadByte() /// Object has been disposed public int SafeReadByte(ref int streamPosition) { - this.CheckDisposed(); - if (streamPosition == this.length) - { - return -1; - } + CheckDisposed(); + if (streamPosition == length) return -1; + byte value; - if (this._largeBuffer == null) + if (_largeBuffer == null) { - var blockAndOffset = this.GetBlockAndRelativeOffset(streamPosition); - value = this._blocks[blockAndOffset.Block][blockAndOffset.Offset]; + var blockAndOffset = GetBlockAndRelativeOffset(streamPosition); + value = _blocks[blockAndOffset.Block][blockAndOffset.Offset]; } else - { - value = this._largeBuffer[streamPosition]; - } + value = _largeBuffer[streamPosition]; streamPosition++; return value; } @@ -635,20 +547,15 @@ public int SafeReadByte(ref int streamPosition) /// Object has been disposed public override void SetLength(long value) { - this.CheckDisposed(); + CheckDisposed(); if (value < 0 || value > MaxStreamLength) - { throw new ArgumentOutOfRangeException(nameof(value), "value must be non-negative and at most " + MaxStreamLength); - } - this.EnsureCapacity((int)value); + EnsureCapacity((int)value); - this.length = (int)value; - if (this.position > value) - { - this.position = (int)value; - } + length = (int)value; + if (position > value) position = (int)value; } /// @@ -663,11 +570,8 @@ public override void SetLength(long value) /// Attempt to set negative position public override long Seek(long offset, SeekOrigin loc) { - this.CheckDisposed(); - if (offset > MaxStreamLength) - { - throw new ArgumentOutOfRangeException(nameof(offset), "offset cannot be larger than " + MaxStreamLength); - } + CheckDisposed(); + if (offset > MaxStreamLength) throw new ArgumentOutOfRangeException(nameof(offset), "offset cannot be larger than " + MaxStreamLength); int newPosition; switch (loc) @@ -676,20 +580,18 @@ public override long Seek(long offset, SeekOrigin loc) newPosition = (int)offset; break; case SeekOrigin.Current: - newPosition = (int)offset + this.position; + newPosition = (int)offset + position; break; case SeekOrigin.End: - newPosition = (int)offset + this.length; + newPosition = (int)offset + length; break; default: throw new ArgumentException("Invalid seek origin", nameof(loc)); } - if (newPosition < 0) - { - throw new IOException("Seek before beginning"); - } - this.position = newPosition; - return this.position; + if (newPosition < 0) throw new IOException("Seek before beginning"); + + position = newPosition; + return position; } /// @@ -699,21 +601,18 @@ public override long Seek(long offset, SeekOrigin loc) /// Important: This does a synchronous write, which may not be desired in some situations public override void WriteTo(Stream stream) { - this.CheckDisposed(); - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } + CheckDisposed(); + if (stream == null) throw new ArgumentNullException(nameof(stream)); - if (this._largeBuffer == null) + if (_largeBuffer == null) { - int currentBlock = 0; - int bytesRemaining = this.length; + var currentBlock = 0; + var bytesRemaining = length; while (bytesRemaining > 0) { - int amountToCopy = Math.Min(this._blocks[currentBlock].Length, bytesRemaining); - stream.Write(this._blocks[currentBlock], 0, amountToCopy); + var amountToCopy = Math.Min(_blocks[currentBlock].Length, bytesRemaining); + stream.Write(_blocks[currentBlock], 0, amountToCopy); bytesRemaining -= amountToCopy; @@ -721,44 +620,32 @@ public override void WriteTo(Stream stream) } } else - { - stream.Write(this._largeBuffer, 0, this.length); - } + stream.Write(_largeBuffer, 0, length); } - #endregion - - #region Helper Methods - private bool Disposed => Interlocked.Read(ref this._disposedState) != 0; private void CheckDisposed() { - if (this.Disposed) - { - throw new ObjectDisposedException($"The stream with Id {this._id} and Tag {this._tag} is disposed."); - } + if (Disposed) throw new ObjectDisposedException($"The stream with Id {_id} and Tag {_tag} is disposed."); } private int InternalRead(byte[] buffer, int offset, int count, int fromPosition) { - if (this.length - fromPosition <= 0) - { - return 0; - } + if (length - fromPosition <= 0) return 0; int amountToCopy; - if (this._largeBuffer == null) + if (_largeBuffer == null) { - var blockAndOffset = this.GetBlockAndRelativeOffset(fromPosition); - int bytesWritten = 0; - int bytesRemaining = Math.Min(count, this.length - fromPosition); + var blockAndOffset = GetBlockAndRelativeOffset(fromPosition); + var bytesWritten = 0; + var bytesRemaining = Math.Min(count, length - fromPosition); while (bytesRemaining > 0) { - amountToCopy = Math.Min(this._blocks[blockAndOffset.Block].Length - blockAndOffset.Offset, + amountToCopy = Math.Min(_blocks[blockAndOffset.Block].Length - blockAndOffset.Offset, bytesRemaining); - Buffer.BlockCopy(this._blocks[blockAndOffset.Block], blockAndOffset.Offset, buffer, + Buffer.BlockCopy(_blocks[blockAndOffset.Block], blockAndOffset.Offset, buffer, bytesWritten + offset, amountToCopy); bytesWritten += amountToCopy; @@ -769,54 +656,36 @@ private int InternalRead(byte[] buffer, int offset, int count, int fromPosition) } return bytesWritten; } - amountToCopy = Math.Min(count, this.length - fromPosition); - Buffer.BlockCopy(this._largeBuffer, fromPosition, buffer, offset, amountToCopy); + amountToCopy = Math.Min(count, length - fromPosition); + Buffer.BlockCopy(_largeBuffer, fromPosition, buffer, offset, amountToCopy); return amountToCopy; } - private struct BlockAndOffset - { - public int Block; - public int Offset; - - public BlockAndOffset(int block, int offset) - { - this.Block = block; - this.Offset = offset; - } - } - private BlockAndOffset GetBlockAndRelativeOffset(int offset) { - var blockSize = this._memoryManager.BlockSize; + var blockSize = _memoryManager.BlockSize; return new BlockAndOffset(offset / blockSize, offset % blockSize); } private void EnsureCapacity(int newCapacity) { - if (newCapacity > this._memoryManager.MaximumStreamCapacity && this._memoryManager.MaximumStreamCapacity > 0) - { + if (newCapacity > _memoryManager.MaximumStreamCapacity && _memoryManager.MaximumStreamCapacity > 0) throw new InvalidOperationException("Requested capacity is too large: " + newCapacity + ". Limit is " + - this._memoryManager.MaximumStreamCapacity); - } + _memoryManager.MaximumStreamCapacity); - if (this._largeBuffer != null) + if (_largeBuffer != null) { - if (newCapacity > this._largeBuffer.Length) + if (newCapacity > _largeBuffer.Length) { - var newBuffer = this._memoryManager.GetLargeBuffer(newCapacity, this._tag); - this.InternalRead(newBuffer, 0, this.length, 0); - this.ReleaseLargeBuffer(); - this._largeBuffer = newBuffer; + var newBuffer = _memoryManager.GetLargeBuffer(newCapacity, _tag); + InternalRead(newBuffer, 0, length, 0); + ReleaseLargeBuffer(); + _largeBuffer = newBuffer; } } else - { - while (this.Capacity < newCapacity) - { - _blocks.Add((this._memoryManager.GetBlock())); - } - } + while (Capacity < newCapacity) + _blocks.Add(_memoryManager.GetBlock()); } /// @@ -824,22 +693,27 @@ private void EnsureCapacity(int newCapacity) /// private void ReleaseLargeBuffer() { - if (this._memoryManager.AggressiveBufferReturn) - { - this._memoryManager.ReturnLargeBuffer(this._largeBuffer, this._tag); - } + if (_memoryManager.AggressiveBufferReturn) + _memoryManager.ReturnLargeBuffer(_largeBuffer, _tag); else { - if (this._dirtyBuffers == null) - { - // We most likely will only ever need space for one - this._dirtyBuffers = new List(1); - } - this._dirtyBuffers.Add(this._largeBuffer); + if (_dirtyBuffers == null) _dirtyBuffers = new List(1); + _dirtyBuffers.Add(_largeBuffer); } - this._largeBuffer = null; + _largeBuffer = null; + } + + private struct BlockAndOffset + { + public int Block; + public int Offset; + + public BlockAndOffset(int block, int offset) + { + Block = block; + Offset = offset; + } } - #endregion } } diff --git a/src/Elasticsearch.Net/Providers/RecyclableMemoryStreamFactory.cs b/src/Elasticsearch.Net/Providers/RecyclableMemoryStreamFactory.cs index a75a7857da3..9b99ed10d65 100644 --- a/src/Elasticsearch.Net/Providers/RecyclableMemoryStreamFactory.cs +++ b/src/Elasticsearch.Net/Providers/RecyclableMemoryStreamFactory.cs @@ -1,10 +1,9 @@ using System.IO; -using System.Linq; namespace Elasticsearch.Net { /// - /// A factory for creating memory streams using a recyclable pool of instances + /// A factory for creating memory streams using a recyclable pool of instances /// public class RecyclableMemoryStreamFactory : IMemoryStreamFactory { diff --git a/src/Elasticsearch.Net/Providers/RecyclableMemoryStreamManager.cs b/src/Elasticsearch.Net/Providers/RecyclableMemoryStreamManager.cs index ab9499fd925..453de76356e 100644 --- a/src/Elasticsearch.Net/Providers/RecyclableMemoryStreamManager.cs +++ b/src/Elasticsearch.Net/Providers/RecyclableMemoryStreamManager.cs @@ -38,10 +38,8 @@ internal class RecyclableMemoryStreamManager public const int DefaultLargeBufferMultiple = 1024 * 1024; public const int DefaultMaximumBufferSize = 128 * 1024 * 1024; - private readonly int _blockSize; private readonly long[] _largeBufferFreeSize; private readonly long[] _largeBufferInUseSize; - private readonly int _largeBufferMultiple; /// /// pools[0] = 1x largeBufferMultiple buffers @@ -50,7 +48,6 @@ internal class RecyclableMemoryStreamManager /// private readonly ConcurrentStack[] largePools; - private readonly int _maximumBufferSize; private readonly ConcurrentStack smallPool; private long _smallPoolFreeSize; @@ -68,78 +65,75 @@ public RecyclableMemoryStreamManager() /// Size of each block that is pooled. Must be > 0. /// Each large buffer will be a multiple of this value. /// Buffers larger than this are not pooled - /// blockSize is not a positive number, or largeBufferMultiple is not a positive number, or maximumBufferSize is less than blockSize. + /// + /// blockSize is not a positive number, or largeBufferMultiple is not a positive number, or + /// maximumBufferSize is less than blockSize. + /// /// maximumBufferSize is not a multiple of largeBufferMultiple public RecyclableMemoryStreamManager(int blockSize, int largeBufferMultiple, int maximumBufferSize) { - if (blockSize <= 0) - { - throw new ArgumentOutOfRangeException(nameof(blockSize), blockSize, "blockSize must be a positive number"); - } + if (blockSize <= 0) throw new ArgumentOutOfRangeException(nameof(blockSize), blockSize, "blockSize must be a positive number"); if (largeBufferMultiple <= 0) - { throw new ArgumentOutOfRangeException(nameof(largeBufferMultiple), "largeBufferMultiple must be a positive number"); - } if (maximumBufferSize < blockSize) - { throw new ArgumentOutOfRangeException(nameof(maximumBufferSize), "maximumBufferSize must be at least blockSize"); - } - this._blockSize = blockSize; - this._largeBufferMultiple = largeBufferMultiple; - this._maximumBufferSize = maximumBufferSize; + BlockSize = blockSize; + LargeBufferMultiple = largeBufferMultiple; + MaximumBufferSize = maximumBufferSize; - if (!this.IsLargeBufferMultiple(maximumBufferSize)) - { + if (!IsLargeBufferMultiple(maximumBufferSize)) throw new ArgumentException("maximumBufferSize is not a multiple of largeBufferMultiple", nameof(maximumBufferSize)); - } - this.smallPool = new ConcurrentStack(); + smallPool = new ConcurrentStack(); var numLargePools = maximumBufferSize / largeBufferMultiple; // +1 to store size of bytes in use that are too large to be pooled - this._largeBufferInUseSize = new long[numLargePools + 1]; - this._largeBufferFreeSize = new long[numLargePools]; + _largeBufferInUseSize = new long[numLargePools + 1]; + _largeBufferFreeSize = new long[numLargePools]; - this.largePools = new ConcurrentStack[numLargePools]; + largePools = new ConcurrentStack[numLargePools]; - for (var i = 0; i < this.largePools.Length; ++i) - { - this.largePools[i] = new ConcurrentStack(); - } + for (var i = 0; i < largePools.Length; ++i) largePools[i] = new ConcurrentStack(); } /// - /// The size of each block. It must be set at creation and cannot be changed. - /// - public int BlockSize => this._blockSize; - - /// - /// All buffers are multiples of this number. It must be set at creation and cannot be changed. + /// Whether dirty buffers can be immediately returned to the buffer pool. E.g. when GetBuffer() is called on + /// a stream and creates a single large buffer, if this setting is enabled, the other blocks will be returned + /// to the buffer pool immediately. + /// Note when enabling this setting that the user is responsible for ensuring that any buffer previously + /// retrieved from a stream which is subsequently modified is not used after modification (as it may no longer + /// be valid). /// - public int LargeBufferMultiple => this._largeBufferMultiple; + public bool AggressiveBufferReturn { get; set; } /// - /// Gets or sets the maximum buffer size. + /// The size of each block. It must be set at creation and cannot be changed. /// - /// Any buffer that is returned to the pool that is larger than this will be - /// discarded and garbage collected. - public int MaximumBufferSize => this._maximumBufferSize; + public int BlockSize { get; } /// - /// Number of bytes in small pool not currently in use + /// All buffers are multiples of this number. It must be set at creation and cannot be changed. /// - public long SmallPoolFreeSize => this._smallPoolFreeSize; + public int LargeBufferMultiple { get; } /// - /// Number of bytes currently in use by stream from the small pool + /// How many buffers are in the large pool /// - public long SmallPoolInUseSize => this._smallPoolInUseSize; + public long LargeBuffersFree + { + get + { + long free = 0; + foreach (var pool in largePools) free += pool.Count; + return free; + } + } /// /// Number of bytes in large pool not currently in use @@ -149,9 +143,9 @@ public long LargePoolFreeSize get { long sum = 0; - for (var index = 0; index < this._largeBufferFreeSize.Length; index++) + for (var index = 0; index < _largeBufferFreeSize.Length; index++) { - var freeSize = this._largeBufferFreeSize[index]; + var freeSize = _largeBufferFreeSize[index]; sum += freeSize; } @@ -167,9 +161,9 @@ public long LargePoolInUseSize get { long sum = 0; - for (var index = 0; index < this._largeBufferInUseSize.Length; index++) + for (var index = 0; index < _largeBufferInUseSize.Length; index++) { - var inUseSize = this._largeBufferInUseSize[index]; + var inUseSize = _largeBufferInUseSize[index]; sum += inUseSize; } @@ -178,25 +172,19 @@ public long LargePoolInUseSize } /// - /// How many blocks are in the small pool + /// Gets or sets the maximum buffer size. /// - public long SmallBlocksFree => this.smallPool.Count; + /// + /// Any buffer that is returned to the pool that is larger than this will be + /// discarded and garbage collected. + /// + public int MaximumBufferSize { get; } /// - /// How many buffers are in the large pool + /// How many bytes of large free buffers to allow before we start dropping + /// those returned to us. /// - public long LargeBuffersFree - { - get - { - long free = 0; - foreach (var pool in this.largePools) - { - free += pool.Count; - } - return free; - } - } + public long MaximumFreeLargePoolBytes { get; set; } /// /// How many bytes of small free blocks to allow before we start dropping @@ -204,12 +192,6 @@ public long LargeBuffersFree /// public long MaximumFreeSmallPoolBytes { get; set; } - /// - /// How many bytes of large free buffers to allow before we start dropping - /// those returned to us. - /// - public long MaximumFreeLargePoolBytes { get; set; } - /// /// Maximum stream capacity in bytes. Attempts to set a larger capacity will /// result in an exception. @@ -218,14 +200,19 @@ public long LargeBuffersFree public long MaximumStreamCapacity { get; set; } /// - /// Whether dirty buffers can be immediately returned to the buffer pool. E.g. when GetBuffer() is called on - /// a stream and creates a single large buffer, if this setting is enabled, the other blocks will be returned - /// to the buffer pool immediately. - /// Note when enabling this setting that the user is responsible for ensuring that any buffer previously - /// retrieved from a stream which is subsequently modified is not used after modification (as it may no longer - /// be valid). + /// How many blocks are in the small pool /// - public bool AggressiveBufferReturn { get; set; } + public long SmallBlocksFree => smallPool.Count; + + /// + /// Number of bytes in small pool not currently in use + /// + public long SmallPoolFreeSize => _smallPoolFreeSize; + + /// + /// Number of bytes currently in use by stream from the small pool + /// + public long SmallPoolInUseSize => _smallPoolInUseSize; /// /// Removes and returns a single block from the pool. @@ -233,18 +220,12 @@ public long LargeBuffersFree /// A byte[] array internal byte[] GetBlock() { - if (!this.smallPool.TryPop(out var block)) - { - // We'll add this back to the pool when the stream is disposed - // (unless our free pool is too large) - block = new byte[this.BlockSize]; - } + if (!smallPool.TryPop(out var block)) + block = new byte[BlockSize]; else - { - Interlocked.Add(ref this._smallPoolFreeSize, -this.BlockSize); - } + Interlocked.Add(ref _smallPoolFreeSize, -BlockSize); - Interlocked.Add(ref this._smallPoolInUseSize, this.BlockSize); + Interlocked.Add(ref _smallPoolInUseSize, BlockSize); return block; } @@ -257,21 +238,17 @@ internal byte[] GetBlock() /// A buffer of at least the required size. internal byte[] GetLargeBuffer(int requiredSize, string tag) { - requiredSize = this.RoundToLargeBufferMultiple(requiredSize); + requiredSize = RoundToLargeBufferMultiple(requiredSize); - var poolIndex = requiredSize / this._largeBufferMultiple - 1; + var poolIndex = requiredSize / LargeBufferMultiple - 1; byte[] buffer; - if (poolIndex < this.largePools.Length) + if (poolIndex < largePools.Length) { - if (!this.largePools[poolIndex].TryPop(out buffer)) - { + if (!largePools[poolIndex].TryPop(out buffer)) buffer = new byte[requiredSize]; - } else - { - Interlocked.Add(ref this._largeBufferFreeSize[poolIndex], -buffer.Length); - } + Interlocked.Add(ref _largeBufferFreeSize[poolIndex], -buffer.Length); } else { @@ -279,26 +256,21 @@ internal byte[] GetLargeBuffer(int requiredSize, string tag) // We still want to track the size, though, and we've reserved a slot // in the end of the inuse array for nonpooled bytes in use. - poolIndex = this._largeBufferInUseSize.Length - 1; + poolIndex = _largeBufferInUseSize.Length - 1; // We still want to round up to reduce heap fragmentation. buffer = new byte[requiredSize]; } - Interlocked.Add(ref this._largeBufferInUseSize[poolIndex], buffer.Length); + Interlocked.Add(ref _largeBufferInUseSize[poolIndex], buffer.Length); return buffer; } - private int RoundToLargeBufferMultiple(int requiredSize) - { - return ((requiredSize + this.LargeBufferMultiple - 1) / this.LargeBufferMultiple) * this.LargeBufferMultiple; - } + private int RoundToLargeBufferMultiple(int requiredSize) => + (requiredSize + LargeBufferMultiple - 1) / LargeBufferMultiple * LargeBufferMultiple; - private bool IsLargeBufferMultiple(int value) - { - return (value != 0) && (value % this.LargeBufferMultiple) == 0; - } + private bool IsLargeBufferMultiple(int value) => value != 0 && value % LargeBufferMultiple == 0; /// /// Returns the buffer to the large pool @@ -309,37 +281,28 @@ private bool IsLargeBufferMultiple(int value) /// buffer.Length is not a multiple of LargeBufferMultiple (it did not originate from this pool) internal void ReturnLargeBuffer(byte[] buffer, string tag) { - if (buffer == null) - { - throw new ArgumentNullException(nameof(buffer)); - } + if (buffer == null) throw new ArgumentNullException(nameof(buffer)); - if (!this.IsLargeBufferMultiple(buffer.Length)) - { + if (!IsLargeBufferMultiple(buffer.Length)) throw new ArgumentException( "buffer did not originate from this memory manager. The size is not a multiple of " + - this.LargeBufferMultiple); - } + LargeBufferMultiple); - var poolIndex = buffer.Length / this._largeBufferMultiple - 1; + var poolIndex = buffer.Length / LargeBufferMultiple - 1; - if (poolIndex < this.largePools.Length) + if (poolIndex < largePools.Length) { - if ((this.largePools[poolIndex].Count + 1) * buffer.Length <= this.MaximumFreeLargePoolBytes || - this.MaximumFreeLargePoolBytes == 0) + if ((largePools[poolIndex].Count + 1) * buffer.Length <= MaximumFreeLargePoolBytes || + MaximumFreeLargePoolBytes == 0) { - this.largePools[poolIndex].Push(buffer); - Interlocked.Add(ref this._largeBufferFreeSize[poolIndex], buffer.Length); + largePools[poolIndex].Push(buffer); + Interlocked.Add(ref _largeBufferFreeSize[poolIndex], buffer.Length); } } else - { - // This is a non-poolable buffer, but we still want to track its size for inuse - // analysis. We have space in the inuse array for this. - poolIndex = this._largeBufferInUseSize.Length - 1; - } + poolIndex = _largeBufferInUseSize.Length - 1; - Interlocked.Add(ref this._largeBufferInUseSize[poolIndex], -buffer.Length); + Interlocked.Add(ref _largeBufferInUseSize[poolIndex], -buffer.Length); } /// @@ -351,33 +314,26 @@ internal void ReturnLargeBuffer(byte[] buffer, string tag) /// blocks contains buffers that are the wrong size (or null) for this memory manager internal void ReturnBlocks(ICollection blocks, string tag) { - if (blocks == null) - { - throw new ArgumentNullException(nameof(blocks)); - } + if (blocks == null) throw new ArgumentNullException(nameof(blocks)); - var bytesToReturn = blocks.Count * this.BlockSize; - Interlocked.Add(ref this._smallPoolInUseSize, -bytesToReturn); + var bytesToReturn = blocks.Count * BlockSize; + Interlocked.Add(ref _smallPoolInUseSize, -bytesToReturn); foreach (var block in blocks) { - if (block == null || block.Length != this.BlockSize) - { + if (block == null || block.Length != BlockSize) throw new ArgumentException("blocks contains buffers that are not BlockSize in length"); - } } foreach (var block in blocks) { - if (this.MaximumFreeSmallPoolBytes == 0 || this.SmallPoolFreeSize < this.MaximumFreeSmallPoolBytes) + if (MaximumFreeSmallPoolBytes == 0 || SmallPoolFreeSize < MaximumFreeSmallPoolBytes) { - Interlocked.Add(ref this._smallPoolFreeSize, this.BlockSize); - this.smallPool.Push(block); + Interlocked.Add(ref _smallPoolFreeSize, BlockSize); + smallPool.Push(block); } else - { break; - } } } @@ -386,20 +342,14 @@ internal void ReturnBlocks(ICollection blocks, string tag) /// Retrieve a new MemoryStream object with no tag and a default initial capacity. /// /// A MemoryStream. - public MemoryStream GetStream() - { - return new RecyclableMemoryStream(this); - } + public MemoryStream GetStream() => new RecyclableMemoryStream(this); /// /// Retrieve a new MemoryStream object with the given tag and a default initial capacity. /// /// A tag which can be used to track the source of the stream. /// A MemoryStream. - public MemoryStream GetStream(string tag) - { - return new RecyclableMemoryStream(this, tag); - } + public MemoryStream GetStream(string tag) => new RecyclableMemoryStream(this, tag); /// /// Retrieve a new MemoryStream object with the given tag and at least the given capacity. @@ -407,31 +357,27 @@ public MemoryStream GetStream(string tag) /// A tag which can be used to track the source of the stream. /// The minimum desired capacity for the stream. /// A MemoryStream. - public MemoryStream GetStream(string tag, int requiredSize) - { - return new RecyclableMemoryStream(this, tag, requiredSize); - } + public MemoryStream GetStream(string tag, int requiredSize) => new RecyclableMemoryStream(this, tag, requiredSize); /// /// Retrieve a new MemoryStream object with the given tag and at least the given capacity, possibly using /// a single continugous underlying buffer. /// - /// Retrieving a MemoryStream which provides a single contiguous buffer can be useful in situations + /// + /// Retrieving a MemoryStream which provides a single contiguous buffer can be useful in situations /// where the initial size is known and it is desirable to avoid copying data between the smaller underlying /// buffers to a single large one. This is most helpful when you know that you will always call GetBuffer - /// on the underlying stream. + /// on the underlying stream. + /// /// A tag which can be used to track the source of the stream. /// The minimum desired capacity for the stream. /// Whether to attempt to use a single contiguous buffer. /// A MemoryStream. public MemoryStream GetStream(string tag, int requiredSize, bool asContiguousBuffer) { - if (!asContiguousBuffer || requiredSize <= this.BlockSize) - { - return this.GetStream(tag, requiredSize); - } + if (!asContiguousBuffer || requiredSize <= BlockSize) return GetStream(tag, requiredSize); - return new RecyclableMemoryStream(this, tag, requiredSize, this.GetLargeBuffer(requiredSize, tag)); + return new RecyclableMemoryStream(this, tag, requiredSize, GetLargeBuffer(requiredSize, tag)); } /// diff --git a/src/Elasticsearch.Net/Responses/Dynamic/DynamicBody.cs b/src/Elasticsearch.Net/Responses/Dynamic/DynamicBody.cs index c08879ece25..bcffe6e14ed 100644 --- a/src/Elasticsearch.Net/Responses/Dynamic/DynamicBody.cs +++ b/src/Elasticsearch.Net/Responses/Dynamic/DynamicBody.cs @@ -12,94 +12,36 @@ namespace Elasticsearch.Net /// /// A dictionary that supports dynamic access. /// - public class DynamicBody : - DynamicObject, - IEquatable, - IEnumerable, - IDictionary + public class DynamicBody + : DynamicObject, + IEquatable, + IEnumerable, + IDictionary { private readonly IDictionary BackingDictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); /// - /// Returns an empty dynamic dictionary. - /// - /// A instance. - public static DynamicBody Empty => new DynamicBody(); - - /// - /// Creates a dynamic dictionary from an instance. + /// Gets the number of elements contained in the . /// - /// An instance, that the dynamic dictionary should be created from. - /// An instance. - public static DynamicBody Create(IDictionary values) - { - var instance = new DynamicBody(); - - foreach (var key in values.Keys) - { - instance[key] = values[key]; - } - - return instance; - } + /// The number of elements contained in the . + public int Count => BackingDictionary.Count; /// - /// Provides the implementation for operations that set member values. Classes derived from the class can override this method to specify dynamic behavior for operations such as setting a value for a property. - /// - /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.) - /// Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member to which the value is being assigned. For example, for the statement sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.The value to set to the member. For example, for sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the class, the is "Test". - public override bool TrySetMember(SetMemberBinder binder, object value) - { - this[binder.Name] = value; - return true; - } - - /// - /// Provides the implementation for operations that get member values. Classes derived from the class can override this method to specify dynamic behavior for operations such as getting a value for a property. - /// - /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.) - /// Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.The result of the get operation. For example, if the method is called for a property, you can assign the property value to . - public override bool TryGetMember(GetMemberBinder binder, out object result) - { - if (!BackingDictionary.TryGetValue(binder.Name, out result)) - { - result = new ElasticsearchDynamicValue(null); - } - - return true; - } - - /// - /// Returns the enumeration of all dynamic member names. - /// - /// A that contains dynamic member names. - public override IEnumerable GetDynamicMemberNames() - { - return BackingDictionary.Keys; - } - - /// - /// Returns the enumeration of all dynamic member names. + /// Returns an empty dynamic dictionary. /// - /// A that contains dynamic member names. - public IEnumerator GetEnumerator() - { - return BackingDictionary.Keys.GetEnumerator(); - } + /// A instance. + public static DynamicBody Empty => new DynamicBody(); /// - /// Returns the enumeration of all dynamic member names. + /// Gets a value indicating whether the is read-only. /// - /// A that contains dynamic member names. - IEnumerator IEnumerable.GetEnumerator() - { - return BackingDictionary.Keys.GetEnumerator(); - } + /// Always returns . + public bool IsReadOnly => false; /// - /// Gets or sets the with the specified name. + /// Gets or sets the with the specified name. /// - /// A instance containing a value. + /// A instance containing a value. public dynamic this[string name] { get @@ -107,10 +49,7 @@ public dynamic this[string name] name = GetNeutralKey(name); dynamic member; - if (!BackingDictionary.TryGetValue(name, out member)) - { - member = new ElasticsearchDynamicValue(null); - } + if (!BackingDictionary.TryGetValue(name, out member)) member = new ElasticsearchDynamicValue(null); return member; } @@ -123,182 +62,240 @@ public dynamic this[string name] } /// - /// Indicates whether the current is equal to another object of the same type. + /// Gets an containing the keys of the . /// - /// if the current instance is equal to the parameter; otherwise, . - /// An instance to compare with this instance. - public bool Equals(DynamicBody other) - { - if (ReferenceEquals(null, other)) - { - return false; - } - - return ReferenceEquals(this, other) || Equals(other.BackingDictionary, this.BackingDictionary); - } + /// An containing the keys of the . + public ICollection Keys => BackingDictionary.Keys; /// - /// Determines whether the specified is equal to this instance. + /// Gets an containing the values in the . /// - /// The to compare with this instance. - /// if the specified is equal to this instance; otherwise, . - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } + /// An containing the values in the . + public ICollection Values => BackingDictionary.Values; - if (ReferenceEquals(this, obj)) - { - return true; - } + /// + /// Adds an item to the . + /// + /// The object to add to the . + public void Add(KeyValuePair item) => this[item.Key] = item.Value; - return obj.GetType() == typeof(DynamicBody) && this.Equals((DynamicBody)obj); - } + /// + /// Removes all items from the . + /// + public void Clear() => BackingDictionary.Clear(); /// - /// Returns an enumerator that iterates through the collection. + /// Determines whether the contains a specific value. /// - /// A that can be used to iterate through the collection. - IEnumerator> IEnumerable>.GetEnumerator() + /// + /// if is found in the ; otherwise, . + /// + /// The object to locate in the . + public bool Contains(KeyValuePair item) { - return this.BackingDictionary.GetEnumerator(); + var dynamicValueKeyValuePair = + GetDynamicKeyValuePair(item); + + return BackingDictionary.Contains(dynamicValueKeyValuePair); } /// - /// Returns a hash code for this . + /// Copies the elements of the to an , starting at a particular + /// index. /// - /// A hash code for this , suitable for use in hashing algorithms and data structures like a hash table. - public override int GetHashCode() => BackingDictionary?.GetHashCode() ?? 0; + /// + /// The one-dimensional that is the destination of the elements copied from the + /// . The must have zero-based indexing. + /// + /// The zero-based index in at which copying begins. + public void CopyTo(KeyValuePair[] array, int arrayIndex) => BackingDictionary.CopyTo(array, arrayIndex); /// - /// Adds an element with the provided key and value to the . + /// Removes the first occurrence of a specific object from the . /// - /// The object to use as the key of the element to add. - /// The object to use as the value of the element to add. - public void Add(string key, dynamic value) + /// + /// if was successfully removed from the ; otherwise, + /// . + /// + /// The object to remove from the . + public bool Remove(KeyValuePair item) { - this[key] = value; + var dynamicValueKeyValuePair = + GetDynamicKeyValuePair(item); + + return BackingDictionary.Remove(dynamicValueKeyValuePair); } /// - /// Adds an item to the . + /// Adds an element with the provided key and value to the . /// - /// The object to add to the . - public void Add(KeyValuePair item) - { - this[item.Key] = item.Value; - } + /// The object to use as the key of the element to add. + /// The object to use as the value of the element to add. + public void Add(string key, dynamic value) => this[key] = value; /// - /// Determines whether the contains an element with the specified key. + /// Determines whether the contains an element with the specified key. /// - /// if the contains an element with the key; otherwise, . + /// + /// if the contains an element with the key; otherwise, . /// - /// The key to locate in the . - public bool ContainsKey(string key) - { - return this.BackingDictionary.ContainsKey(key); - } + /// The key to locate in the . + public bool ContainsKey(string key) => BackingDictionary.ContainsKey(key); /// - /// Gets an containing the keys of the . + /// Removes the element with the specified key from the . /// - /// An containing the keys of the . - public ICollection Keys => this.BackingDictionary.Keys; + /// if the element is successfully removed; otherwise, . + /// The key of the element to remove. + public bool Remove(string key) + { + key = GetNeutralKey(key); + return BackingDictionary.Remove(key); + } /// /// Gets the value associated with the specified key. /// - /// if the contains an element with the specified key; otherwise, . + /// + /// if the contains an element with the specified key; otherwise, + /// . + /// /// The key whose value to get. - /// When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the parameter. This parameter is passed uninitialized. + /// + /// When this method returns, the value associated with the specified key, if the key is found; otherwise, the default + /// value for the type of the parameter. This parameter is passed uninitialized. + /// public bool TryGetValue(string key, out dynamic value) { - if (this.BackingDictionary.TryGetValue(key, out value)) return true; + if (BackingDictionary.TryGetValue(key, out value)) return true; + return false; } /// - /// Removes all items from the . + /// Returns the enumeration of all dynamic member names. /// - public void Clear() => this.BackingDictionary.Clear(); + /// A that contains dynamic member names. + IEnumerator IEnumerable.GetEnumerator() => BackingDictionary.Keys.GetEnumerator(); /// - /// Gets the number of elements contained in the . + /// Returns an enumerator that iterates through the collection. /// - /// The number of elements contained in the . - public int Count - { - get { return this.BackingDictionary.Count; } - } + /// A that can be used to iterate through the collection. + IEnumerator> IEnumerable>.GetEnumerator() => BackingDictionary.GetEnumerator(); + + /// + /// Returns the enumeration of all dynamic member names. + /// + /// A that contains dynamic member names. + public IEnumerator GetEnumerator() => BackingDictionary.Keys.GetEnumerator(); /// - /// Determines whether the contains a specific value. + /// Indicates whether the current is equal to another object of the same type. /// - /// if is found in the ; otherwise, . + /// + /// if the current instance is equal to the parameter; otherwise, + /// . /// - /// The object to locate in the . - public bool Contains(KeyValuePair item) + /// An instance to compare with this instance. + public bool Equals(DynamicBody other) { - var dynamicValueKeyValuePair = - GetDynamicKeyValuePair(item); + if (ReferenceEquals(null, other)) return false; - return this.BackingDictionary.Contains(dynamicValueKeyValuePair); + return ReferenceEquals(this, other) || Equals(other.BackingDictionary, BackingDictionary); } /// - /// Copies the elements of the to an , starting at a particular index. + /// Creates a dynamic dictionary from an instance. /// - /// The one-dimensional that is the destination of the elements copied from the . The must have zero-based indexing. - /// The zero-based index in at which copying begins. - public void CopyTo(KeyValuePair[] array, int arrayIndex) + /// An instance, that the dynamic dictionary should be created from. + /// An instance. + public static DynamicBody Create(IDictionary values) { - this.BackingDictionary.CopyTo(array, arrayIndex); + var instance = new DynamicBody(); + + foreach (var key in values.Keys) instance[key] = values[key]; + + return instance; } /// - /// Gets a value indicating whether the is read-only. + /// Provides the implementation for operations that set member values. Classes derived from the + /// class can override this method to specify dynamic behavior for operations such as setting a value for a property. /// - /// Always returns . - public bool IsReadOnly + /// + /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language + /// determines the behavior. (In most cases, a language-specific run-time exception is thrown.) + /// + /// + /// Provides information about the object that called the dynamic operation. The binder.Name property provides the name of + /// the member to which the value is being assigned. For example, for the statement sampleObject.SampleProperty = "Test", where sampleObject is + /// an instance of the class derived from the class, binder.Name returns "SampleProperty". The + /// binder.IgnoreCase property specifies whether the member name is case-sensitive. + /// + /// + /// The value to set to the member. For example, for sampleObject.SampleProperty = "Test", where sampleObject is an + /// instance of the class derived from the class, the is "Test". + /// + public override bool TrySetMember(SetMemberBinder binder, object value) { - get { return false; } + this[binder.Name] = value; + return true; } /// - /// Removes the element with the specified key from the . + /// Provides the implementation for operations that get member values. Classes derived from the + /// class can override this method to specify dynamic behavior for operations such as getting a value for a property. /// - /// if the element is successfully removed; otherwise, . - /// The key of the element to remove. - public bool Remove(string key) + /// + /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language + /// determines the behavior. (In most cases, a run-time exception is thrown.) + /// + /// + /// Provides information about the object that called the dynamic operation. The binder.Name property provides the name of + /// the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, + /// where sampleObject is an instance of the class derived from the class, binder.Name returns + /// "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive. + /// + /// + /// The result of the get operation. For example, if the method is called for a property, you can assign the property + /// value to . + /// + public override bool TryGetMember(GetMemberBinder binder, out object result) { - key = GetNeutralKey(key); - return this.BackingDictionary.Remove(key); + if (!BackingDictionary.TryGetValue(binder.Name, out result)) result = new ElasticsearchDynamicValue(null); + + return true; } /// - /// Removes the first occurrence of a specific object from the . + /// Returns the enumeration of all dynamic member names. /// - /// if was successfully removed from the ; otherwise, . - /// The object to remove from the . - public bool Remove(KeyValuePair item) + /// A that contains dynamic member names. + public override IEnumerable GetDynamicMemberNames() => BackingDictionary.Keys; + + /// + /// Determines whether the specified is equal to this instance. + /// + /// The to compare with this instance. + /// + /// if the specified is equal to this instance; otherwise, + /// . + /// + public override bool Equals(object obj) { - var dynamicValueKeyValuePair = - GetDynamicKeyValuePair(item); + if (ReferenceEquals(null, obj)) return false; - return this.BackingDictionary.Remove(dynamicValueKeyValuePair); + if (ReferenceEquals(this, obj)) return true; + + return obj.GetType() == typeof(DynamicBody) && Equals((DynamicBody)obj); } /// - /// Gets an containing the values in the . + /// Returns a hash code for this . /// - /// An containing the values in the . - public ICollection Values - { - get { return this.BackingDictionary.Values; } - } + /// A hash code for this , suitable for use in hashing algorithms and data structures like a hash table. + public override int GetHashCode() => BackingDictionary?.GetHashCode() ?? 0; private static KeyValuePair GetDynamicKeyValuePair(KeyValuePair item) { @@ -307,9 +304,6 @@ private static KeyValuePair GetDynamicKeyValuePair(KeyValuePair return dynamicValueKeyValuePair; } - private static string GetNeutralKey(string key) - { - return key; - } + private static string GetNeutralKey(string key) => key; } } diff --git a/src/Elasticsearch.Net/Responses/Dynamic/DynamicResponse.cs b/src/Elasticsearch.Net/Responses/Dynamic/DynamicResponse.cs index 65883f26b2b..48b7181c773 100644 --- a/src/Elasticsearch.Net/Responses/Dynamic/DynamicResponse.cs +++ b/src/Elasticsearch.Net/Responses/Dynamic/DynamicResponse.cs @@ -3,6 +3,7 @@ public class DynamicResponse : ElasticsearchResponse { public DynamicResponse() { } - public DynamicResponse(DynamicBody body) => this.Body = body; + + public DynamicResponse(DynamicBody body) => Body = body; } } diff --git a/src/Elasticsearch.Net/Responses/Dynamic/ElasticsearchDynamicValue.cs b/src/Elasticsearch.Net/Responses/Dynamic/ElasticsearchDynamicValue.cs index 62aa2f639a4..68f078e4e3e 100644 --- a/src/Elasticsearch.Net/Responses/Dynamic/ElasticsearchDynamicValue.cs +++ b/src/Elasticsearch.Net/Responses/Dynamic/ElasticsearchDynamicValue.cs @@ -5,10 +5,8 @@ using System.Dynamic; using System.Globalization; using System.Linq.Expressions; -using System.Reflection; using System.Runtime.CompilerServices; using Microsoft.CSharp.RuntimeBinder; -using Binder = Microsoft.CSharp.RuntimeBinder.Binder; namespace Elasticsearch.Net { @@ -16,6 +14,297 @@ public class ElasticsearchDynamicValue : DynamicObject, IEquatable + /// Initializes a new instance of the class. + /// + /// The value to store in the instance + public ElasticsearchDynamicValue(object value) => this.value = value; + + /// + /// Gets a value indicating whether this instance has value. + /// + /// true if this instance has value; otherwise, false. + /// is considered as not being a value. + public bool HasValue => value != null; + + public ElasticsearchDynamicValue this[string name] + { + get + { + object r; + Dispatch(out r, name); + return (ElasticsearchDynamicValue)r; + } + } + + public ElasticsearchDynamicValue this[int i] + { + get + { + if (!HasValue) + return new ElasticsearchDynamicValue(null); + + var l = Value as IList; + if (l != null && l.Count - 1 >= i) return new ElasticsearchDynamicValue(l[i]); + + return new ElasticsearchDynamicValue(null); + } + } + + /// + /// Gets the inner value + /// + public object Value => value; + + /// + /// Returns the for this instance. + /// + /// + /// The enumerated constant that is the of the class or value type that implements this interface. + /// + /// 2 + public TypeCode GetTypeCode() + { + if (value == null) return TypeCode.Empty; + + return value.GetType().GetTypeCode(); + } + + /// + /// Converts the value of this instance to an equivalent Boolean value using the specified culture-specific formatting information. + /// + /// + /// A Boolean value equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public bool ToBoolean(IFormatProvider provider) => Convert.ToBoolean(value, provider); + + /// + /// Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified culture-specific formatting information. + /// + /// + /// An 8-bit unsigned integer equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public byte ToByte(IFormatProvider provider) => Convert.ToByte(value, provider); + + /// + /// Converts the value of this instance to an equivalent Unicode character using the specified culture-specific formatting information. + /// + /// + /// A Unicode character equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public char ToChar(IFormatProvider provider) => Convert.ToChar(value, provider); + + /// + /// Converts the value of this instance to an equivalent using the specified culture-specific formatting + /// information. + /// + /// + /// A instance equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public DateTime ToDateTime(IFormatProvider provider) => Convert.ToDateTime(value, provider); + + /// + /// Converts the value of this instance to an equivalent number using the specified culture-specific formatting + /// information. + /// + /// + /// A number equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public decimal ToDecimal(IFormatProvider provider) => Convert.ToDecimal(value, provider); + + /// + /// Converts the value of this instance to an equivalent double-precision floating-point number using the specified culture-specific formatting + /// information. + /// + /// + /// A double-precision floating-point number equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public double ToDouble(IFormatProvider provider) => Convert.ToDouble(value, provider); + + /// + /// Converts the value of this instance to an equivalent 16-bit signed integer using the specified culture-specific formatting information. + /// + /// + /// An 16-bit signed integer equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public short ToInt16(IFormatProvider provider) => Convert.ToInt16(value, provider); + + /// + /// Converts the value of this instance to an equivalent 32-bit signed integer using the specified culture-specific formatting information. + /// + /// + /// An 32-bit signed integer equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public int ToInt32(IFormatProvider provider) => Convert.ToInt32(value, provider); + + /// + /// Converts the value of this instance to an equivalent 64-bit signed integer using the specified culture-specific formatting information. + /// + /// + /// An 64-bit signed integer equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public long ToInt64(IFormatProvider provider) => Convert.ToInt64(value, provider); + + /// + /// Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture-specific formatting information. + /// + /// + /// An 8-bit signed integer equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + [CLSCompliant(false)] + public sbyte ToSByte(IFormatProvider provider) => Convert.ToSByte(value, provider); + + /// + /// Converts the value of this instance to an equivalent single-precision floating-point number using the specified culture-specific formatting + /// information. + /// + /// + /// A single-precision floating-point number equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public float ToSingle(IFormatProvider provider) => Convert.ToSingle(value, provider); + + /// + /// Converts the value of this instance to an equivalent using the specified culture-specific formatting + /// information. + /// + /// + /// A instance equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public string ToString(IFormatProvider provider) => Convert.ToString(value, provider); + + /// + /// Converts the value of this instance to an of the specified that has an + /// equivalent value, using the specified culture-specific formatting information. + /// + /// + /// An instance of type whose value is equivalent to the value of this + /// instance. + /// + /// The to which the value of this instance is converted. + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + public object ToType(Type conversionType, IFormatProvider provider) => Convert.ChangeType(value, conversionType, provider); + + /// + /// Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified culture-specific formatting information. + /// + /// + /// An 16-bit unsigned integer equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + [CLSCompliant(false)] + public ushort ToUInt16(IFormatProvider provider) => Convert.ToUInt16(value, provider); + + /// + /// Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified culture-specific formatting information. + /// + /// + /// An 32-bit unsigned integer equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + [CLSCompliant(false)] + public uint ToUInt32(IFormatProvider provider) => Convert.ToUInt32(value, provider); + + /// + /// Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified culture-specific formatting information. + /// + /// + /// An 64-bit unsigned integer equivalent to the value of this instance. + /// + /// + /// An interface implementation that supplies culture-specific formatting + /// information. + /// + /// 2 + [CLSCompliant(false)] + public ulong ToUInt64(IFormatProvider provider) => Convert.ToUInt64(value, provider); + + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// + /// true if the current object is equal to the parameter; otherwise, false. + /// + /// An to compare with this instance. + public bool Equals(ElasticsearchDynamicValue compareValue) + { + if (ReferenceEquals(null, compareValue)) return false; + + return ReferenceEquals(this, compareValue) || Equals(compareValue.value, value); + } + public override bool TryGetMember(GetMemberBinder binder, out object result) { var name = binder.Name; @@ -26,96 +315,45 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) private bool Dispatch(out object result, string name) { - if (!this.HasValue) + if (!HasValue) { result = new ElasticsearchDynamicValue(null); return true; } - var d = this.Value as IDictionary; + var d = Value as IDictionary; object r; if (d != null && d.TryGetValue(name, out r)) { result = new ElasticsearchDynamicValue(r); return true; } - var x = this.Value as IDynamicMetaObjectProvider; + var x = Value as IDynamicMetaObjectProvider; if (x != null) { - var dm = GetDynamicMember(this.Value, name); + var dm = GetDynamicMember(Value, name); result = new ElasticsearchDynamicValue(dm); return true; } - var ds = this.Value as IDictionary; + var ds = Value as IDictionary; if (ds != null && ds.Contains(name)) { result = new ElasticsearchDynamicValue(ds[name]); return true; } - result = new ElasticsearchDynamicValue(this.Value); + result = new ElasticsearchDynamicValue(Value); return true; } - static object GetDynamicMember(object obj, string memberName) + private static object GetDynamicMember(object obj, string memberName) { - var binder = Binder.GetMember(CSharpBinderFlags.None, memberName, null, new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }); + var binder = Binder.GetMember(CSharpBinderFlags.None, memberName, null, + new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }); var callsite = CallSite>.Create(binder); return callsite.Target(callsite, obj); } - public ElasticsearchDynamicValue this[string name] - { - get - { - object r; - Dispatch(out r, name); - return (ElasticsearchDynamicValue) r; - } - } - - public ElasticsearchDynamicValue this[int i] - { - get - { - if (!this.HasValue) - return new ElasticsearchDynamicValue(null); - var l = this.Value as IList; - if (l != null && l.Count -1 >= i) - { - return new ElasticsearchDynamicValue(l[i]); - } - return new ElasticsearchDynamicValue(null); - } - } - - /// - /// Initializes a new instance of the class. - /// - /// The value to store in the instance - public ElasticsearchDynamicValue(object value) - { - this.value = value; - } - - /// - /// Gets a value indicating whether this instance has value. - /// - /// true if this instance has value; otherwise, false. - /// is considered as not being a value. - public bool HasValue - { - get { return (this.value != null); } - } - - /// - /// Gets the inner value - /// - public object Value - { - get { return this.value; } - } - /// /// Returns a default value if Value is null /// @@ -124,7 +362,7 @@ public object Value /// If value is not null, value is returned, else default value is returned public T Default(T defaultValue = default(T)) { - if (this.HasValue) + if (HasValue) { try { @@ -134,7 +372,7 @@ public object Value { var typeName = value.GetType().Name; var message = string.Format("Cannot convert value of type '{0}' to type '{1}'", - typeName, typeof(T).Name); + typeName, typeof(T).Name); throw new InvalidCastException(message); } @@ -149,16 +387,13 @@ public object Value /// When no default value is supplied, required to supply the default type /// Optional parameter for default value, if not given it returns default of type T /// If value is not null, value is returned, else default value is returned - public T TryParse(T defaultValue = default (T)) + public T TryParse(T defaultValue = default(T)) { - if (this.HasValue) + if (HasValue) { try { - if (value.GetType().IsAssignableFrom(typeof(T))) - { - return (T)value; - } + if (value.GetType().IsAssignableFrom(typeof(T))) return (T)value; var TType = typeof(T); @@ -167,10 +402,7 @@ public object Value { DateTime result; - if (DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out result)) - { - return (T)((object)result); - } + if (DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out result)) return (T)(object)result; } else if (stringValue != null) { @@ -179,16 +411,10 @@ public object Value #if DOTNETCORE return (T)converter.ConvertFromInvariantString(stringValue); #else - if (converter.IsValid(stringValue)) - { - return (T)converter.ConvertFromInvariantString(stringValue); - } + if (converter.IsValid(stringValue)) return (T)converter.ConvertFromInvariantString(stringValue); #endif } - else if (TType == typeof(string)) - { - return (T)Convert.ChangeType(value, TypeCode.String, CultureInfo.InvariantCulture); - } + else if (TType == typeof(string)) return (T)Convert.ChangeType(value, TypeCode.String, CultureInfo.InvariantCulture); } catch { @@ -201,111 +427,96 @@ public object Value public static bool operator ==(ElasticsearchDynamicValue dynamicValue, object compareValue) { - if (dynamicValue.value == null && compareValue == null) - { - return true; - } + if (dynamicValue.value == null && compareValue == null) return true; return dynamicValue.value != null && dynamicValue.value.Equals(compareValue); } - public static bool operator !=(ElasticsearchDynamicValue dynamicValue, object compareValue) - { - return !(dynamicValue == compareValue); - } - + public static bool operator !=(ElasticsearchDynamicValue dynamicValue, object compareValue) => !(dynamicValue == compareValue); /// - /// Indicates whether the current object is equal to another object of the same type. + /// Determines whether the specified is equal to the current . /// - /// true if the current object is equal to the parameter; otherwise, false. + /// + /// true if the specified is equal to the current ; otherwise, + /// false. /// - /// An to compare with this instance. - public bool Equals(ElasticsearchDynamicValue compareValue) - { - if (ReferenceEquals(null, compareValue)) - { - return false; - } - - return ReferenceEquals(this, compareValue) || Equals(compareValue.value, this.value); - } - - /// - /// Determines whether the specified is equal to the current . - /// - /// true if the specified is equal to the current ; otherwise, false. - /// The to compare with the current . + /// The to compare with the current . public override bool Equals(object compareValue) { - if (ReferenceEquals(null, compareValue)) - { - return false; - } + if (ReferenceEquals(null, compareValue)) return false; if (ReferenceEquals(this, compareValue) - || ReferenceEquals(this.value, compareValue) - || Equals(this.value, compareValue) - ) - { + || ReferenceEquals(value, compareValue) + || Equals(value, compareValue) + ) return true; - } - return compareValue.GetType() == typeof(ElasticsearchDynamicValue) && this.Equals((ElasticsearchDynamicValue)compareValue); + return compareValue.GetType() == typeof(ElasticsearchDynamicValue) && Equals((ElasticsearchDynamicValue)compareValue); } /// /// Serves as a hash function for a particular type. /// /// A hash code for the current instance. - public override int GetHashCode() - { - return (this.value != null ? this.value.GetHashCode() : 0); - } + public override int GetHashCode() => value != null ? value.GetHashCode() : 0; /// - /// Provides implementation for binary operations. Classes derived from the class can override this method to specify dynamic behavior for operations such as addition and multiplication. + /// Provides implementation for binary operations. Classes derived from the class can override + /// this method to specify dynamic behavior for operations such as addition and multiplication. /// - /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.) - /// Provides information about the binary operation. The binder.Operation property returns an object. For example, for the sum = first + second statement, where first and second are derived from the DynamicObject class, binder.Operation returns ExpressionType.Add.The right operand for the binary operation. For example, for the sum = first + second statement, where first and second are derived from the DynamicObject class, is equal to second.The result of the binary operation. + /// + /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of + /// the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.) + /// + /// + /// Provides information about the binary operation. The binder.Operation property returns an + /// object. For example, for the sum = first + second statement, where first and second + /// are derived from the DynamicObject class, binder.Operation returns ExpressionType.Add. + /// + /// + /// The right operand for the binary operation. For example, for the sum = first + second statement, where first and second + /// are derived from the DynamicObject class, is equal to second. + /// + /// The result of the binary operation. public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result) { object resultOfCast; result = null; - if (binder.Operation != ExpressionType.Equal) - { - return false; - } + if (binder.Operation != ExpressionType.Equal) return false; var convert = Binder.Convert(CSharpBinderFlags.None, arg.GetType(), typeof(ElasticsearchDynamicValue)); - if (!TryConvert((ConvertBinder)convert, out resultOfCast)) - { - return false; - } + if (!TryConvert((ConvertBinder)convert, out resultOfCast)) return false; - result = (resultOfCast == null) ? - Equals(arg, resultOfCast) : - resultOfCast.Equals(arg); + result = resultOfCast == null ? Equals(arg, resultOfCast) : resultOfCast.Equals(arg); return true; } /// - /// Provides implementation for type conversion operations. Classes derived from the class can override this method to specify dynamic behavior for operations that convert an object from one type to another. + /// Provides implementation for type conversion operations. Classes derived from the class can + /// override this method to specify dynamic behavior for operations that convert an object from one type to another. /// - /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.) - /// Provides information about the conversion operation. The binder.Type property provides the type to which the object must be converted. For example, for the statement (String)sampleObject in C# (CType(sampleObject, Type) in Visual Basic), where sampleObject is an instance of the class derived from the class, binder.Type returns the type. The binder.Explicit property provides information about the kind of conversion that occurs. It returns true for explicit conversion and false for implicit conversion.The result of the type conversion operation. + /// + /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of + /// the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.) + /// + /// + /// Provides information about the conversion operation. The binder.Type property provides the type to which the object + /// must be converted. For example, for the statement (String)sampleObject in C# (CType(sampleObject, Type) in Visual Basic), where + /// sampleObject is an instance of the class derived from the class, binder.Type returns the + /// type. The binder.Explicit property provides information about the kind of conversion that occurs. It returns + /// true for explicit conversion and false for implicit conversion. + /// + /// The result of the type conversion operation. public override bool TryConvert(ConvertBinder binder, out object result) { result = null; - if (value == null) - { - return true; - } + if (value == null) return true; var binderType = binder.Type; if (binderType == typeof(String)) @@ -335,9 +546,7 @@ public override bool TryConvert(ConvertBinder binder, out object result) else { if (binderType.IsGeneric() && binderType.GetGenericTypeDefinition() == typeof(Nullable<>)) - { binderType = binderType.GetGenericArguments()[0]; - } var typeCode = binderType.GetTypeCode(); @@ -349,9 +558,7 @@ public override bool TryConvert(ConvertBinder binder, out object result) return true; } else - { return false; - } } #if DOTNETCORE result = Convert.ChangeType(value, binderType); @@ -364,331 +571,78 @@ public override bool TryConvert(ConvertBinder binder, out object result) return base.TryConvert(binder, out result); } - public override string ToString() - { - return this.value == null ? base.ToString() : Convert.ToString(this.value); - } + public override string ToString() => value == null ? base.ToString() : Convert.ToString(value); public static implicit operator bool(ElasticsearchDynamicValue dynamicValue) { - if (!dynamicValue.HasValue) - { - return false; - } + if (!dynamicValue.HasValue) return false; - if (dynamicValue.value.GetType().IsValue()) - { - return (Convert.ToBoolean(dynamicValue.value)); - } + if (dynamicValue.value.GetType().IsValue()) return Convert.ToBoolean(dynamicValue.value); bool result; - if (bool.TryParse(dynamicValue.ToString(), out result)) - { - return result; - } + if (bool.TryParse(dynamicValue.ToString(), out result)) return result; return true; } - public static implicit operator string(ElasticsearchDynamicValue dynamicValue) - { - return dynamicValue.HasValue - ? Convert.ToString(dynamicValue.value) - : null; - } + public static implicit operator string(ElasticsearchDynamicValue dynamicValue) => dynamicValue.HasValue + ? Convert.ToString(dynamicValue.value) + : null; public static implicit operator int(ElasticsearchDynamicValue dynamicValue) { - if (dynamicValue.value.GetType().IsValue()) - { - return Convert.ToInt32(dynamicValue.value); - } + if (dynamicValue.value.GetType().IsValue()) return Convert.ToInt32(dynamicValue.value); return int.Parse(dynamicValue.ToString()); } public static implicit operator Guid(ElasticsearchDynamicValue dynamicValue) { - if (dynamicValue.value is Guid) - { - return (Guid)dynamicValue.value; - } + if (dynamicValue.value is Guid) return (Guid)dynamicValue.value; return Guid.Parse(dynamicValue.ToString()); } public static implicit operator DateTime(ElasticsearchDynamicValue dynamicValue) { - if (dynamicValue.value is DateTime) - { - return (DateTime)dynamicValue.value; - } + if (dynamicValue.value is DateTime) return (DateTime)dynamicValue.value; return DateTime.Parse(dynamicValue.ToString()); } public static implicit operator TimeSpan(ElasticsearchDynamicValue dynamicValue) { - if (dynamicValue.value is TimeSpan) - { - return (TimeSpan)dynamicValue.value; - } + if (dynamicValue.value is TimeSpan) return (TimeSpan)dynamicValue.value; return TimeSpan.Parse(dynamicValue.ToString()); } public static implicit operator long(ElasticsearchDynamicValue dynamicValue) { - if (dynamicValue.value.GetType().IsValue()) - { - return Convert.ToInt64(dynamicValue.value); - } + if (dynamicValue.value.GetType().IsValue()) return Convert.ToInt64(dynamicValue.value); return long.Parse(dynamicValue.ToString()); } public static implicit operator float(ElasticsearchDynamicValue dynamicValue) { - if (dynamicValue.value.GetType().IsValue()) - { - return Convert.ToSingle(dynamicValue.value); - } + if (dynamicValue.value.GetType().IsValue()) return Convert.ToSingle(dynamicValue.value); return float.Parse(dynamicValue.ToString()); } public static implicit operator decimal(ElasticsearchDynamicValue dynamicValue) { - if (dynamicValue.value.GetType().IsValue()) - { - return Convert.ToDecimal(dynamicValue.value); - } + if (dynamicValue.value.GetType().IsValue()) return Convert.ToDecimal(dynamicValue.value); return decimal.Parse(dynamicValue.ToString()); } public static implicit operator double(ElasticsearchDynamicValue dynamicValue) { - if (dynamicValue.value.GetType().IsValue()) - { - return Convert.ToDouble(dynamicValue.value); - } + if (dynamicValue.value.GetType().IsValue()) return Convert.ToDouble(dynamicValue.value); return double.Parse(dynamicValue.ToString()); } - -#region Implementation of IConvertible - - /// - /// Returns the for this instance. - /// - /// - /// The enumerated constant that is the of the class or value type that implements this interface. - /// - /// 2 - public TypeCode GetTypeCode() - { - if (value == null) return TypeCode.Empty; - return value.GetType().GetTypeCode(); - } - - /// - /// Converts the value of this instance to an equivalent Boolean value using the specified culture-specific formatting information. - /// - /// - /// A Boolean value equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public bool ToBoolean(IFormatProvider provider) - { - return Convert.ToBoolean(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent Unicode character using the specified culture-specific formatting information. - /// - /// - /// A Unicode character equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public char ToChar(IFormatProvider provider) - { - return Convert.ToChar(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent 8-bit signed integer using the specified culture-specific formatting information. - /// - /// - /// An 8-bit signed integer equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - [CLSCompliant(false)] - public sbyte ToSByte(IFormatProvider provider) - { - return Convert.ToSByte(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent 8-bit unsigned integer using the specified culture-specific formatting information. - /// - /// - /// An 8-bit unsigned integer equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public byte ToByte(IFormatProvider provider) - { - return Convert.ToByte(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent 16-bit signed integer using the specified culture-specific formatting information. - /// - /// - /// An 16-bit signed integer equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public short ToInt16(IFormatProvider provider) - { - return Convert.ToInt16(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent 16-bit unsigned integer using the specified culture-specific formatting information. - /// - /// - /// An 16-bit unsigned integer equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - [CLSCompliant(false)] - public ushort ToUInt16(IFormatProvider provider) - { - return Convert.ToUInt16(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent 32-bit signed integer using the specified culture-specific formatting information. - /// - /// - /// An 32-bit signed integer equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public int ToInt32(IFormatProvider provider) - { - return Convert.ToInt32(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent 32-bit unsigned integer using the specified culture-specific formatting information. - /// - /// - /// An 32-bit unsigned integer equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - [CLSCompliant(false)] - public uint ToUInt32(IFormatProvider provider) - { - return Convert.ToUInt32(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent 64-bit signed integer using the specified culture-specific formatting information. - /// - /// - /// An 64-bit signed integer equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public long ToInt64(IFormatProvider provider) - { - return Convert.ToInt64(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent 64-bit unsigned integer using the specified culture-specific formatting information. - /// - /// - /// An 64-bit unsigned integer equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - [CLSCompliant(false)] - public ulong ToUInt64(IFormatProvider provider) - { - return Convert.ToUInt64(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent single-precision floating-point number using the specified culture-specific formatting information. - /// - /// - /// A single-precision floating-point number equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public float ToSingle(IFormatProvider provider) - { - return Convert.ToSingle(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent double-precision floating-point number using the specified culture-specific formatting information. - /// - /// - /// A double-precision floating-point number equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public double ToDouble(IFormatProvider provider) - { - return Convert.ToDouble(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent number using the specified culture-specific formatting information. - /// - /// - /// A number equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public decimal ToDecimal(IFormatProvider provider) - { - return Convert.ToDecimal(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent using the specified culture-specific formatting information. - /// - /// - /// A instance equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public DateTime ToDateTime(IFormatProvider provider) - { - return Convert.ToDateTime(value, provider); - } - - /// - /// Converts the value of this instance to an equivalent using the specified culture-specific formatting information. - /// - /// - /// A instance equivalent to the value of this instance. - /// - /// An interface implementation that supplies culture-specific formatting information. 2 - public string ToString(IFormatProvider provider) - { - return Convert.ToString(value, provider); - } - - /// - /// Converts the value of this instance to an of the specified that has an equivalent value, using the specified culture-specific formatting information. - /// - /// - /// An instance of type whose value is equivalent to the value of this instance. - /// - /// The to which the value of this instance is converted. An interface implementation that supplies culture-specific formatting information. 2 - public object ToType(Type conversionType, IFormatProvider provider) - { - return Convert.ChangeType(value, conversionType, provider); - } - -#endregion - } } diff --git a/src/Elasticsearch.Net/Responses/ElasticsearchResponse.cs b/src/Elasticsearch.Net/Responses/ElasticsearchResponse.cs index 9d6f36548c7..c4f5f2784dc 100644 --- a/src/Elasticsearch.Net/Responses/ElasticsearchResponse.cs +++ b/src/Elasticsearch.Net/Responses/ElasticsearchResponse.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Elasticsearch.Net { @@ -11,44 +9,43 @@ namespace Elasticsearch.Net public abstract class ElasticsearchResponseBase : IApiCallDetails, IElasticsearchResponse { public IApiCallDetails ApiCall { get; set; } + public List AuditTrail => ApiCall.AuditTrail; - bool IElasticsearchResponse.TryGetServerErrorReason(out string reason) => this.TryGetServerErrorReason(out reason); - - protected virtual bool TryGetServerErrorReason(out string reason) - { - reason = null; - return false; - } - - //ignored - List IApiCallDetails.AuditTrail { get; set; } - - public bool Success => this.ApiCall.Success; - public string ResponseMimeType => this.ApiCall.ResponseMimeType; - public HttpMethod HttpMethod => this.ApiCall.HttpMethod; - public Uri Uri => this.ApiCall.Uri; - public int? HttpStatusCode => this.ApiCall.HttpStatusCode; - public List AuditTrail => this.ApiCall.AuditTrail; - public IEnumerable DeprecationWarnings => this.ApiCall.DeprecationWarnings; - public bool SuccessOrKnownError => this.ApiCall.SuccessOrKnownError; - public Exception OriginalException => this.ApiCall.OriginalException; + public string DebugInformation => ApiCall.DebugInformation; + public IEnumerable DeprecationWarnings => ApiCall.DeprecationWarnings; + public HttpMethod HttpMethod => ApiCall.HttpMethod; + public int? HttpStatusCode => ApiCall.HttpStatusCode; + public Exception OriginalException => ApiCall.OriginalException; /// The raw byte request message body, only set when DisableDirectStreaming() is set on Connection configuration - public byte[] RequestBodyInBytes => this.ApiCall.RequestBodyInBytes; + public byte[] RequestBodyInBytes => ApiCall.RequestBodyInBytes; /// The raw byte response message body, only set when DisableDirectStreaming() is set on Connection configuration - public byte[] ResponseBodyInBytes => this.ApiCall.ResponseBodyInBytes; + public byte[] ResponseBodyInBytes => ApiCall.ResponseBodyInBytes; - public string DebugInformation => this.ApiCall.DebugInformation; + public string ResponseMimeType => ApiCall.ResponseMimeType; - public override string ToString() => this.ApiCall.ToString(); + public bool Success => ApiCall.Success; + public bool SuccessOrKnownError => ApiCall.SuccessOrKnownError; + public Uri Uri => ApiCall.Uri; + //ignored + List IApiCallDetails.AuditTrail { get; set; } + + bool IElasticsearchResponse.TryGetServerErrorReason(out string reason) => TryGetServerErrorReason(out reason); + + protected virtual bool TryGetServerErrorReason(out string reason) + { + reason = null; + return false; + } + public override string ToString() => ApiCall.ToString(); } /// /// A response from Elasticsearch including details about the request/response life cycle. Base class for the built in low level response - /// types: and + /// types: and /// public abstract class ElasticsearchResponse : ElasticsearchResponseBase { diff --git a/src/Elasticsearch.Net/Responses/HttpDetails/ApiCallDetails.cs b/src/Elasticsearch.Net/Responses/HttpDetails/ApiCallDetails.cs index e371c8867dc..ac9bc288132 100644 --- a/src/Elasticsearch.Net/Responses/HttpDetails/ApiCallDetails.cs +++ b/src/Elasticsearch.Net/Responses/HttpDetails/ApiCallDetails.cs @@ -6,35 +6,36 @@ namespace Elasticsearch.Net { public class ApiCallDetails : IApiCallDetails { - public bool Success { get; set; } - public string ResponseMimeType { get; set; } - public Exception OriginalException { get; set; } - public ServerError ServerError { get; set; } - public HttpMethod HttpMethod { get; set; } - public Uri Uri { get; set; } - public int? HttpStatusCode { get; set; } - public bool SuccessOrKnownError => - this.Success || ( - HttpStatusCode >= 400 && HttpStatusCode < 599 - && HttpStatusCode != 504 //Gateway timeout needs to be retried - && HttpStatusCode != 503 //service unavailable needs to be retried - && HttpStatusCode != 502 //bad gateway needs to be retried - ); - public byte[] ResponseBodyInBytes { get; set; } - public byte[] RequestBodyInBytes { get; set; } public List AuditTrail { get; set; } - public IEnumerable DeprecationWarnings { get; set; } public string DebugInformation { get { var sb = new StringBuilder(); - sb.AppendLine(this.ToString()); + sb.AppendLine(ToString()); return ResponseStatics.DebugInformationBuilder(this, sb); } } + public IEnumerable DeprecationWarnings { get; set; } + public HttpMethod HttpMethod { get; set; } + public int? HttpStatusCode { get; set; } + public Exception OriginalException { get; set; } + public byte[] RequestBodyInBytes { get; set; } + public byte[] ResponseBodyInBytes { get; set; } + public string ResponseMimeType { get; set; } + public ServerError ServerError { get; set; } + public bool Success { get; set; } + + public bool SuccessOrKnownError => + Success || HttpStatusCode >= 400 && HttpStatusCode < 599 + && HttpStatusCode != 504 //Gateway timeout needs to be retried + && HttpStatusCode != 503 //service unavailable needs to be retried + && HttpStatusCode != 502; + + public Uri Uri { get; set; } + public override string ToString() => $"{(Success ? "S" : "Uns")}uccessful low level call on {HttpMethod.GetStringValue()}: {Uri.PathAndQuery}"; } diff --git a/src/Elasticsearch.Net/Responses/HttpDetails/IApiCallDetails.cs b/src/Elasticsearch.Net/Responses/HttpDetails/IApiCallDetails.cs index d055e4490ef..6766b1df821 100644 --- a/src/Elasticsearch.Net/Responses/HttpDetails/IApiCallDetails.cs +++ b/src/Elasticsearch.Net/Responses/HttpDetails/IApiCallDetails.cs @@ -6,19 +6,23 @@ namespace Elasticsearch.Net { public interface IApiCallDetails { + //TODO Get rid of setter /// - /// The response status code is in the 200 range or is in the allowed list of status codes set on the request. + /// An audit trail of requests made to nodes within the cluster /// - bool Success { get; } + List AuditTrail { get; set; } - /// The response mime type - string ResponseMimeType { get; } + /// + /// A lazy human readable string representation of what happened during this request for both successful and + /// failed requests. + /// + string DebugInformation { get; } /// - /// If is false, this will hold the original exception. - /// This will be the orginating CLR exception in most cases. + /// A collection of deprecation warnings returned from Elasticsearch. + /// Used to signal that the request uses an API feature that is marked as deprecated /// - Exception OriginalException { get; } + IEnumerable DeprecationWarnings { get; } /// /// The HTTP method used by the request @@ -26,51 +30,47 @@ public interface IApiCallDetails HttpMethod HttpMethod { get; } /// - /// The url as requested + /// The HTTP status code as returned by Elasticsearch /// - Uri Uri { get; } + int? HttpStatusCode { get; } /// - /// The HTTP status code as returned by Elasticsearch + /// If is false, this will hold the original exception. + /// This will be the orginating CLR exception in most cases. /// - int? HttpStatusCode { get; } + Exception OriginalException { get; } /// - /// The response is successful or has a response code between 400-599, the call should not be retried. - /// Only on 502,503 and 504 will this return false; + /// The request body bytes. + /// NOTE: Only set when disable direct streaming is set for the request /// - bool SuccessOrKnownError { get; } + [DebuggerDisplay("{RequestBodyInBytes != null ? System.Text.Encoding.UTF8.GetString(RequestBodyInBytes) : null,nq}")] + byte[] RequestBodyInBytes { get; } - /// - /// The response body bytes. - /// NOTE: Only set when disable direct streaming is set for the request - /// - [DebuggerDisplay("{ResponseBodyInBytes != null ? System.Text.Encoding.UTF8.GetString(ResponseBodyInBytes) : null,nq}")] + /// + /// The response body bytes. + /// NOTE: Only set when disable direct streaming is set for the request + /// + [DebuggerDisplay("{ResponseBodyInBytes != null ? System.Text.Encoding.UTF8.GetString(ResponseBodyInBytes) : null,nq}")] byte[] ResponseBodyInBytes { get; } - /// - /// The request body bytes. - /// NOTE: Only set when disable direct streaming is set for the request - /// - [DebuggerDisplay("{RequestBodyInBytes != null ? System.Text.Encoding.UTF8.GetString(RequestBodyInBytes) : null,nq}")] - byte[] RequestBodyInBytes { get; } + /// The response mime type + string ResponseMimeType { get; } - //TODO Get rid of setter - /// - /// An audit trail of requests made to nodes within the cluster - /// - List AuditTrail { get; set; } + /// + /// The response status code is in the 200 range or is in the allowed list of status codes set on the request. + /// + bool Success { get; } - /// - /// A lazy human readable string representation of what happened during this request for both successful and - /// failed requests. - /// - string DebugInformation { get; } + /// + /// The response is successful or has a response code between 400-599, the call should not be retried. + /// Only on 502,503 and 504 will this return false; + /// + bool SuccessOrKnownError { get; } - /// - ///A collection of deprecation warnings returned from Elasticsearch. - ///Used to signal that the request uses an API feature that is marked as deprecated - /// - IEnumerable DeprecationWarnings { get; } + /// + /// The url as requested + /// + Uri Uri { get; } } } diff --git a/src/Elasticsearch.Net/Responses/IElasticsearchResponse.cs b/src/Elasticsearch.Net/Responses/IElasticsearchResponse.cs index dc1f0e9eb0c..2991010d36c 100644 --- a/src/Elasticsearch.Net/Responses/IElasticsearchResponse.cs +++ b/src/Elasticsearch.Net/Responses/IElasticsearchResponse.cs @@ -7,7 +7,7 @@ namespace Elasticsearch.Net public interface IElasticsearchResponse { /// - /// Sets and returns the diagnostic information + /// Sets and returns the diagnostic information /// IApiCallDetails ApiCall { get; set; } diff --git a/src/Elasticsearch.Net/Responses/ResponseStatics.cs b/src/Elasticsearch.Net/Responses/ResponseStatics.cs index 4d1b72654b7..e8914f18f93 100644 --- a/src/Elasticsearch.Net/Responses/ResponseStatics.cs +++ b/src/Elasticsearch.Net/Responses/ResponseStatics.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,14 +6,18 @@ namespace Elasticsearch.Net { public static class ResponseStatics { - private static readonly string ResponseAlreadyCaptured = ""; - private static readonly string RequestAlreadyCaptured = ""; + private static readonly string RequestAlreadyCaptured = + ""; + + private static readonly string ResponseAlreadyCaptured = + ""; + public static string DebugInformationBuilder(IApiCallDetails r, StringBuilder sb) { if (r.DeprecationWarnings.HasAny()) { sb.AppendLine($"# Server indicated deprecations:"); - foreach(var deprecation in r.DeprecationWarnings) + foreach (var deprecation in r.DeprecationWarnings) sb.AppendLine($"- {deprecation}"); } sb.AppendLine($"# Audit trail of this API call:"); @@ -24,8 +26,8 @@ public static string DebugInformationBuilder(IApiCallDetails r, StringBuilder sb if (r.OriginalException != null) sb.AppendLine($"# OriginalException: {r.OriginalException}"); DebugAuditTrailExceptions(auditTrail, sb); - var response = r.ResponseBodyInBytes?.Utf8String() ?? ResponseStatics.ResponseAlreadyCaptured; - var request = r.RequestBodyInBytes?.Utf8String() ?? ResponseStatics.RequestAlreadyCaptured; + var response = r.ResponseBodyInBytes?.Utf8String() ?? ResponseAlreadyCaptured; + var request = r.RequestBodyInBytes?.Utf8String() ?? RequestAlreadyCaptured; sb.AppendLine($"# Request:\r\n{request}"); sb.AppendLine($"# Response:\r\n{response}"); @@ -34,7 +36,7 @@ public static string DebugInformationBuilder(IApiCallDetails r, StringBuilder sb public static void DebugAuditTrailExceptions(List auditTrail, StringBuilder sb) { - var auditExceptions = auditTrail.Select((audit, i) => new {audit, i}).Where(a => a.audit.Exception != null); + var auditExceptions = auditTrail.Select((audit, i) => new { audit, i }).Where(a => a.audit.Exception != null); foreach (var a in auditExceptions) sb.AppendLine($"# Audit exception in step {a.i + 1} {a.audit.Event.GetStringValue()}:\r\n{a.audit.Exception}"); } @@ -42,7 +44,8 @@ public static void DebugAuditTrailExceptions(List auditTrail, StringBuild public static void DebugAuditTrail(List auditTrail, StringBuilder sb) { if (auditTrail == null) return; - foreach (var a in auditTrail.Select((a, i)=> new { a, i })) + + foreach (var a in auditTrail.Select((a, i) => new { a, i })) { var audit = a.a; sb.Append($" - [{a.i + 1}] {audit.Event.GetStringValue()}:"); diff --git a/src/Elasticsearch.Net/Responses/ServerException/Error.cs b/src/Elasticsearch.Net/Responses/ServerException/Error.cs index 6ed44dd7c92..218b21f5f35 100644 --- a/src/Elasticsearch.Net/Responses/ServerException/Error.cs +++ b/src/Elasticsearch.Net/Responses/ServerException/Error.cs @@ -9,21 +9,21 @@ public class Error : ErrorCause private static readonly IReadOnlyDictionary DefaultHeaders = new ReadOnlyDictionary(new Dictionary(0)); - public IReadOnlyCollection RootCause { get; set; } - public IReadOnlyDictionary Headers { get; set; } = DefaultHeaders; + public IReadOnlyCollection RootCause { get; set; } + internal static Error CreateError(IDictionary dict, IJsonSerializerStrategy strategy) { var error = new Error(); error.FillValues(dict); if (dict.TryGetValue("caused_by", out var causedBy)) - error.CausedBy = (ErrorCause) strategy.DeserializeObject(causedBy, typeof(ErrorCause)); + error.CausedBy = (ErrorCause)strategy.DeserializeObject(causedBy, typeof(ErrorCause)); if (dict.TryGetValue("headers", out var headers)) { - var d = (IDictionary) strategy.DeserializeObject(headers, typeof(IDictionary)); + var d = (IDictionary)strategy.DeserializeObject(headers, typeof(IDictionary)); if (d != null) error.Headers = new ReadOnlyDictionary(d); } @@ -37,7 +37,8 @@ private static Error ReadRootCause(IDictionary dict, IJsonSerial if (!dict.TryGetValue("root_cause", out var rootCause)) return error; if (!(rootCause is object[] os)) return error; - error.RootCause = os.Select(o => (ErrorCause) strategy.DeserializeObject(o, typeof(ErrorCause))).ToList().AsReadOnly(); + + error.RootCause = os.Select(o => (ErrorCause)strategy.DeserializeObject(o, typeof(ErrorCause))).ToList().AsReadOnly(); return error; } } diff --git a/src/Elasticsearch.Net/Responses/ServerException/ErrorCause.cs b/src/Elasticsearch.Net/Responses/ServerException/ErrorCause.cs index d262a0dacae..9afc9b4c386 100644 --- a/src/Elasticsearch.Net/Responses/ServerException/ErrorCause.cs +++ b/src/Elasticsearch.Net/Responses/ServerException/ErrorCause.cs @@ -6,11 +6,11 @@ namespace Elasticsearch.Net { public class ErrorCause { - public string Reason { get; set; } - public string Type { get; set; } public ErrorCause CausedBy { get; set; } - public string StackTrace { get; set; } public ErrorCauseMetadata Metadata { get; set; } + public string Reason { get; set; } + public string StackTrace { get; set; } + public string Type { get; set; } internal static ErrorCause CreateErrorCause(IDictionary dict, IJsonSerializerStrategy strategy) { @@ -24,9 +24,9 @@ internal static ErrorCause CreateErrorCause(IDictionary dict, IJ return causedBy; } - public override string ToString() => this.CausedBy == null - ? $"Type: {this.Type} Reason: \"{this.Reason}\"" - : $"Type: {this.Type} Reason: \"{this.Reason}\" CausedBy: \"{this.CausedBy}\""; + public override string ToString() => CausedBy == null + ? $"Type: {Type} Reason: \"{Reason}\"" + : $"Type: {Type} Reason: \"{Reason}\" CausedBy: \"{CausedBy}\""; public class ErrorCauseMetadata { @@ -36,31 +36,32 @@ public class ErrorCauseMetadata private static readonly IReadOnlyCollection DefaultFailedShards = new ReadOnlyCollection(new ShardFailure[0] { }); - public string LicensedExpiredFeature { get; set; } + public long? BytesLimit { get; set; } + + public long? BytesWanted { get; set; } + public int? Column { get; set; } + + public IReadOnlyCollection FailedShards { get; set; } = DefaultFailedShards; + public bool? Grouped { get; set; } public string Index { get; set; } public string IndexUUID { get; set; } - public string ResourceType { get; set; } - public IReadOnlyCollection ResourceId { get; set; } = DefaultCollection; - public int? Shard { get; set; } + public string Language { get; set; } - public IReadOnlyCollection FailedShards { get; set; } = DefaultFailedShards; + public string LicensedExpiredFeature { get; set; } public int? Line { get; set; } - public int? Column { get; set; } - - public long? BytesWanted { get; set; } - public long? BytesLimit { get; set; } public string Phase { get; set; } - public bool? Grouped { get; set; } + public IReadOnlyCollection ResourceId { get; set; } = DefaultCollection; + public string ResourceType { get; set; } + public string Script { get; set; } public IReadOnlyCollection ScriptStack { get; set; } = DefaultCollection; - public string Script { get; set; } - public string Language { get; set; } + public int? Shard { get; set; } - internal static ErrorCauseMetadata CreateCauseMetadata(IDictionary dict, IJsonSerializerStrategy strategy) - { - var m = new ErrorCauseMetadata(); + internal static ErrorCauseMetadata CreateCauseMetadata(IDictionary dict, IJsonSerializerStrategy strategy) + { + var m = new ErrorCauseMetadata(); if (dict.TryGetValue("license.expired.feature", out var feature)) m.LicensedExpiredFeature = Convert.ToString(feature); if (dict.TryGetValue("index", out var index)) m.Index = Convert.ToString(index); if (dict.TryGetValue("index_uuid", out var indexUUID)) m.IndexUUID = Convert.ToString(indexUUID); @@ -80,10 +81,10 @@ internal static ErrorCauseMetadata CreateCauseMetadata(IDictionary GetShardFailures(object value,IJsonSerializerStrategy strategy) + private static IReadOnlyCollection GetShardFailures(object value, IJsonSerializerStrategy strategy) { if (!(value is object[] objects)) return DefaultFailedShards; @@ -91,15 +92,16 @@ private static IReadOnlyCollection GetShardFailures(object value,I var values = new List(); foreach (var v in objects) { - var cause = (ShardFailure) strategy.DeserializeObject(v, typeof(ShardFailure)); + var cause = (ShardFailure)strategy.DeserializeObject(v, typeof(ShardFailure)); if (cause != null) values.Add(cause); } return new ReadOnlyCollection(values.ToArray()); } - private static IReadOnlyCollection GetStringArray(object value,IJsonSerializerStrategy strategy) + private static IReadOnlyCollection GetStringArray(object value, IJsonSerializerStrategy strategy) { - if (value is string s) return new ReadOnlyCollection(new [] {s}); + if (value is string s) return new ReadOnlyCollection(new[] { s }); + if (value is object[] objects) { var values = new List(); @@ -110,7 +112,6 @@ private static IReadOnlyCollection GetStringArray(object value,IJsonSeri return new ReadOnlyCollection(values.ToArray()); } return DefaultCollection; - } } } diff --git a/src/Elasticsearch.Net/Responses/ServerException/ErrorCauseExtensions.cs b/src/Elasticsearch.Net/Responses/ServerException/ErrorCauseExtensions.cs index e3d638d6d71..7e546f2b742 100644 --- a/src/Elasticsearch.Net/Responses/ServerException/ErrorCauseExtensions.cs +++ b/src/Elasticsearch.Net/Responses/ServerException/ErrorCauseExtensions.cs @@ -8,6 +8,7 @@ internal static class ErrorCauseExtensions public static void FillValues(this ErrorCause rootCause, IDictionary dict) { if (dict == null) return; + if (dict.TryGetValue("reason", out var reason)) rootCause.Reason = Convert.ToString(reason); if (dict.TryGetValue("type", out var type)) rootCause.Type = Convert.ToString(type); if (dict.TryGetValue("stack_trace", out var stackTrace)) rootCause.StackTrace = Convert.ToString(stackTrace); diff --git a/src/Elasticsearch.Net/Responses/ServerException/ServerError.cs b/src/Elasticsearch.Net/Responses/ServerException/ServerError.cs index d48cbd0caf5..c3c2822af61 100644 --- a/src/Elasticsearch.Net/Responses/ServerException/ServerError.cs +++ b/src/Elasticsearch.Net/Responses/ServerException/ServerError.cs @@ -11,8 +11,8 @@ public class ServerError { public ServerError(Error error, int? statusCode) { - this.Error = error; - this.Status = statusCode.GetValueOrDefault(); + Error = error; + Status = statusCode.GetValueOrDefault(); } public Error Error { get; } @@ -32,12 +32,11 @@ internal static ServerError Create(IDictionary dict, IJsonSerial statusCode = Convert.ToInt32(status); if (!dict.TryGetValue("error", out var error)) return null; + Error err; if (error is string s) - { - err = new Error {Reason = s}; - } - else err = (Error) strategy.DeserializeObject(error, typeof(Error)); + err = new Error { Reason = s }; + else err = (Error)strategy.DeserializeObject(error, typeof(Error)); return new ServerError(err, statusCode); } diff --git a/src/Elasticsearch.Net/Responses/ServerException/ShardFailure.cs b/src/Elasticsearch.Net/Responses/ServerException/ShardFailure.cs index 4d0f6c532c4..75178d2b626 100644 --- a/src/Elasticsearch.Net/Responses/ServerException/ShardFailure.cs +++ b/src/Elasticsearch.Net/Responses/ServerException/ShardFailure.cs @@ -5,10 +5,10 @@ namespace Elasticsearch.Net { public class ShardFailure { - public ErrorCause Reason { get; set; } - public int? Shard { get; set; } public string Index { get; set; } public string Node { get; set; } + public ErrorCause Reason { get; set; } + public int? Shard { get; set; } public string Status { get; set; } internal static ShardFailure CreateShardFailure(IDictionary dict, IJsonSerializerStrategy strategy) @@ -20,10 +20,10 @@ internal static ShardFailure CreateShardFailure(IDictionary dict if (dict.TryGetValue("status", out var status)) f.Status = Convert.ToString(status); if (dict.TryGetValue("reason", out var reason)) { - var cause = (ErrorCause) strategy.DeserializeObject(reason, typeof(ErrorCause)); + var cause = (ErrorCause)strategy.DeserializeObject(reason, typeof(ErrorCause)); f.Reason = cause; } return f; } } -} \ No newline at end of file +} diff --git a/src/Elasticsearch.Net/Responses/Sniff/SniffResponse.cs b/src/Elasticsearch.Net/Responses/Sniff/SniffResponse.cs index 17c831b3ba2..9e9d4146970 100644 --- a/src/Elasticsearch.Net/Responses/Sniff/SniffResponse.cs +++ b/src/Elasticsearch.Net/Responses/Sniff/SniffResponse.cs @@ -13,6 +13,7 @@ public static class SniffParser public static Uri ParseToUri(string boundAddress, bool forceHttp) { if (boundAddress == null) throw new ArgumentNullException(nameof(boundAddress)); + var suffix = forceHttp ? "s" : string.Empty; var match = AddressRegex.Match(boundAddress); if (!match.Success) throw new Exception($"Can not parse bound_address: {boundAddress} to Uri"); @@ -62,29 +63,31 @@ public IEnumerable ToNodes(bool forceHttp = false) internal class NodeInfo { - public string name { get; set; } - public string transport_address { get; set; } + public string build_hash { get; set; } public string host { get; set; } + public NodeInfoHttp http { get; set; } public string ip { get; set; } - public string version { get; set; } - public string build_hash { get; set; } + public string name { get; set; } public IList roles { get; set; } - public NodeInfoHttp http { get; set; } public IDictionary settings { get; set; } - - internal bool MasterEligible => this.roles?.Contains("master") ?? false; - internal bool HoldsData => this.roles?.Contains("data") ?? false; - internal bool IngestEnabled => this.roles?.Contains("ingest") ?? false; + public string transport_address { get; set; } + public string version { get; set; } + internal bool HoldsData => roles?.Contains("data") ?? false; internal bool HttpEnabled { get { - if (this.settings != null && this.settings.ContainsKey("http.enabled")) - return Convert.ToBoolean(this.settings["http.enabled"]); + if (settings != null && settings.ContainsKey("http.enabled")) + return Convert.ToBoolean(settings["http.enabled"]); + return http != null; } } + + internal bool IngestEnabled => roles?.Contains("ingest") ?? false; + + internal bool MasterEligible => roles?.Contains("master") ?? false; } internal class NodeInfoHttp diff --git a/src/Elasticsearch.Net/Responses/Special/BytesResponse.cs b/src/Elasticsearch.Net/Responses/Special/BytesResponse.cs index 43879c879b6..8f6895822eb 100644 --- a/src/Elasticsearch.Net/Responses/Special/BytesResponse.cs +++ b/src/Elasticsearch.Net/Responses/Special/BytesResponse.cs @@ -1,18 +1,19 @@ using System.IO; -using System.Text; namespace Elasticsearch.Net { public class BytesResponse : ElasticsearchResponse { public BytesResponse() { } - public BytesResponse(byte[] body) => this.Body = body; + + public BytesResponse(byte[] body) => Body = body; public bool TryGetServerError(out ServerError serverError) { serverError = null; - if (this.Body == null || this.Body.Length == 0) return false; - using(var stream = new MemoryStream(this.Body)) + if (Body == null || Body.Length == 0) return false; + + using (var stream = new MemoryStream(Body)) serverError = ServerError.Create(stream); return true; } @@ -20,7 +21,8 @@ public bool TryGetServerError(out ServerError serverError) protected override bool TryGetServerErrorReason(out string reason) { reason = null; - if (!this.TryGetServerError(out var serverError)) return false; + if (!TryGetServerError(out var serverError)) return false; + reason = serverError?.Error?.ToString(); return !reason.IsNullOrEmpty(); } diff --git a/src/Elasticsearch.Net/Responses/Special/StringResponse.cs b/src/Elasticsearch.Net/Responses/Special/StringResponse.cs index 8077ef10ed8..bb9201d3a2d 100644 --- a/src/Elasticsearch.Net/Responses/Special/StringResponse.cs +++ b/src/Elasticsearch.Net/Responses/Special/StringResponse.cs @@ -6,13 +6,15 @@ namespace Elasticsearch.Net public class StringResponse : ElasticsearchResponse { public StringResponse() { } - public StringResponse(string body) => this.Body = body; + + public StringResponse(string body) => Body = body; public bool TryGetServerError(out ServerError serverError) { serverError = null; - if (string.IsNullOrEmpty(this.Body)) return false; - using(var stream = new MemoryStream(Encoding.UTF8.GetBytes(this.Body))) + if (string.IsNullOrEmpty(Body)) return false; + + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(Body))) serverError = ServerError.Create(stream); return true; } @@ -20,7 +22,8 @@ public bool TryGetServerError(out ServerError serverError) protected override bool TryGetServerErrorReason(out string reason) { reason = null; - if (!this.TryGetServerError(out var serverError)) return false; + if (!TryGetServerError(out var serverError)) return false; + reason = serverError?.Error?.ToString(); return !reason.IsNullOrEmpty(); } diff --git a/src/Elasticsearch.Net/Responses/Special/VoidResponse.cs b/src/Elasticsearch.Net/Responses/Special/VoidResponse.cs index abfc537dece..69e0d95fc4d 100644 --- a/src/Elasticsearch.Net/Responses/Special/VoidResponse.cs +++ b/src/Elasticsearch.Net/Responses/Special/VoidResponse.cs @@ -1,10 +1,7 @@ -using System; - -namespace Elasticsearch.Net +namespace Elasticsearch.Net { public class VoidResponse : ElasticsearchResponse { public class VoidBody { } - } } diff --git a/src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs b/src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs index 53319f708bf..1d7f2db0e35 100644 --- a/src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs +++ b/src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs @@ -15,7 +15,7 @@ public override bool TrySerializeNonPrimitiveObject(object input, out object out return base.TrySerializeNonPrimitiveObject(input, out output); var e = input as Exception; - var exceptionsJson = this.FlattenExceptions(e).ToList(); + var exceptionsJson = FlattenExceptions(e).ToList(); var array = new JsonArray(exceptionsJson.Count); array.AddRange(exceptionsJson); output = array; @@ -31,9 +31,9 @@ private IEnumerable FlattenExceptions(Exception e) var o = ToExceptionJsonObject(e, depth); depth++; yield return o; + e = e.InnerException; - } - while (depth < maxExceptions && e != null); + } while (depth < maxExceptions && e != null); } private JsonObject ToExceptionJsonObject(Exception e, int depth) @@ -124,16 +124,17 @@ public override object DeserializeObject(object value, Type type) } if (type == typeof(Error)) { - if (value is string s) - return new Error {Reason = s}; + if (value is string s) + return new Error { Reason = s }; var dict = base.DeserializeObject(value, typeof(IDictionary)) as IDictionary; return Error.CreateError(dict, this); } if (type == typeof(ErrorCause)) { - if (value is string s) - return new ErrorCause {Reason = s}; + if (value is string s) + return new ErrorCause { Reason = s }; + var dict = base.DeserializeObject(value, typeof(IDictionary)) as IDictionary; return ErrorCause.CreateErrorCause(dict, this); } diff --git a/src/Elasticsearch.Net/Serialization/ElasticsearchUrlFormatter.cs b/src/Elasticsearch.Net/Serialization/ElasticsearchUrlFormatter.cs index b39710d644f..3d39068c22a 100644 --- a/src/Elasticsearch.Net/Serialization/ElasticsearchUrlFormatter.cs +++ b/src/Elasticsearch.Net/Serialization/ElasticsearchUrlFormatter.cs @@ -12,28 +12,27 @@ public class ElasticsearchUrlFormatter : IFormatProvider, ICustomFormatter { private readonly IConnectionConfigurationValues _settings; - public ElasticsearchUrlFormatter(IConnectionConfigurationValues settings) - { - _settings = settings; - } - - public object GetFormat(Type formatType) => formatType == typeof(ICustomFormatter) ? this : null; + public ElasticsearchUrlFormatter(IConnectionConfigurationValues settings) => _settings = settings; public string Format(string format, object arg, IFormatProvider formatProvider) { if (arg == null) throw new ArgumentNullException(); + if (format == "r") return arg.ToString(); - var value = CreateString(arg, this._settings); + + var value = CreateString(arg, _settings); return value.IsNullOrEmpty() ? string.Empty : Uri.EscapeDataString(value); } + public object GetFormat(Type formatType) => formatType == typeof(ICustomFormatter) ? this : null; + public string CreateEscapedString(object value) { - var r = CreateString(value, this._settings); + var r = CreateString(value, _settings); return r.IsNullOrEmpty() ? string.Empty : Uri.EscapeDataString(r); } - public string CreateString(object value) => CreateString(value, this._settings); + public string CreateString(object value) => CreateString(value, _settings); public static string CreateString(object value, IConnectionConfigurationValues settings) { @@ -46,7 +45,7 @@ public static string CreateString(object value, IConnectionConfigurationValues s case bool b: return b ? "true" : "false"; case DateTimeOffset offset: return offset.ToString("o"); case IEnumerable pns: - return string.Join(",", pns.Select(o=> ResolveUrlParameterOrDefault(o, settings))); + return string.Join(",", pns.Select(o => ResolveUrlParameterOrDefault(o, settings))); case TimeSpan timeSpan: return timeSpan.ToTimeUnit(); default: return ResolveUrlParameterOrDefault(value, settings); diff --git a/src/Elasticsearch.Net/Serialization/IElasticsearchSerializer.cs b/src/Elasticsearch.Net/Serialization/IElasticsearchSerializer.cs index 141d6892336..6b013f7d1e8 100644 --- a/src/Elasticsearch.Net/Serialization/IElasticsearchSerializer.cs +++ b/src/Elasticsearch.Net/Serialization/IElasticsearchSerializer.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -19,13 +18,15 @@ public interface IElasticsearchSerializer void Serialize(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.Indented); Task SerializeAsync(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.Indented, - CancellationToken cancellationToken = default(CancellationToken)); + CancellationToken cancellationToken = default(CancellationToken) + ); } public static class ElasticsearchSerializerExtensions { - - public static byte[] SerializeToBytes(this IElasticsearchSerializer serializer, T data, SerializationFormatting formatting = SerializationFormatting.Indented) + public static byte[] SerializeToBytes(this IElasticsearchSerializer serializer, T data, + SerializationFormatting formatting = SerializationFormatting.Indented + ) { using (var ms = new MemoryStream()) { @@ -33,7 +34,10 @@ public static byte[] SerializeToBytes(this IElasticsearchSerializer serialize return ms.ToArray(); } } - public static string SerializeToString(this IElasticsearchSerializer serializer, T data, SerializationFormatting formatting = SerializationFormatting.Indented) => + + public static string SerializeToString(this IElasticsearchSerializer serializer, T data, + SerializationFormatting formatting = SerializationFormatting.Indented + ) => serializer.SerializeToBytes(data, formatting).Utf8String(); } } diff --git a/src/Elasticsearch.Net/Serialization/IUrlParameter.cs b/src/Elasticsearch.Net/Serialization/IUrlParameter.cs index e84760eb28b..2a77927ee68 100644 --- a/src/Elasticsearch.Net/Serialization/IUrlParameter.cs +++ b/src/Elasticsearch.Net/Serialization/IUrlParameter.cs @@ -4,4 +4,4 @@ public interface IUrlParameter { string GetString(IConnectionConfigurationValues settings); } -} \ No newline at end of file +} diff --git a/src/Elasticsearch.Net/Serialization/LowLevelRequestResponseSerializer.cs b/src/Elasticsearch.Net/Serialization/LowLevelRequestResponseSerializer.cs index 42a9bcda2f8..223af56a4a5 100644 --- a/src/Elasticsearch.Net/Serialization/LowLevelRequestResponseSerializer.cs +++ b/src/Elasticsearch.Net/Serialization/LowLevelRequestResponseSerializer.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Linq; -using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -9,27 +8,26 @@ namespace Elasticsearch.Net { public class LowLevelRequestResponseSerializer : IElasticsearchSerializer { + private const int BufferSize = 81920; public static readonly LowLevelRequestResponseSerializer Instance = new LowLevelRequestResponseSerializer(); private static readonly ElasticsearchNetJsonStrategy Strategy = new ElasticsearchNetJsonStrategy(); - private const int BufferSize = 81920; - - private static object Default(Type type) => type.IsValueType() ? type.CreateInstance() : null; public object Deserialize(Type type, Stream stream) { if (stream == null) return Default(type); using (var ms = new MemoryStream()) - using(stream) + using (stream) { stream.CopyTo(ms); var buffer = ms.ToArray(); if (buffer.Length <= 1) return Default(type); + return SimpleJson.DeserializeObject(buffer.Utf8String(), type, Strategy); } } - public T Deserialize(Stream stream) => (T) this.Deserialize(typeof(T), stream); + public T Deserialize(Stream stream) => (T)Deserialize(typeof(T), stream); public async Task DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default(CancellationToken)) { @@ -41,6 +39,7 @@ public object Deserialize(Type type, Stream stream) await stream.CopyToAsync(ms, BufferSize, cancellationToken).ConfigureAwait(false); var buffer = ms.ToArray(); if (buffer.Length <= 1) return Default(type); + var r = SimpleJson.DeserializeObject(buffer.Utf8String(), type, Strategy); return r; } @@ -48,36 +47,30 @@ public object Deserialize(Type type, Stream stream) public async Task DeserializeAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken)) { - var o = await this.DeserializeAsync(typeof(T), stream, cancellationToken).ConfigureAwait(false); - return (T) o; + var o = await DeserializeAsync(typeof(T), stream, cancellationToken).ConfigureAwait(false); + return (T)o; } public void Serialize(T data, Stream writableStream, SerializationFormatting formatting = SerializationFormatting.Indented) { var serialized = SimpleJson.SerializeObject(data, Strategy); if (formatting == SerializationFormatting.None) serialized = RemoveNewLinesAndTabs(serialized); - using (var ms = new MemoryStream(serialized.Utf8Bytes())) - { - ms.CopyTo(writableStream); - } + using (var ms = new MemoryStream(serialized.Utf8Bytes())) ms.CopyTo(writableStream); } public async Task SerializeAsync(T data, Stream writableStream, SerializationFormatting formatting, - CancellationToken cancellationToken = default(CancellationToken)) + CancellationToken cancellationToken = default(CancellationToken) + ) { var serialized = SimpleJson.SerializeObject(data, Strategy); if (formatting == SerializationFormatting.None) serialized = RemoveNewLinesAndTabs(serialized); - using (var ms = new MemoryStream(serialized.Utf8Bytes())) - { - await ms.CopyToAsync(writableStream).ConfigureAwait(false); - } + using (var ms = new MemoryStream(serialized.Utf8Bytes())) await ms.CopyToAsync(writableStream).ConfigureAwait(false); } - private static string RemoveNewLinesAndTabs(string input) - { - return new string(input - .Where(c => c != '\r' && c != '\n') - .ToArray()); - } + private static object Default(Type type) => type.IsValueType() ? type.CreateInstance() : null; + + private static string RemoveNewLinesAndTabs(string input) => new string(input + .Where(c => c != '\r' && c != '\n') + .ToArray()); } } diff --git a/src/Elasticsearch.Net/Serialization/SerializationFormatting.cs b/src/Elasticsearch.Net/Serialization/SerializationFormatting.cs index c4140e7ba91..3b90055c3c5 100644 --- a/src/Elasticsearch.Net/Serialization/SerializationFormatting.cs +++ b/src/Elasticsearch.Net/Serialization/SerializationFormatting.cs @@ -5,4 +5,4 @@ public enum SerializationFormatting None, Indented } -} \ No newline at end of file +} diff --git a/src/Elasticsearch.Net/Serialization/SimpleJson.cs b/src/Elasticsearch.Net/Serialization/SimpleJson.cs index 0bf318022d4..0c5ac95602b 100644 --- a/src/Elasticsearch.Net/Serialization/SimpleJson.cs +++ b/src/Elasticsearch.Net/Serialization/SimpleJson.cs @@ -17,6 +17,8 @@ // https://github.com/facebook-csharp-sdk/simple-json //----------------------------------------------------------------------- +// @formatter:on — enable formatter after this line + // VERSION: 0.32.0 // NOTE: uncomment the following line to make SimpleJson class internal. @@ -46,9 +48,7 @@ // original json parsing code from http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html -#if NETFX_CORE || DOTNETCORE #define SIMPLE_JSON_TYPEINFO -#endif using System; using System.CodeDom.Compiler; using System.Collections; @@ -61,6 +61,15 @@ using System.Reflection; using System.Runtime.Serialization; using System.Text; +// ReSharper disable ArrangeMethodOrOperatorBody +// ReSharper disable SuggestVarOrType_BuiltInTypes +// ReSharper disable ArrangeAccessorOwnerBody +// ReSharper disable ArrangeConstructorOrDestructorBody +// ReSharper disable SuggestVarOrType_Elsewhere +// ReSharper disable SuggestVarOrType_SimpleTypes +// ReSharper disable ArrangeTypeMemberModifiers +// ReSharper disable RemoveRedundantBraces +// ReSharper disable BuiltInTypeReferenceStyle namespace Elasticsearch.Net { @@ -2081,3 +2090,4 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() // ReSharper restore RedundantExplicitArrayCreation // ReSharper restore SuggestUseVarKeywordEvident } +// @formatter:on — enable formatter after this line diff --git a/src/Elasticsearch.Net/Transport/ITransport.cs b/src/Elasticsearch.Net/Transport/ITransport.cs index 08f7b08d800..4aad961b21f 100644 --- a/src/Elasticsearch.Net/Transport/ITransport.cs +++ b/src/Elasticsearch.Net/Transport/ITransport.cs @@ -1,4 +1,3 @@ -using System; using System.Threading; using System.Threading.Tasks; @@ -14,9 +13,8 @@ TResponse Request(HttpMethod method, string path, PostData data = nul where TResponse : class, IElasticsearchResponse, new(); Task RequestAsync( - HttpMethod method, string path, CancellationToken ctx, PostData data = null, IRequestParameters requestParameters = null) + HttpMethod method, string path, CancellationToken ctx, PostData data = null, IRequestParameters requestParameters = null + ) where TResponse : class, IElasticsearchResponse, new(); - } - } diff --git a/src/Elasticsearch.Net/Transport/Pipeline/IRequestPipeline.cs b/src/Elasticsearch.Net/Transport/Pipeline/IRequestPipeline.cs index d6109be09c8..387bdea5294 100644 --- a/src/Elasticsearch.Net/Transport/Pipeline/IRequestPipeline.cs +++ b/src/Elasticsearch.Net/Transport/Pipeline/IRequestPipeline.cs @@ -7,18 +7,17 @@ namespace Elasticsearch.Net { public interface IRequestPipeline : IDisposable { + List AuditTrail { get; } bool FirstPoolUsageNeedsSniffing { get; } + bool IsTakingTooLong { get; } + int MaxRetries { get; } + + int Retried { get; } bool SniffsOnConnectionFailure { get; } bool SniffsOnStaleCluster { get; } bool StaleClusterState { get; } - List AuditTrail { get; } - DateTime StartedOn { get; } - bool IsTakingTooLong { get; } - - int Retried { get; } - int MaxRetries { get; } TResponse CallElasticsearch(RequestData requestData) where TResponse : class, IElasticsearchResponse, new(); @@ -27,23 +26,29 @@ Task CallElasticsearchAsync(RequestData requestData, Cance where TResponse : class, IElasticsearchResponse, new(); void MarkAlive(Node node); + void MarkDead(Node node); IEnumerable NextNode(); void Ping(Node node); + Task PingAsync(Node node, CancellationToken cancellationToken); void FirstPoolUsage(SemaphoreSlim semaphore); + Task FirstPoolUsageAsync(SemaphoreSlim semaphore, CancellationToken cancellationToken); void Sniff(); + Task SniffAsync(CancellationToken cancellationToken); void SniffOnStaleCluster(); + Task SniffOnStaleClusterAsync(CancellationToken cancellationToken); void SniffOnConnectionFailure(); + Task SniffOnConnectionFailureAsync(CancellationToken cancellationToken); void BadResponse(ref TResponse response, IApiCallDetails callDetails, RequestData data, ElasticsearchClientException exception) @@ -53,7 +58,9 @@ void BadResponse(ref TResponse response, IApiCallDetails callDetails, void AuditCancellationRequested(); - ElasticsearchClientException CreateClientException(TResponse response, IApiCallDetails callDetails, RequestData data, List seenExceptions) + ElasticsearchClientException CreateClientException(TResponse response, IApiCallDetails callDetails, RequestData data, + List seenExceptions + ) where TResponse : class, IElasticsearchResponse, new(); } } diff --git a/src/Elasticsearch.Net/Transport/Pipeline/PipelineException.cs b/src/Elasticsearch.Net/Transport/Pipeline/PipelineException.cs index 6a26e50a704..e8c9b8f0fae 100644 --- a/src/Elasticsearch.Net/Transport/Pipeline/PipelineException.cs +++ b/src/Elasticsearch.Net/Transport/Pipeline/PipelineException.cs @@ -4,9 +4,17 @@ namespace Elasticsearch.Net { public class PipelineException : Exception { - public PipelineFailure FailureReason { get; } + public PipelineException(PipelineFailure failure) + : base(GetMessage(failure)) => FailureReason = failure; + + public PipelineException(string message) + : base(message) => FailureReason = PipelineFailure.BadResponse; + + public PipelineException(PipelineFailure failure, Exception innerException) + : base(GetMessage(failure), innerException) => FailureReason = failure; public IApiCallDetails ApiCall { get; internal set; } + public PipelineFailure FailureReason { get; } public bool Recoverable => FailureReason == PipelineFailure.BadRequest @@ -15,27 +23,9 @@ public class PipelineException : Exception public IElasticsearchResponse Response { get; internal set; } - public PipelineException(PipelineFailure failure) - : base(GetMessage(failure)) - { - this.FailureReason = failure; - } - - public PipelineException(string message) - : base(message) - { - this.FailureReason = PipelineFailure.BadResponse; - } - - public PipelineException(PipelineFailure failure, Exception innerException) - : base(GetMessage(failure), innerException) - { - this.FailureReason = failure; - } - private static string GetMessage(PipelineFailure failure) { - switch(failure) + switch (failure) { case PipelineFailure.BadRequest: return "An error occurred trying to write the request data to the specified node."; case PipelineFailure.BadResponse: return "An error occurred trying to read the response from the specified node."; diff --git a/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs b/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs index acef7e38e21..276425dff91 100644 --- a/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs +++ b/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs @@ -4,58 +4,22 @@ using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; -using System.Text; namespace Elasticsearch.Net { public class RequestData { public const string MimeType = "application/json"; - public const string RunAsSecurityHeader = "es-security-runas-user"; public const string OpaqueIdHeader = "X-Opaque-Id"; + public const string RunAsSecurityHeader = "es-security-runas-user"; - public Uri Uri => this.Node != null ? new Uri(this.Node.Uri, this.PathAndQuery) : null; - - public HttpMethod Method { get; private set; } - public string PathAndQuery { get; } - public PostData PostData { get; } - public bool MadeItToResponse { get; set;} - public AuditEvent OnFailureAuditEvent => this.MadeItToResponse ? AuditEvent.BadResponse : AuditEvent.BadRequest; - public PipelineFailure OnFailurePipelineFailure => this.MadeItToResponse ? PipelineFailure.BadResponse : PipelineFailure.BadRequest; - - public Node Node { get; set; } - public TimeSpan RequestTimeout { get; } - public TimeSpan PingTimeout { get; } - public int KeepAliveTime { get; } - public int KeepAliveInterval { get; } - - public bool Pipelined { get; } - public bool HttpCompression { get; } - public string RequestMimeType { get; } - public string Accept { get; } - public string RunAs { get; } - public IReadOnlyCollection SkipDeserializationForStatusCodes { get; } - - public NameValueCollection Headers { get; } - public string ProxyAddress { get; } - public string ProxyUsername { get; } - public string ProxyPassword { get; } - public bool DisableAutomaticProxyDetection { get; } - public bool ThrowExceptions { get; } - - public BasicAuthenticationCredentials BasicAuthorizationCredentials { get; } - public IEnumerable AllowedStatusCodes { get; } - public Func CustomConverter { get; } - public IConnectionConfigurationValues ConnectionSettings { get; } - public IMemoryStreamFactory MemoryStreamFactory { get; } - - public X509CertificateCollection ClientCertificates { get; } - - public RequestData(HttpMethod method, string path, PostData data, IConnectionConfigurationValues global, IRequestParameters local, IMemoryStreamFactory memoryStreamFactory) + public RequestData(HttpMethod method, string path, PostData data, IConnectionConfigurationValues global, IRequestParameters local, + IMemoryStreamFactory memoryStreamFactory + ) : this(method, data, global, local?.RequestConfiguration, memoryStreamFactory) { - this.CustomConverter = local?.DeserializationOverride; - this.PathAndQuery = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, local); + CustomConverter = local?.DeserializationOverride; + PathAndQuery = CreatePathWithQueryStrings(path, ConnectionSettings, local); } private RequestData( @@ -63,47 +27,86 @@ private RequestData( PostData data, IConnectionConfigurationValues global, IRequestConfiguration local, - IMemoryStreamFactory memoryStreamFactory) + IMemoryStreamFactory memoryStreamFactory + ) { - this.ConnectionSettings = global; - this.MemoryStreamFactory = memoryStreamFactory; - this.Method = method; - this.PostData = data; + ConnectionSettings = global; + MemoryStreamFactory = memoryStreamFactory; + Method = method; + PostData = data; if (data != null) data.DisableDirectStreaming = local?.DisableDirectStreaming ?? global.DisableDirectStreaming; - this.Pipelined = local?.EnableHttpPipelining ?? global.HttpPipeliningEnabled; - this.HttpCompression = global.EnableHttpCompression; - this.RequestMimeType = local?.ContentType ?? MimeType; - this.Accept = local?.Accept ?? MimeType; - this.Headers = global.Headers != null ? new NameValueCollection(global.Headers) : new NameValueCollection(); + Pipelined = local?.EnableHttpPipelining ?? global.HttpPipeliningEnabled; + HttpCompression = global.EnableHttpCompression; + RequestMimeType = local?.ContentType ?? MimeType; + Accept = local?.Accept ?? MimeType; + Headers = global.Headers != null ? new NameValueCollection(global.Headers) : new NameValueCollection(); if (!string.IsNullOrEmpty(local?.OpaqueId)) - this.Headers.Add(OpaqueIdHeader, local.OpaqueId); + Headers.Add(OpaqueIdHeader, local.OpaqueId); - this.RunAs = local?.RunAs; - this.SkipDeserializationForStatusCodes = global?.SkipDeserializationForStatusCodes; - this.ThrowExceptions = local?.ThrowExceptions ?? global.ThrowExceptions; + RunAs = local?.RunAs; + SkipDeserializationForStatusCodes = global?.SkipDeserializationForStatusCodes; + ThrowExceptions = local?.ThrowExceptions ?? global.ThrowExceptions; - this.RequestTimeout = local?.RequestTimeout ?? global.RequestTimeout; - this.PingTimeout = + RequestTimeout = local?.RequestTimeout ?? global.RequestTimeout; + PingTimeout = local?.PingTimeout ?? global?.PingTimeout ?? (global.ConnectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout); - this.KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000); - this.KeepAliveTime = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000); + KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000); + KeepAliveTime = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000); - this.ProxyAddress = global.ProxyAddress; - this.ProxyUsername = global.ProxyUsername; - this.ProxyPassword = global.ProxyPassword; - this.DisableAutomaticProxyDetection = global.DisableAutomaticProxyDetection; - this.BasicAuthorizationCredentials = local?.BasicAuthenticationCredentials ?? global.BasicAuthenticationCredentials; - this.AllowedStatusCodes = local?.AllowedStatusCodes ?? Enumerable.Empty(); - this.ClientCertificates = local?.ClientCertificates ?? global.ClientCertificates; + ProxyAddress = global.ProxyAddress; + ProxyUsername = global.ProxyUsername; + ProxyPassword = global.ProxyPassword; + DisableAutomaticProxyDetection = global.DisableAutomaticProxyDetection; + BasicAuthorizationCredentials = local?.BasicAuthenticationCredentials ?? global.BasicAuthenticationCredentials; + AllowedStatusCodes = local?.AllowedStatusCodes ?? Enumerable.Empty(); + ClientCertificates = local?.ClientCertificates ?? global.ClientCertificates; } + public string Accept { get; } + public IEnumerable AllowedStatusCodes { get; } + + public BasicAuthenticationCredentials BasicAuthorizationCredentials { get; } + + public X509CertificateCollection ClientCertificates { get; } + public IConnectionConfigurationValues ConnectionSettings { get; } + public Func CustomConverter { get; } + public bool DisableAutomaticProxyDetection { get; } + + public NameValueCollection Headers { get; } + public bool HttpCompression { get; } + public int KeepAliveInterval { get; } + public int KeepAliveTime { get; } + public bool MadeItToResponse { get; set; } + public IMemoryStreamFactory MemoryStreamFactory { get; } + + public HttpMethod Method { get; private set; } + + public Node Node { get; set; } + public AuditEvent OnFailureAuditEvent => MadeItToResponse ? AuditEvent.BadResponse : AuditEvent.BadRequest; + public PipelineFailure OnFailurePipelineFailure => MadeItToResponse ? PipelineFailure.BadResponse : PipelineFailure.BadRequest; + public string PathAndQuery { get; } + public TimeSpan PingTimeout { get; } + + public bool Pipelined { get; } + public PostData PostData { get; } + public string ProxyAddress { get; } + public string ProxyPassword { get; } + public string ProxyUsername { get; } + public string RequestMimeType { get; } + public TimeSpan RequestTimeout { get; } + public string RunAs { get; } + public IReadOnlyCollection SkipDeserializationForStatusCodes { get; } + public bool ThrowExceptions { get; } + + public Uri Uri => Node != null ? new Uri(Node.Uri, PathAndQuery) : null; + private string CreatePathWithQueryStrings(string path, IConnectionConfigurationValues global, IRequestParameters request) { path = path ?? string.Empty; @@ -118,7 +121,7 @@ private string CreatePathWithQueryStrings(string path, IConnectionConfigurationV var nv = g == null ? new NameValueCollection() : new NameValueCollection(g); //set all querystring pairs from local `l` on the querystring collection - var formatter = this.ConnectionSettings.UrlFormatter; + var formatter = ConnectionSettings.UrlFormatter; nv.UpdateFromDictionary(l, formatter); //if nv has no keys simply return path as provided @@ -137,11 +140,18 @@ internal static string ToQueryString(this NameValueCollection nv) { if (nv == null) return string.Empty; if (nv.AllKeys.Length == 0) return string.Empty; - string E(string v) => Uri.EscapeDataString(v); + + string E(string v) + { + return Uri.EscapeDataString(v); + } + return "?" + string.Join("&", nv.AllKeys.Select(key => $"{E(key)}={E(nv[key])}")); } - internal static void UpdateFromDictionary(this NameValueCollection queryString, Dictionary queryStringUpdates, ElasticsearchUrlFormatter provider) + internal static void UpdateFromDictionary(this NameValueCollection queryString, Dictionary queryStringUpdates, + ElasticsearchUrlFormatter provider + ) { if (queryString == null || queryString.Count < 0) return; if (queryStringUpdates == null || queryStringUpdates.Count < 0) return; diff --git a/src/Elasticsearch.Net/Transport/Pipeline/RequestPipeline.cs b/src/Elasticsearch.Net/Transport/Pipeline/RequestPipeline.cs index df29a74047a..099d5f8e97d 100644 --- a/src/Elasticsearch.Net/Transport/Pipeline/RequestPipeline.cs +++ b/src/Elasticsearch.Net/Transport/Pipeline/RequestPipeline.cs @@ -8,144 +8,265 @@ namespace Elasticsearch.Net { - public class RequestPipeline : IRequestPipeline { - private readonly IConnectionConfigurationValues _settings; + private static readonly string NoNodesAttemptedMessage = + "No nodes were attempted, this can happen when a node predicate does not match any nodes"; + private readonly IConnection _connection; private readonly IConnectionPool _connectionPool; private readonly IDateTimeProvider _dateTimeProvider; private readonly IMemoryStreamFactory _memoryStreamFactory; - - private IRequestParameters RequestParameters { get; } - private IRequestConfiguration RequestConfiguration { get; } - - public DateTime StartedOn { get; } - - public List AuditTrail { get; } = new List(); - private int _retried = 0; - public int Retried => _retried; + private readonly IConnectionConfigurationValues _settings; public RequestPipeline( IConnectionConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider, IMemoryStreamFactory memoryStreamFactory, - IRequestParameters requestParameters) + IRequestParameters requestParameters + ) { - this._settings = configurationValues; - this._connectionPool = this._settings.ConnectionPool; - this._connection = this._settings.Connection; - this._dateTimeProvider = dateTimeProvider; - this._memoryStreamFactory = memoryStreamFactory; - - this.RequestParameters = requestParameters; - this.RequestConfiguration = requestParameters?.RequestConfiguration; - this.StartedOn = dateTimeProvider.Now(); + _settings = configurationValues; + _connectionPool = _settings.ConnectionPool; + _connection = _settings.Connection; + _dateTimeProvider = dateTimeProvider; + _memoryStreamFactory = memoryStreamFactory; + + RequestParameters = requestParameters; + RequestConfiguration = requestParameters?.RequestConfiguration; + StartedOn = dateTimeProvider.Now(); } - public int MaxRetries => - this.RequestConfiguration?.ForceNode != null - ? 0 - : Math.Min(this.RequestConfiguration?.MaxRetries ?? this._settings.MaxRetries.GetValueOrDefault(int.MaxValue), this._connectionPool.MaxRetries); + public List AuditTrail { get; } = new List(); - private bool RequestDisabledSniff => this.RequestConfiguration != null && (this.RequestConfiguration.DisableSniff ?? false); + // TODO: rename to DepeletedRetries in 7.x + public bool DepleededRetries => Retried >= MaxRetries + 1 || IsTakingTooLong; public bool FirstPoolUsageNeedsSniffing => - !this.RequestDisabledSniff - && this._connectionPool.SupportsReseeding && this._settings.SniffsOnStartup && !this._connectionPool.SniffedOnStartup; + !RequestDisabledSniff + && _connectionPool.SupportsReseeding && _settings.SniffsOnStartup && !_connectionPool.SniffedOnStartup; + + public bool IsTakingTooLong + { + get + { + var timeout = _settings.MaxRetryTimeout.GetValueOrDefault(RequestTimeout); + var now = _dateTimeProvider.Now(); + + //we apply a soft margin so that if a request timesout at 59 seconds when the maximum is 60 we also abort. + var margin = timeout.TotalMilliseconds / 100.0 * 98; + var marginTimeSpan = TimeSpan.FromMilliseconds(margin); + var timespanCall = now - StartedOn; + var tookToLong = timespanCall >= marginTimeSpan; + return tookToLong; + } + } + + public int MaxRetries => + RequestConfiguration?.ForceNode != null + ? 0 + : Math.Min(RequestConfiguration?.MaxRetries ?? _settings.MaxRetries.GetValueOrDefault(int.MaxValue), _connectionPool.MaxRetries); + + public bool Refresh { get; private set; } + public int Retried { get; private set; } = 0; + + public IEnumerable SniffNodes => _connectionPool + .CreateView(LazyAuditable) + .ToList() + .OrderBy(n => n.MasterEligible ? n.Uri.Port : int.MaxValue); + + public static string SniffPath => "_nodes/http,settings"; public bool SniffsOnConnectionFailure => - !this.RequestDisabledSniff - && this._connectionPool.SupportsReseeding && this._settings.SniffsOnConnectionFault; + !RequestDisabledSniff + && _connectionPool.SupportsReseeding && _settings.SniffsOnConnectionFault; public bool SniffsOnStaleCluster => - !this.RequestDisabledSniff - && this._connectionPool.SupportsReseeding && this._settings.SniffInformationLifeSpan.HasValue; + !RequestDisabledSniff + && _connectionPool.SupportsReseeding && _settings.SniffInformationLifeSpan.HasValue; public bool StaleClusterState { get { if (!SniffsOnStaleCluster) return false; + // ReSharper disable once PossibleInvalidOperationException // already checked by SniffsOnStaleCluster - var sniffLifeSpan = this._settings.SniffInformationLifeSpan.Value; + var sniffLifeSpan = _settings.SniffInformationLifeSpan.Value; - var now = this._dateTimeProvider.Now(); - var lastSniff = this._connectionPool.LastUpdate; + var now = _dateTimeProvider.Now(); + var lastSniff = _connectionPool.LastUpdate; - return sniffLifeSpan < (now - lastSniff); + return sniffLifeSpan < now - lastSniff; } } - private bool PingDisabled(Node node) => - (this.RequestConfiguration?.DisablePing).GetValueOrDefault(false) - || this._settings.DisablePings || !this._connectionPool.SupportsPinging || !node.IsResurrected; + public DateTime StartedOn { get; } - TimeSpan PingTimeout => - this.RequestConfiguration?.PingTimeout - ?? this._settings.PingTimeout - ?? (this._connectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout); + private TimeSpan PingTimeout => + RequestConfiguration?.PingTimeout + ?? _settings.PingTimeout + ?? (_connectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout); - TimeSpan RequestTimeout => this.RequestConfiguration?.RequestTimeout ?? this._settings.RequestTimeout; + private IRequestConfiguration RequestConfiguration { get; } - public bool IsTakingTooLong + private bool RequestDisabledSniff => RequestConfiguration != null && (RequestConfiguration.DisableSniff ?? false); + + private IRequestParameters RequestParameters { get; } + + private TimeSpan RequestTimeout => RequestConfiguration?.RequestTimeout ?? _settings.RequestTimeout; + + private NodesInfoRequestParameters SniffParameters => new NodesInfoRequestParameters { - get - { - var timeout = this._settings.MaxRetryTimeout.GetValueOrDefault(this.RequestTimeout); - var now = this._dateTimeProvider.Now(); + Timeout = PingTimeout, + FlatSettings = true + }; - //we apply a soft margin so that if a request timesout at 59 seconds when the maximum is 60 we also abort. - var margin = (timeout.TotalMilliseconds / 100.0) * 98; - var marginTimeSpan = TimeSpan.FromMilliseconds(margin); - var timespanCall = (now - this.StartedOn); - var tookToLong = timespanCall >= marginTimeSpan; - return tookToLong; - } - } + void IDisposable.Dispose() => Dispose(); - public bool Refresh { get; private set; } + public void AuditCancellationRequested() => Audit(CancellationRequested).Dispose(); - // TODO: rename to DepeletedRetries in 7.x - public bool DepleededRetries => this.Retried >= this.MaxRetries + 1 || this.IsTakingTooLong; + public void BadResponse(ref TResponse response, IApiCallDetails callDetails, RequestData data, + ElasticsearchClientException exception + ) + where TResponse : class, IElasticsearchResponse, new() + { + if (response == null) + { + //make sure we copy over the error body in case we disabled direct streaming. + var s = callDetails?.ResponseBodyInBytes == null ? Stream.Null : new MemoryStream(callDetails.ResponseBodyInBytes); + var m = callDetails?.ResponseMimeType ?? RequestData.MimeType; + response = ResponseBuilder.ToResponse(data, exception, callDetails?.HttpStatusCode, null, s, m); + } - private Auditable Audit(AuditEvent type) => new Auditable(type, this.AuditTrail, this._dateTimeProvider); + response.ApiCall.AuditTrail = AuditTrail; + } - private static string NoNodesAttemptedMessage = "No nodes were attempted, this can happen when a node predicate does not match any nodes"; - public void ThrowNoNodesAttempted(RequestData requestData, List seenExceptions) + public TResponse CallElasticsearch(RequestData requestData) + where TResponse : class, IElasticsearchResponse, new() { - var clientException = new ElasticsearchClientException(PipelineFailure.NoNodesAttempted, NoNodesAttemptedMessage, (Exception) null); - using(this.Audit(NoNodesAttempted)) - throw new UnexpectedElasticsearchClientException(clientException, seenExceptions) + using (var audit = Audit(HealthyResponse)) + { + audit.Node = requestData.Node; + audit.Path = requestData.PathAndQuery; + + TResponse response = null; + try { - Request = requestData, - AuditTrail = this.AuditTrail - }; + response = _connection.Request(requestData); + response.ApiCall.AuditTrail = AuditTrail; + ThrowBadAuthPipelineExceptionWhenNeeded(response.ApiCall, response); + if (!response.ApiCall.Success) audit.Event = requestData.OnFailureAuditEvent; + return response; + } + catch (Exception e) + { + (response as ElasticsearchResponse)?.Body?.Dispose(); + audit.Event = requestData.OnFailureAuditEvent; + audit.Exception = e; + throw; + } + } } - public void AuditCancellationRequested() => Audit(CancellationRequested).Dispose(); - - public void MarkDead(Node node) + public async Task CallElasticsearchAsync(RequestData requestData, CancellationToken cancellationToken) + where TResponse : class, IElasticsearchResponse, new() { - var deadUntil = this._dateTimeProvider.DeadTime(node.FailedAttempts, this._settings.DeadTimeout, this._settings.MaxDeadTimeout); - node.MarkDead(deadUntil); - this._retried++; + using (var audit = Audit(HealthyResponse)) + { + audit.Node = requestData.Node; + audit.Path = requestData.PathAndQuery; + + TResponse response = null; + try + { + response = await _connection.RequestAsync(requestData, cancellationToken).ConfigureAwait(false); + response.ApiCall.AuditTrail = AuditTrail; + ThrowBadAuthPipelineExceptionWhenNeeded(response.ApiCall, response); + if (!response.ApiCall.Success) audit.Event = requestData.OnFailureAuditEvent; + return response; + } + catch (Exception e) + { + (response as ElasticsearchResponse)?.Body?.Dispose(); + audit.Event = requestData.OnFailureAuditEvent; + audit.Exception = e; + throw; + } + } } - public void MarkAlive(Node node) => node.MarkAlive(); + public ElasticsearchClientException CreateClientException( + TResponse response, IApiCallDetails callDetails, RequestData data, List pipelineExceptions + ) + where TResponse : class, IElasticsearchResponse, new() + { + if (callDetails?.Success ?? false) return null; + + var innerException = pipelineExceptions.HasAny() ? pipelineExceptions.AsAggregateOrFirst() : callDetails?.OriginalException; + + var statusCode = callDetails?.HttpStatusCode != null ? callDetails.HttpStatusCode.Value.ToString() : "unknown"; + var resource = callDetails == null + ? "unknown resource" + : $"Status code {statusCode} from: {callDetails.HttpMethod} {callDetails.Uri.PathAndQuery}"; + + + var exceptionMessage = innerException?.Message ?? $"Request failed to execute"; + + var pipelineFailure = data.OnFailurePipelineFailure; + if (pipelineExceptions.HasAny()) + pipelineFailure = pipelineExceptions.Last().FailureReason; + + if (IsTakingTooLong) + { + pipelineFailure = PipelineFailure.MaxTimeoutReached; + Audit(MaxTimeoutReached); + exceptionMessage = "Maximum timeout reached while retrying request"; + } + else if (Retried >= MaxRetries && MaxRetries > 0) + { + pipelineFailure = PipelineFailure.MaxRetriesReached; + Audit(MaxRetriesReached); + exceptionMessage = "Maximum number of retries reached"; + + var now = _dateTimeProvider.Now(); + // TODO make AliveNodes on IConnectionPool public in 7.0 (default interface C# 8 FTW) + var activeNodes = _connectionPool.Nodes.Count(n => n.IsAlive || n.DeadUntil <= now); + if (Retried >= activeNodes) + { + Audit(FailedOverAllNodes); + exceptionMessage += ", failed over to all the known alive nodes before failing"; + } + } + + exceptionMessage += $". Call: {resource}"; + if (response != null && response.TryGetServerErrorReason(out var reason)) + exceptionMessage += $". ServerError: {reason}"; + + var clientException = new ElasticsearchClientException(pipelineFailure, exceptionMessage, innerException) + { + Request = data, + Response = callDetails, + AuditTrail = AuditTrail + }; + + return clientException; + } public void FirstPoolUsage(SemaphoreSlim semaphore) { - if (!this.FirstPoolUsageNeedsSniffing) return; - if (!semaphore.Wait(this._settings.RequestTimeout)) + if (!FirstPoolUsageNeedsSniffing) return; + + if (!semaphore.Wait(_settings.RequestTimeout)) { - if (this.FirstPoolUsageNeedsSniffing) + if (FirstPoolUsageNeedsSniffing) throw new PipelineException(PipelineFailure.CouldNotStartSniffOnStartup, null); + return; } - if (!this.FirstPoolUsageNeedsSniffing) + if (!FirstPoolUsageNeedsSniffing) { semaphore.Release(); return; @@ -153,10 +274,10 @@ public void FirstPoolUsage(SemaphoreSlim semaphore) try { - using (this.Audit(SniffOnStartup)) + using (Audit(SniffOnStartup)) { - this.Sniff(); - this._connectionPool.SniffedOnStartup = true; + Sniff(); + _connectionPool.SniffedOnStartup = true; } } finally @@ -167,26 +288,28 @@ public void FirstPoolUsage(SemaphoreSlim semaphore) public async Task FirstPoolUsageAsync(SemaphoreSlim semaphore, CancellationToken cancellationToken) { - if (!this.FirstPoolUsageNeedsSniffing) return; - var success = await semaphore.WaitAsync(this._settings.RequestTimeout, cancellationToken).ConfigureAwait(false); + if (!FirstPoolUsageNeedsSniffing) return; + + var success = await semaphore.WaitAsync(_settings.RequestTimeout, cancellationToken).ConfigureAwait(false); if (!success) { - if(this.FirstPoolUsageNeedsSniffing) + if (FirstPoolUsageNeedsSniffing) throw new PipelineException(PipelineFailure.CouldNotStartSniffOnStartup, null); + return; } - if (!this.FirstPoolUsageNeedsSniffing) + if (!FirstPoolUsageNeedsSniffing) { semaphore.Release(); return; } try { - using (this.Audit(SniffOnStartup)) + using (Audit(SniffOnStartup)) { - await this.SniffAsync(cancellationToken).ConfigureAwait(false); - this._connectionPool.SniffedOnStartup = true; + await SniffAsync(cancellationToken).ConfigureAwait(false); + _connectionPool.SniffedOnStartup = true; } } finally @@ -195,31 +318,21 @@ public async Task FirstPoolUsageAsync(SemaphoreSlim semaphore, CancellationToken } } - public void SniffOnStaleCluster() - { - if (!StaleClusterState) return; - using (this.Audit(AuditEvent.SniffOnStaleCluster)) - { - this.Sniff(); - this._connectionPool.SniffedOnStartup = true; - } - } + public void MarkAlive(Node node) => node.MarkAlive(); - public async Task SniffOnStaleClusterAsync(CancellationToken cancellationToken) + public void MarkDead(Node node) { - if (!StaleClusterState) return; - using (this.Audit(AuditEvent.SniffOnStaleCluster)) - { - await this.SniffAsync(cancellationToken).ConfigureAwait(false); - this._connectionPool.SniffedOnStartup = true; - } + var deadUntil = _dateTimeProvider.DeadTime(node.FailedAttempts, _settings.DeadTimeout, _settings.MaxDeadTimeout); + node.MarkDead(deadUntil); + Retried++; } public IEnumerable NextNode() { - if (this.RequestConfiguration?.ForceNode != null) + if (RequestConfiguration?.ForceNode != null) { - yield return new Node(this.RequestConfiguration.ForceNode); + yield return new Node(RequestConfiguration.ForceNode); + yield break; } @@ -229,15 +342,19 @@ public IEnumerable NextNode() var refreshed = false; for (var i = 0; i < 100; i++) { - if (this.DepleededRetries) yield break; - foreach (var node in this._connectionPool + if (DepleededRetries) yield break; + + foreach (var node in _connectionPool .CreateView(LazyAuditable) - .TakeWhile(node => !this.DepleededRetries)) + .TakeWhile(node => !DepleededRetries)) { - if (!this._settings.NodePredicate(node)) continue; + if (!_settings.NodePredicate(node)) continue; + yield return node; - if (!this.Refresh) continue; - this.Refresh = false; + + if (!Refresh) continue; + + Refresh = false; refreshed = true; break; } @@ -247,39 +364,20 @@ public IEnumerable NextNode() } } - private RequestData CreatePingRequestData(Node node, Auditable audit) - { - audit.Node = node; - - var requestOverrides = new RequestConfiguration - { - PingTimeout = this.PingTimeout, - RequestTimeout = this.PingTimeout, - BasicAuthenticationCredentials = this._settings.BasicAuthenticationCredentials, - EnableHttpPipelining = this.RequestConfiguration?.EnableHttpPipelining ?? this._settings.HttpPipeliningEnabled, - ForceNode = this.RequestConfiguration?.ForceNode - }; - IRequestParameters requestParameters = new RootNodeInfoRequestParameters(); - requestParameters.RequestConfiguration = requestOverrides; - - var data = new RequestData(HttpMethod.HEAD, "/", null, this._settings, requestParameters, this._memoryStreamFactory) { Node = node }; - audit.Path = data.PathAndQuery; - return data; - } - public void Ping(Node node) { if (PingDisabled(node)) return; - using (var audit = this.Audit(PingSuccess)) + using (var audit = Audit(PingSuccess)) { try { var pingData = CreatePingRequestData(node, audit); - var response = this._connection.Request(pingData); + var response = _connection.Request(pingData); ThrowBadAuthPipelineExceptionWhenNeeded(response); //ping should not silently accept bad but valid http responses - if (!response.Success) throw new PipelineException(pingData.OnFailurePipelineFailure, response.OriginalException) { ApiCall = response }; + if (!response.Success) + throw new PipelineException(pingData.OnFailurePipelineFailure, response.OriginalException) { ApiCall = response }; } catch (Exception e) { @@ -295,15 +393,16 @@ public async Task PingAsync(Node node, CancellationToken cancellationToken) { if (PingDisabled(node)) return; - using (var audit = this.Audit(PingSuccess)) + using (var audit = Audit(PingSuccess)) { try { var pingData = CreatePingRequestData(node, audit); - var response = await this._connection.RequestAsync(pingData, cancellationToken).ConfigureAwait(false); + var response = await _connection.RequestAsync(pingData, cancellationToken).ConfigureAwait(false); ThrowBadAuthPipelineExceptionWhenNeeded(response); //ping should not silently accept bad but valid http responses - if (!response.Success) throw new PipelineException(pingData.OnFailurePipelineFailure, response.OriginalException) { ApiCall = response }; + if (!response.Success) + throw new PipelineException(pingData.OnFailurePipelineFailure, response.OriginalException) { ApiCall = response }; } catch (Exception e) { @@ -315,66 +414,27 @@ public async Task PingAsync(Node node, CancellationToken cancellationToken) } } - private static void ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IElasticsearchResponse response = null) - { - if (details?.HttpStatusCode == 401) - throw new PipelineException(PipelineFailure.BadAuthentication, details.OriginalException) - { - Response = response, - ApiCall = details - }; - } - - public static string SniffPath => "_nodes/http,settings"; - private NodesInfoRequestParameters SniffParameters => new NodesInfoRequestParameters - { - Timeout = this.PingTimeout, - FlatSettings = true - }; - - public IEnumerable SniffNodes => this._connectionPool - .CreateView(LazyAuditable) - .ToList() - .OrderBy(n => n.MasterEligible ? n.Uri.Port : int.MaxValue); - - private void LazyAuditable(AuditEvent e, Node n) - { - using (new Auditable(e, this.AuditTrail, this._dateTimeProvider) { Node = n }) {}; - } - - public void SniffOnConnectionFailure() - { - if (!this.SniffsOnConnectionFailure) return; - using (this.Audit(SniffOnFail)) - this.Sniff(); - } - - public async Task SniffOnConnectionFailureAsync(CancellationToken cancellationToken) - { - if (!this.SniffsOnConnectionFailure) return; - using (this.Audit(SniffOnFail)) - await this.SniffAsync(cancellationToken).ConfigureAwait(false); - } - public void Sniff() { var exceptions = new List(); - foreach (var node in this.SniffNodes) + foreach (var node in SniffNodes) { - using (var audit = this.Audit(SniffSuccess)) + using (var audit = Audit(SniffSuccess)) { audit.Node = node; try { var requestData = CreateSniffRequestData(node); audit.Path = requestData.PathAndQuery; - var response = this._connection.Request(requestData); + var response = _connection.Request(requestData); ThrowBadAuthPipelineExceptionWhenNeeded(response); //sniff should not silently accept bad but valid http responses - if (!response.Success) throw new PipelineException(requestData.OnFailurePipelineFailure, response.OriginalException) { ApiCall = response }; - var nodes = response.ToNodes(this._connectionPool.UsingSsl); - this._connectionPool.Reseed(nodes); - this.Refresh = true; + if (!response.Success) + throw new PipelineException(requestData.OnFailurePipelineFailure, response.OriginalException) { ApiCall = response }; + + var nodes = response.ToNodes(_connectionPool.UsingSsl); + _connectionPool.Reseed(nodes); + Refresh = true; return; } catch (Exception e) @@ -392,21 +452,23 @@ public void Sniff() public async Task SniffAsync(CancellationToken cancellationToken) { var exceptions = new List(); - foreach (var node in this.SniffNodes) + foreach (var node in SniffNodes) { - using (var audit = this.Audit(SniffSuccess)) + using (var audit = Audit(SniffSuccess)) { audit.Node = node; try { var requestData = CreateSniffRequestData(node); audit.Path = requestData.PathAndQuery; - var response = await this._connection.RequestAsync(requestData, cancellationToken).ConfigureAwait(false); + var response = await _connection.RequestAsync(requestData, cancellationToken).ConfigureAwait(false); ThrowBadAuthPipelineExceptionWhenNeeded(response); //sniff should not silently accept bad but valid http responses - if (!response.Success) throw new PipelineException(requestData.OnFailurePipelineFailure, response.OriginalException) { ApiCall = response }; - this._connectionPool.Reseed(response.ToNodes(this._connectionPool.UsingSsl)); - this.Refresh = true; + if (!response.Success) + throw new PipelineException(requestData.OnFailurePipelineFailure, response.OriginalException) { ApiCall = response }; + + _connectionPool.Reseed(response.ToNodes(_connectionPool.UsingSsl)); + Refresh = true; return; } catch (Exception e) @@ -421,138 +483,103 @@ public async Task SniffAsync(CancellationToken cancellationToken) throw new PipelineException(PipelineFailure.SniffFailure, exceptions.AsAggregateOrFirst()); } - private RequestData CreateSniffRequestData(Node node) => - new RequestData(HttpMethod.GET, SniffPath, null, this._settings, this.SniffParameters, this._memoryStreamFactory) - { - Node = node - }; + public void SniffOnConnectionFailure() + { + if (!SniffsOnConnectionFailure) return; - public TResponse CallElasticsearch(RequestData requestData) - where TResponse : class, IElasticsearchResponse, new() + using (Audit(SniffOnFail)) + Sniff(); + } + + public async Task SniffOnConnectionFailureAsync(CancellationToken cancellationToken) { - using (var audit = this.Audit(HealthyResponse)) - { - audit.Node = requestData.Node; - audit.Path = requestData.PathAndQuery; + if (!SniffsOnConnectionFailure) return; - TResponse response = null; - try - { - response = this._connection.Request(requestData); - response.ApiCall.AuditTrail = this.AuditTrail; - ThrowBadAuthPipelineExceptionWhenNeeded(response.ApiCall, response); - if (!response.ApiCall.Success) audit.Event = requestData.OnFailureAuditEvent; - return response; - } - catch (Exception e) - { - (response as ElasticsearchResponse)?.Body?.Dispose(); - audit.Event = requestData.OnFailureAuditEvent; - audit.Exception = e; - throw; - } - } + using (Audit(SniffOnFail)) + await SniffAsync(cancellationToken).ConfigureAwait(false); } - public async Task CallElasticsearchAsync(RequestData requestData, CancellationToken cancellationToken) - where TResponse : class, IElasticsearchResponse, new() + public void SniffOnStaleCluster() { - using (var audit = this.Audit(HealthyResponse)) - { - audit.Node = requestData.Node; - audit.Path = requestData.PathAndQuery; + if (!StaleClusterState) return; - TResponse response = null; - try - { - response = await this._connection.RequestAsync(requestData, cancellationToken).ConfigureAwait(false); - response.ApiCall.AuditTrail = this.AuditTrail; - ThrowBadAuthPipelineExceptionWhenNeeded(response.ApiCall, response); - if (!response.ApiCall.Success) audit.Event = requestData.OnFailureAuditEvent; - return response; - } - catch (Exception e) - { - (response as ElasticsearchResponse)?.Body?.Dispose(); - audit.Event = requestData.OnFailureAuditEvent; - audit.Exception = e; - throw; - } + using (Audit(AuditEvent.SniffOnStaleCluster)) + { + Sniff(); + _connectionPool.SniffedOnStartup = true; } } - public void BadResponse(ref TResponse response, IApiCallDetails callDetails, RequestData data, ElasticsearchClientException exception) - where TResponse : class, IElasticsearchResponse, new() + public async Task SniffOnStaleClusterAsync(CancellationToken cancellationToken) { - if (response == null) + if (!StaleClusterState) return; + + using (Audit(AuditEvent.SniffOnStaleCluster)) { - //make sure we copy over the error body in case we disabled direct streaming. - var s = callDetails?.ResponseBodyInBytes == null ? Stream.Null : new MemoryStream(callDetails.ResponseBodyInBytes); - var m = callDetails?.ResponseMimeType ?? RequestData.MimeType; - response = ResponseBuilder.ToResponse(data, exception, callDetails?.HttpStatusCode, null, s, m); + await SniffAsync(cancellationToken).ConfigureAwait(false); + _connectionPool.SniffedOnStartup = true; } - - response.ApiCall.AuditTrail = this.AuditTrail; } - public ElasticsearchClientException CreateClientException( - TResponse response, IApiCallDetails callDetails, RequestData data, List pipelineExceptions - ) - where TResponse : class, IElasticsearchResponse, new() + public void ThrowNoNodesAttempted(RequestData requestData, List seenExceptions) { - if (callDetails?.Success ?? false) return null; - var innerException = pipelineExceptions.HasAny() ? pipelineExceptions.AsAggregateOrFirst() : callDetails?.OriginalException; - - var statusCode = callDetails?.HttpStatusCode != null ? callDetails.HttpStatusCode.Value.ToString() : "unknown"; - var resource = callDetails == null - ? "unknown resource" - : $"Status code {statusCode} from: {callDetails.HttpMethod} {callDetails.Uri.PathAndQuery}"; + var clientException = new ElasticsearchClientException(PipelineFailure.NoNodesAttempted, NoNodesAttemptedMessage, (Exception)null); + using (Audit(NoNodesAttempted)) + throw new UnexpectedElasticsearchClientException(clientException, seenExceptions) + { + Request = requestData, + AuditTrail = AuditTrail + }; + } + private bool PingDisabled(Node node) => + (RequestConfiguration?.DisablePing).GetValueOrDefault(false) + || _settings.DisablePings || !_connectionPool.SupportsPinging || !node.IsResurrected; - var exceptionMessage = innerException?.Message ?? $"Request failed to execute"; + private Auditable Audit(AuditEvent type) => new Auditable(type, AuditTrail, _dateTimeProvider); - var pipelineFailure = data.OnFailurePipelineFailure; - if (pipelineExceptions.HasAny()) - pipelineFailure = pipelineExceptions.Last().FailureReason; + private RequestData CreatePingRequestData(Node node, Auditable audit) + { + audit.Node = node; - if (this.IsTakingTooLong) - { - pipelineFailure = PipelineFailure.MaxTimeoutReached; - this.Audit(MaxTimeoutReached); - exceptionMessage = "Maximum timeout reached while retrying request"; - } - else if (this.Retried >= this.MaxRetries && this.MaxRetries > 0) + var requestOverrides = new RequestConfiguration { - pipelineFailure = PipelineFailure.MaxRetriesReached; - this.Audit(MaxRetriesReached); - exceptionMessage = "Maximum number of retries reached"; + PingTimeout = PingTimeout, + RequestTimeout = PingTimeout, + BasicAuthenticationCredentials = _settings.BasicAuthenticationCredentials, + EnableHttpPipelining = RequestConfiguration?.EnableHttpPipelining ?? _settings.HttpPipeliningEnabled, + ForceNode = RequestConfiguration?.ForceNode + }; + IRequestParameters requestParameters = new RootNodeInfoRequestParameters(); + requestParameters.RequestConfiguration = requestOverrides; - var now = this._dateTimeProvider.Now(); - // TODO make AliveNodes on IConnectionPool public in 7.0 (default interface C# 8 FTW) - var activeNodes = this._connectionPool.Nodes.Count(n => n.IsAlive || n.DeadUntil <= now); - if (this.Retried >= activeNodes) + var data = new RequestData(HttpMethod.HEAD, "/", null, _settings, requestParameters, _memoryStreamFactory) { Node = node }; + audit.Path = data.PathAndQuery; + return data; + } + + private static void ThrowBadAuthPipelineExceptionWhenNeeded(IApiCallDetails details, IElasticsearchResponse response = null) + { + if (details?.HttpStatusCode == 401) + throw new PipelineException(PipelineFailure.BadAuthentication, details.OriginalException) { - this.Audit(FailedOverAllNodes); - exceptionMessage += ", failed over to all the known alive nodes before failing"; - } - } + Response = response, + ApiCall = details + }; + } - exceptionMessage += $". Call: {resource}"; - if (response != null && response.TryGetServerErrorReason(out var reason)) - exceptionMessage += $". ServerError: {reason}"; + private void LazyAuditable(AuditEvent e, Node n) + { + using (new Auditable(e, AuditTrail, _dateTimeProvider) { Node = n }) { } + ; + } - var clientException = new ElasticsearchClientException(pipelineFailure, exceptionMessage, innerException) + private RequestData CreateSniffRequestData(Node node) => + new RequestData(HttpMethod.GET, SniffPath, null, _settings, SniffParameters, _memoryStreamFactory) { - Request = data, - Response = callDetails, - AuditTrail = this.AuditTrail + Node = node }; - return clientException; - } - - void IDisposable.Dispose() => this.Dispose(); - protected virtual void Dispose() { } } } diff --git a/src/Elasticsearch.Net/Transport/Pipeline/ResponseBuilder.cs b/src/Elasticsearch.Net/Transport/Pipeline/ResponseBuilder.cs index 26c6e21d048..2f32f9fca28 100644 --- a/src/Elasticsearch.Net/Transport/Pipeline/ResponseBuilder.cs +++ b/src/Elasticsearch.Net/Transport/Pipeline/ResponseBuilder.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -12,6 +11,11 @@ public static class ResponseBuilder { public const int BufferSize = 81920; + private static readonly Type[] SpecialTypes = + { typeof(StringResponse), typeof(BytesResponse), typeof(VoidResponse), typeof(DynamicResponse) }; + + private static readonly VoidResponse StaticVoid = new VoidResponse { Body = new VoidResponse.VoidBody() }; + public static TResponse ToResponse( RequestData requestData, Exception ex, @@ -19,7 +23,7 @@ public static TResponse ToResponse( IEnumerable warnings, Stream responseStream, string mimeType = RequestData.MimeType - ) + ) where TResponse : class, IElasticsearchResponse, new() { responseStream.ThrowIfNull(nameof(responseStream)); @@ -37,7 +41,7 @@ public static async Task ToResponseAsync( Stream responseStream, string mimeType = RequestData.MimeType, CancellationToken cancellationToken = default(CancellationToken) - ) + ) where TResponse : class, IElasticsearchResponse, new() { responseStream.ThrowIfNull(nameof(responseStream)); @@ -49,17 +53,16 @@ public static async Task ToResponseAsync( } private static ApiCallDetails Initialize( - RequestData requestData, Exception exception, int? statusCode, IEnumerable warnings, string mimeType) + RequestData requestData, Exception exception, int? statusCode, IEnumerable warnings, string mimeType + ) { var success = false; var allowedStatusCodes = requestData.AllowedStatusCodes.ToList(); if (statusCode.HasValue) - { success = statusCode >= 200 && statusCode < 300 - || (requestData.Method == HttpMethod.HEAD && statusCode == 404) - || allowedStatusCodes.Contains(statusCode.Value) - || allowedStatusCodes.Contains(-1); - } + || requestData.Method == HttpMethod.HEAD && statusCode == 404 + || allowedStatusCodes.Contains(statusCode.Value) + || allowedStatusCodes.Contains(-1); var details = new ApiCallDetails { Success = success, @@ -96,14 +99,16 @@ private static TResponse SetBody(ApiCallDetails details, RequestData return null; if (requestData.CustomConverter != null) return requestData.CustomConverter(details, responseStream) as TResponse; + return mimeType == null || !mimeType.StartsWith(requestData.RequestMimeType, StringComparison.Ordinal) - ? null - : requestData.ConnectionSettings.RequestResponseSerializer.Deserialize(responseStream); + ? null + : requestData.ConnectionSettings.RequestResponseSerializer.Deserialize(responseStream); } } private static async Task SetBodyAsync( - ApiCallDetails details, RequestData requestData, Stream responseStream, string mimeType, CancellationToken cancellationToken) + ApiCallDetails details, RequestData requestData, Stream responseStream, string mimeType, CancellationToken cancellationToken + ) where TResponse : class, IElasticsearchResponse, new() { byte[] bytes = null; @@ -124,18 +129,15 @@ private static async Task SetBodyAsync( return null; if (requestData.CustomConverter != null) return requestData.CustomConverter(details, responseStream) as TResponse; + return mimeType == null || !mimeType.StartsWith(requestData.RequestMimeType, StringComparison.Ordinal) - ? null - : await requestData.ConnectionSettings.RequestResponseSerializer - .DeserializeAsync(responseStream, cancellationToken) - .ConfigureAwait(false); + ? null + : await requestData.ConnectionSettings.RequestResponseSerializer + .DeserializeAsync(responseStream, cancellationToken) + .ConfigureAwait(false); } } - private static readonly VoidResponse StaticVoid = new VoidResponse { Body = new VoidResponse.VoidBody() }; - private static readonly Type[] SpecialTypes = - {typeof(StringResponse), typeof(BytesResponse), typeof(VoidResponse), typeof(DynamicResponse)}; - private static bool SetSpecialTypes(byte[] bytes, out TResponse cs) where TResponse : class, IElasticsearchResponse, new() { diff --git a/src/Elasticsearch.Net/Transport/PostData.cs b/src/Elasticsearch.Net/Transport/PostData.cs index 96639d0cb3a..079ff170c59 100644 --- a/src/Elasticsearch.Net/Transport/PostData.cs +++ b/src/Elasticsearch.Net/Transport/PostData.cs @@ -9,6 +9,7 @@ public interface IPostData { void Write(Stream writableStream, IConnectionConfigurationValues settings); } + public interface IPostData : IPostData { } public enum PostType @@ -23,60 +24,90 @@ public enum PostType public abstract class PostData { protected const int BufferSize = 81920; - protected static readonly byte[] NewLineByteArray = { (byte)'\n' }; protected const string NewLineString = "\n"; + protected static readonly byte[] NewLineByteArray = { (byte)'\n' }; public bool? DisableDirectStreaming { get; set; } - public byte[] WrittenBytes { get; protected set; } public PostType Type { get; protected set; } + public byte[] WrittenBytes { get; protected set; } public abstract void Write(Stream writableStream, IConnectionConfigurationValues settings); public abstract Task WriteAsync(Stream writableStream, IConnectionConfigurationValues settings, CancellationToken cancellationToken); - public static implicit operator PostData(byte[] byteArray) => PostData.Bytes(byteArray); - public static implicit operator PostData(string literalString) => PostData.String(literalString); + public static implicit operator PostData(byte[] byteArray) => Bytes(byteArray); + + public static implicit operator PostData(string literalString) => String(literalString); public static SerializableData Serializable(T o) => new SerializableData(o); + public static PostData MultiJson(IEnumerable listOfString) => new PostData(listOfString); + public static PostData MultiJson(IEnumerable listOfObjects) => new PostData(listOfObjects); + public static PostData Bytes(byte[] bytes) => new PostData(bytes); + public static PostData String(string serializedString) => new PostData(serializedString); } public class PostData : PostData, IPostData { - private readonly string _literalString; - private readonly IEnumerable _enumurableOfStrings; private readonly IEnumerable _enumerableOfObject; + private readonly IEnumerable _enumurableOfStrings; + private readonly string _literalString; private readonly T _serializable; - protected internal PostData(byte[] item) { WrittenBytes = item; Type = PostType.ByteArray; } - protected internal PostData(string item) { _literalString = item; Type = PostType.LiteralString; } - protected internal PostData(IEnumerable item) { _enumurableOfStrings = item; Type = PostType.EnumerableOfString; } - protected internal PostData(IEnumerable item) { _enumerableOfObject = item; Type = PostType.EnumerableOfObject; } + protected internal PostData(byte[] item) + { + WrittenBytes = item; + Type = PostType.ByteArray; + } + + protected internal PostData(string item) + { + _literalString = item; + Type = PostType.LiteralString; + } + + protected internal PostData(IEnumerable item) + { + _enumurableOfStrings = item; + Type = PostType.EnumerableOfString; + } + + protected internal PostData(IEnumerable item) + { + _enumerableOfObject = item; + Type = PostType.EnumerableOfObject; + } + private PostData(T item) { var boxedType = item.GetType(); if (typeof(byte[]).AssignableFrom(boxedType)) { - WrittenBytes = item as byte[]; Type = PostType.ByteArray; + WrittenBytes = item as byte[]; + Type = PostType.ByteArray; } else if (typeof(string).AssignableFrom(boxedType)) { - _literalString = item as string; Type = PostType.LiteralString; + _literalString = item as string; + Type = PostType.LiteralString; } else if (typeof(IEnumerable).AssignableFrom(boxedType)) { - _enumurableOfStrings = (IEnumerable)item; Type = PostType.EnumerableOfString; + _enumurableOfStrings = (IEnumerable)item; + Type = PostType.EnumerableOfString; } else if (typeof(IEnumerable).AssignableFrom(boxedType)) { - _enumerableOfObject = (IEnumerable)item; Type = PostType.EnumerableOfObject; + _enumerableOfObject = (IEnumerable)item; + Type = PostType.EnumerableOfObject; } else { - _serializable = item; Type = PostType.Serializable; + _serializable = item; + Type = PostType.Serializable; } } @@ -94,12 +125,14 @@ public override void Write(Stream writableStream, IConnectionConfigurationValues ms = !string.IsNullOrEmpty(_literalString) ? new MemoryStream(_literalString?.Utf8Bytes()) : null; break; case PostType.EnumerableOfString: - ms = _enumurableOfStrings.HasAny() ? new MemoryStream((string.Join(NewLineString, _enumurableOfStrings) + NewLineString).Utf8Bytes()) : null; + ms = _enumurableOfStrings.HasAny() + ? new MemoryStream((string.Join(NewLineString, _enumurableOfStrings) + NewLineString).Utf8Bytes()) + : null; break; case PostType.EnumerableOfObject: if (!_enumerableOfObject.HasAny()) return; - if (this.DisableDirectStreaming ?? settings.DisableDirectStreaming) + if (DisableDirectStreaming ?? settings.DisableDirectStreaming) { ms = new MemoryStream(); stream = ms; @@ -113,12 +146,12 @@ public override void Write(Stream writableStream, IConnectionConfigurationValues break; case PostType.Serializable: stream = writableStream; - if (this.DisableDirectStreaming ?? settings.DisableDirectStreaming) + if (DisableDirectStreaming ?? settings.DisableDirectStreaming) { ms = new MemoryStream(); stream = ms; } - settings.RequestResponseSerializer.Serialize(this._serializable, stream, indent); + settings.RequestResponseSerializer.Serialize(_serializable, stream, indent); break; } if (ms != null) @@ -126,14 +159,15 @@ public override void Write(Stream writableStream, IConnectionConfigurationValues ms.Position = 0; ms.CopyTo(writableStream, BufferSize); } - if (this.Type != 0) - this.WrittenBytes = ms?.ToArray(); + if (Type != 0) + WrittenBytes = ms?.ToArray(); } public override async Task WriteAsync(Stream writableStream, IConnectionConfigurationValues settings, CancellationToken cancellationToken) { var indent = settings.PrettyJson ? SerializationFormatting.Indented : SerializationFormatting.None; - MemoryStream ms = null; Stream stream = null; + MemoryStream ms = null; + Stream stream = null; switch (Type) { case PostType.ByteArray: @@ -143,11 +177,14 @@ public override async Task WriteAsync(Stream writableStream, IConnectionConfigur ms = !string.IsNullOrEmpty(_literalString) ? new MemoryStream(_literalString.Utf8Bytes()) : null; break; case PostType.EnumerableOfString: - ms = _enumurableOfStrings.HasAny() ? new MemoryStream((string.Join(NewLineString, _enumurableOfStrings) + NewLineString).Utf8Bytes()) : null; + ms = _enumurableOfStrings.HasAny() + ? new MemoryStream((string.Join(NewLineString, _enumurableOfStrings) + NewLineString).Utf8Bytes()) + : null; break; case PostType.EnumerableOfObject: if (!_enumerableOfObject.HasAny()) return; - if (this.DisableDirectStreaming ?? settings.DisableDirectStreaming) + + if (DisableDirectStreaming ?? settings.DisableDirectStreaming) { ms = new MemoryStream(); stream = ms; @@ -155,18 +192,19 @@ public override async Task WriteAsync(Stream writableStream, IConnectionConfigur else stream = writableStream; foreach (var o in _enumerableOfObject) { - await settings.RequestResponseSerializer.SerializeAsync(o, stream, SerializationFormatting.None, cancellationToken).ConfigureAwait(false); + await settings.RequestResponseSerializer.SerializeAsync(o, stream, SerializationFormatting.None, cancellationToken) + .ConfigureAwait(false); await stream.WriteAsync(NewLineByteArray, 0, 1, cancellationToken).ConfigureAwait(false); } break; case PostType.Serializable: stream = writableStream; - if (this.DisableDirectStreaming ?? settings.DisableDirectStreaming) + if (DisableDirectStreaming ?? settings.DisableDirectStreaming) { ms = new MemoryStream(); stream = ms; } - await settings.RequestResponseSerializer.SerializeAsync(this._serializable, stream, indent, cancellationToken).ConfigureAwait(false); + await settings.RequestResponseSerializer.SerializeAsync(_serializable, stream, indent, cancellationToken).ConfigureAwait(false); break; } if (ms != null) @@ -174,8 +212,8 @@ public override async Task WriteAsync(Stream writableStream, IConnectionConfigur ms.Position = 0; await ms.CopyToAsync(writableStream, BufferSize, cancellationToken).ConfigureAwait(false); } - if (this.Type != 0) - this.WrittenBytes = ms?.ToArray(); + if (Type != 0) + WrittenBytes = ms?.ToArray(); } } } diff --git a/src/Elasticsearch.Net/Transport/SerializableData.cs b/src/Elasticsearch.Net/Transport/SerializableData.cs index 8c8c43bab55..fc084b92be1 100644 --- a/src/Elasticsearch.Net/Transport/SerializableData.cs +++ b/src/Elasticsearch.Net/Transport/SerializableData.cs @@ -13,46 +13,47 @@ public SerializableData(T item) Type = PostType.Serializable; _serializable = item; } - public static implicit operator SerializableData(T serialiableData) => new SerializableData(serialiableData); public override void Write(Stream writableStream, IConnectionConfigurationValues settings) { var indent = settings.PrettyJson ? SerializationFormatting.Indented : SerializationFormatting.None; var stream = writableStream; MemoryStream ms = null; - if (this.DisableDirectStreaming ?? settings.DisableDirectStreaming) + if (DisableDirectStreaming ?? settings.DisableDirectStreaming) { ms = new MemoryStream(); stream = ms; } - settings.RequestResponseSerializer.Serialize(this._serializable, stream, indent); + settings.RequestResponseSerializer.Serialize(_serializable, stream, indent); if (ms != null) { ms.Position = 0; ms.CopyTo(writableStream, BufferSize); } - if (this.Type != 0) - this.WrittenBytes = ms?.ToArray(); + if (Type != 0) + WrittenBytes = ms?.ToArray(); } + public static implicit operator SerializableData(T serialiableData) => new SerializableData(serialiableData); + public override async Task WriteAsync(Stream writableStream, IConnectionConfigurationValues settings, CancellationToken cancellationToken) { var indent = settings.PrettyJson ? SerializationFormatting.Indented : SerializationFormatting.None; var stream = writableStream; MemoryStream ms = null; - if (this.DisableDirectStreaming ?? settings.DisableDirectStreaming) + if (DisableDirectStreaming ?? settings.DisableDirectStreaming) { ms = new MemoryStream(); stream = ms; } - await settings.RequestResponseSerializer.SerializeAsync(this._serializable, stream, indent, cancellationToken).ConfigureAwait(false); + await settings.RequestResponseSerializer.SerializeAsync(_serializable, stream, indent, cancellationToken).ConfigureAwait(false); if (ms != null) { ms.Position = 0; await ms.CopyToAsync(writableStream, BufferSize, cancellationToken).ConfigureAwait(false); } - if (this.Type != 0) - this.WrittenBytes = ms?.ToArray(); + if (Type != 0) + WrittenBytes = ms?.ToArray(); } } } diff --git a/src/Elasticsearch.Net/Transport/Transport.cs b/src/Elasticsearch.Net/Transport/Transport.cs index 425ae3ffb42..d68ecb3e312 100644 --- a/src/Elasticsearch.Net/Transport/Transport.cs +++ b/src/Elasticsearch.Net/Transport/Transport.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using System.Threading; -using System; +using System; +using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; #if !DOTNETCORE using System.Net; + #endif namespace Elasticsearch.Net @@ -12,12 +13,6 @@ namespace Elasticsearch.Net public class Transport : ITransport where TConnectionSettings : IConnectionConfigurationValues { - public TConnectionSettings Settings { get; } - - private IDateTimeProvider DateTimeProvider { get; } - private IMemoryStreamFactory MemoryStreamFactory { get; } - private IRequestPipelineFactory PipelineProvider { get; } - /// /// Transport coordinates the client requests over the connection pool nodes and is in charge of falling over on different nodes /// @@ -36,28 +31,34 @@ public Transport( IRequestPipelineFactory pipelineProvider, IDateTimeProvider dateTimeProvider, IMemoryStreamFactory memoryStreamFactory - ) + ) { configurationValues.ThrowIfNull(nameof(configurationValues)); configurationValues.ConnectionPool.ThrowIfNull(nameof(configurationValues.ConnectionPool)); configurationValues.Connection.ThrowIfNull(nameof(configurationValues.Connection)); configurationValues.RequestResponseSerializer.ThrowIfNull(nameof(configurationValues.RequestResponseSerializer)); - this.Settings = configurationValues; - this.PipelineProvider = pipelineProvider ?? new RequestPipelineFactory(); - this.DateTimeProvider = dateTimeProvider ?? Elasticsearch.Net.DateTimeProvider.Default; - this.MemoryStreamFactory = memoryStreamFactory ?? configurationValues.MemoryStreamFactory; + Settings = configurationValues; + PipelineProvider = pipelineProvider ?? new RequestPipelineFactory(); + DateTimeProvider = dateTimeProvider ?? Net.DateTimeProvider.Default; + MemoryStreamFactory = memoryStreamFactory ?? configurationValues.MemoryStreamFactory; } + public TConnectionSettings Settings { get; } + + private IDateTimeProvider DateTimeProvider { get; } + private IMemoryStreamFactory MemoryStreamFactory { get; } + private IRequestPipelineFactory PipelineProvider { get; } + public TResponse Request(HttpMethod method, string path, PostData data = null, IRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new() { - using (var pipeline = this.PipelineProvider.Create(this.Settings, this.DateTimeProvider, this.MemoryStreamFactory, requestParameters)) + using (var pipeline = PipelineProvider.Create(Settings, DateTimeProvider, MemoryStreamFactory, requestParameters)) { - pipeline.FirstPoolUsage(this.Settings.BootstrapLock); + pipeline.FirstPoolUsage(Settings.BootstrapLock); - var requestData = new RequestData(method, path, data, this.Settings, requestParameters, this.MemoryStreamFactory); - this.Settings.OnRequestDataCreated?.Invoke(requestData); + var requestData = new RequestData(method, path, data, Settings, requestParameters, MemoryStreamFactory); + Settings.OnRequestDataCreated?.Invoke(requestData); TResponse response = null; var seenExceptions = new List(); @@ -94,6 +95,7 @@ public TResponse Request(HttpMethod method, string path, PostData dat }; } if (response == null || !response.ApiCall.SuccessOrKnownError) continue; + pipeline.MarkAlive(node); break; } @@ -101,15 +103,17 @@ public TResponse Request(HttpMethod method, string path, PostData dat } } - public async Task RequestAsync(HttpMethod method, string path, CancellationToken cancellationToken, PostData data = null, IRequestParameters requestParameters = null) + public async Task RequestAsync(HttpMethod method, string path, CancellationToken cancellationToken, + PostData data = null, IRequestParameters requestParameters = null + ) where TResponse : class, IElasticsearchResponse, new() { - using (var pipeline = this.PipelineProvider.Create(this.Settings, this.DateTimeProvider, this.MemoryStreamFactory, requestParameters)) + using (var pipeline = PipelineProvider.Create(Settings, DateTimeProvider, MemoryStreamFactory, requestParameters)) { - await pipeline.FirstPoolUsageAsync(this.Settings.BootstrapLock, cancellationToken).ConfigureAwait(false); + await pipeline.FirstPoolUsageAsync(Settings.BootstrapLock, cancellationToken).ConfigureAwait(false); - var requestData = new RequestData(method, path, data, this.Settings, requestParameters, this.MemoryStreamFactory); - this.Settings.OnRequestDataCreated?.Invoke(requestData); + var requestData = new RequestData(method, path, data, Settings, requestParameters, MemoryStreamFactory); + Settings.OnRequestDataCreated?.Invoke(requestData); TResponse response = null; var seenExceptions = new List(); @@ -151,6 +155,7 @@ public async Task RequestAsync(HttpMethod method, string p break; } if (response == null || !response.ApiCall.SuccessOrKnownError) continue; + pipeline.MarkAlive(node); break; } @@ -159,7 +164,8 @@ public async Task RequestAsync(HttpMethod method, string p } private static void HandlePipelineException( - ref TResponse response, PipelineException ex, IRequestPipeline pipeline, Node node, List seenExceptions) + ref TResponse response, PipelineException ex, IRequestPipeline pipeline, Node node, List seenExceptions + ) where TResponse : class, IElasticsearchResponse, new() { if (response == null) response = ex.Response as TResponse; @@ -168,7 +174,8 @@ private static void HandlePipelineException( } private TResponse FinalizeResponse(RequestData requestData, IRequestPipeline pipeline, List seenExceptions, - TResponse response) where TResponse : class, IElasticsearchResponse, new() + TResponse response + ) where TResponse : class, IElasticsearchResponse, new() { if (requestData.Node == null) //foreach never ran pipeline.ThrowNoNodesAttempted(requestData, seenExceptions); @@ -186,7 +193,7 @@ private TResponse FinalizeResponse(RequestData requestData, IRequestP private static IApiCallDetails GetMostRecentCallDetails(TResponse response, IEnumerable seenExceptions) where TResponse : class, IElasticsearchResponse, new() { - var callDetails = response?.ApiCall ?? seenExceptions.LastOrDefault(e=>e.ApiCall != null)?.ApiCall; + var callDetails = response?.ApiCall ?? seenExceptions.LastOrDefault(e => e.ApiCall != null)?.ApiCall; return callDetails; } @@ -209,7 +216,7 @@ private void HandleElasticsearchClientException(RequestData data, Exception clie #endif } - this.Settings.OnRequestCompleted?.Invoke(response.ApiCall); + Settings.OnRequestCompleted?.Invoke(response.ApiCall); if (clientException != null && data.ThrowExceptions) throw clientException; } @@ -238,6 +245,5 @@ private static async Task PingAsync(IRequestPipeline pipeline, Node node, Cancel throw; } } - } } diff --git a/src/Elasticsearch.sln.DotSettings b/src/Elasticsearch.sln.DotSettings index c5e478c115b..c0aa08ce146 100644 --- a/src/Elasticsearch.sln.DotSettings +++ b/src/Elasticsearch.sln.DotSettings @@ -1,17 +1,23 @@  True 56A87048-9065-459B-826D-3DF68B409845/d:Views + + *.Doc.cs + True HINT - <?xml version="1.0" encoding="utf-16"?><Profile name="SilentCodeCleanUp"><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUseVar><BehavourStyle>CAN_CHANGE_TO_IMPLICIT</BehavourStyle><LocalVariableStyle>IMPLICIT_WHEN_INITIALIZER_HAS_TYPE</LocalVariableStyle><ForeachVariableStyle>ALWAYS_IMPLICIT</ForeachVariableStyle></CSUseVar><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSReorderTypeMembers>True</CSReorderTypeMembers><JsInsertSemicolon>True</JsInsertSemicolon><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><XMLReformatCode>True</XMLReformatCode><CssReformatCode>True</CssReformatCode><CssAlphabetizeProperties>True</CssAlphabetizeProperties><StyleCop.Documentation><SA1600ElementsMustBeDocumented>False</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>False</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>False</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>False</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>False</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>False</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>False</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>False</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>False</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>False</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>Ignore</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>False</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>False</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>False</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><IDEA_SETTINGS>&lt;profile version="1.0"&gt; + <?xml version="1.0" encoding="utf-16"?><Profile name="SilentCodeCleanUp"><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUseVar><BehavourStyle>CAN_CHANGE_TO_IMPLICIT</BehavourStyle><LocalVariableStyle>IMPLICIT_WHEN_INITIALIZER_HAS_TYPE</LocalVariableStyle><ForeachVariableStyle>ALWAYS_IMPLICIT</ForeachVariableStyle></CSUseVar><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSReorderTypeMembers>True</CSReorderTypeMembers><JsInsertSemicolon>True</JsInsertSemicolon><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><XMLReformatCode>True</XMLReformatCode><CssReformatCode>True</CssReformatCode><CssAlphabetizeProperties>True</CssAlphabetizeProperties><StyleCop.Documentation><SA1600ElementsMustBeDocumented>False</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>False</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>False</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>False</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>False</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>False</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>False</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>False</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>False</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>False</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>Ignore</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>False</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>False</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>False</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><CSArrangeQualifiers>True</CSArrangeQualifiers><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" /><IDEA_SETTINGS>&lt;profile version="1.0"&gt; &lt;option name="myName" value="SilentCodeCleanUp" /&gt; -&lt;/profile&gt;</IDEA_SETTINGS><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="False" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="False" ArrangeArgumentsStyle="False" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" /><CSArrangeQualifiers>True</CSArrangeQualifiers></Profile> +&lt;/profile&gt;</IDEA_SETTINGS></Profile> SilentCodeCleanUp SilentCodeCleanUp False OPTIMAL_FILL - 1 + 0 + 1 + 0 1 - 1 + 0 + TOGETHER_SAME_LINE ALWAYS_ADD ALWAYS_ADD ALWAYS_ADD @@ -32,11 +38,15 @@ False False True + True True True - True + False + CHOP_IF_LONG 150 CHOP_IF_LONG + DoNotTouch + DoNotTouch <?xml version="1.0" encoding="utf-16"?> <Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"> <TypePattern DisplayName="COM interfaces or structs" RemoveRegions="All" Priority="100"> @@ -225,12 +235,7 @@ <Name Is="Enter Pattern Here" /> </Entry.SortBy> </Entry> - <Entry DisplayName="All other members"> - <Entry.SortBy> - <Access /> - <Name Is="Enter Pattern Here" /> - </Entry.SortBy> - </Entry> + <Entry DisplayName="All other members" /> <Entry DisplayName="Nested Types"> <Entry.Match> <Kind Is="Type" /> @@ -462,68 +467,15 @@ True False KM - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - LIVE_MONITOR - LIVE_MONITOR - DO_NOTHING - LIVE_MONITOR - LIVE_MONITOR - LIVE_MONITOR - LIVE_MONITOR - LIVE_MONITOR - LIVE_MONITOR - LIVE_MONITOR - LIVE_MONITOR - DO_NOTHING - LIVE_MONITOR True True True True True + False True HotTrack Hack (?<=\W|^)(?<TAG>HACK)(\W|$)(.*) Warning - True \ No newline at end of file + True diff --git a/src/Nest/Aggregations/AggregateDictionary.cs b/src/Nest/Aggregations/AggregateDictionary.cs index 94fcf5ab8c6..fa46421ce6f 100644 --- a/src/Nest/Aggregations/AggregateDictionary.cs +++ b/src/Nest/Aggregations/AggregateDictionary.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Newtonsoft.Json.Linq; namespace Nest { @@ -12,10 +11,12 @@ namespace Nest [ContractJsonConverter(typeof(AggregateDictionaryConverter))] public class AggregateDictionary : IsAReadOnlyDictionaryBase { - public static AggregateDictionary Default { get; } = new AggregateDictionary(EmptyReadOnly.Dictionary); + internal static readonly char[] TypedKeysSeparator = { '#' }; public AggregateDictionary(IReadOnlyDictionary backingDictionary) : base(backingDictionary) { } + public static AggregateDictionary Default { get; } = new AggregateDictionary(EmptyReadOnly.Dictionary); + protected override string Sanitize(string key) { //typed_keys = true on results in aggregation keys being returned as "#" @@ -23,103 +24,102 @@ protected override string Sanitize(string key) return tokens.Length > 1 ? tokens[1] : tokens[0]; } - internal static readonly char[] TypedKeysSeparator = {'#'}; internal static string[] TypedKeyTokens(string key) { var tokens = key.Split(TypedKeysSeparator, 2, StringSplitOptions.RemoveEmptyEntries); return tokens; } - public ValueAggregate Min(string key) => this.TryGet(key); + public ValueAggregate Min(string key) => TryGet(key); - public ValueAggregate Max(string key) => this.TryGet(key); + public ValueAggregate Max(string key) => TryGet(key); - public ValueAggregate Sum(string key) => this.TryGet(key); + public ValueAggregate Sum(string key) => TryGet(key); - public ValueAggregate Cardinality(string key) => this.TryGet(key); + public ValueAggregate Cardinality(string key) => TryGet(key); - public ValueAggregate Average(string key) => this.TryGet(key); + public ValueAggregate Average(string key) => TryGet(key); - public ValueAggregate ValueCount(string key) => this.TryGet(key); + public ValueAggregate ValueCount(string key) => TryGet(key); - public ValueAggregate AverageBucket(string key) => this.TryGet(key); + public ValueAggregate AverageBucket(string key) => TryGet(key); - public ValueAggregate Derivative(string key) => this.TryGet(key); + public ValueAggregate Derivative(string key) => TryGet(key); - public ValueAggregate SumBucket(string key) => this.TryGet(key); + public ValueAggregate SumBucket(string key) => TryGet(key); - public ValueAggregate MovingAverage(string key) => this.TryGet(key); + public ValueAggregate MovingAverage(string key) => TryGet(key); - public ValueAggregate CumulativeSum(string key) => this.TryGet(key); + public ValueAggregate CumulativeSum(string key) => TryGet(key); - public ValueAggregate BucketScript(string key) => this.TryGet(key); + public ValueAggregate BucketScript(string key) => TryGet(key); - public ValueAggregate SerialDifferencing(string key) => this.TryGet(key); + public ValueAggregate SerialDifferencing(string key) => TryGet(key); - public ValueAggregate WeightedAverage(string key) => this.TryGet(key); + public ValueAggregate WeightedAverage(string key) => TryGet(key); - public KeyedValueAggregate MaxBucket(string key) => this.TryGet(key); + public KeyedValueAggregate MaxBucket(string key) => TryGet(key); - public KeyedValueAggregate MinBucket(string key) => this.TryGet(key); + public KeyedValueAggregate MinBucket(string key) => TryGet(key); public ScriptedMetricAggregate ScriptedMetric(string key) { - var valueMetric = this.TryGet(key); + var valueMetric = TryGet(key); return valueMetric != null ? new ScriptedMetricAggregate(valueMetric.Value) { Meta = valueMetric.Meta } - : this.TryGet(key); + : TryGet(key); } - public StatsAggregate Stats(string key) => this.TryGet(key); + public StatsAggregate Stats(string key) => TryGet(key); - public StatsAggregate StatsBucket(string key) => this.TryGet(key); + public StatsAggregate StatsBucket(string key) => TryGet(key); - public ExtendedStatsAggregate ExtendedStats(string key) => this.TryGet(key); + public ExtendedStatsAggregate ExtendedStats(string key) => TryGet(key); - public ExtendedStatsAggregate ExtendedStatsBucket(string key) => this.TryGet(key); + public ExtendedStatsAggregate ExtendedStatsBucket(string key) => TryGet(key); - public GeoBoundsAggregate GeoBounds(string key) => this.TryGet(key); + public GeoBoundsAggregate GeoBounds(string key) => TryGet(key); - public PercentilesAggregate Percentiles(string key) => this.TryGet(key); + public PercentilesAggregate Percentiles(string key) => TryGet(key); - public PercentilesAggregate PercentilesBucket(string key) => this.TryGet(key); + public PercentilesAggregate PercentilesBucket(string key) => TryGet(key); - public PercentilesAggregate PercentileRanks(string key) => this.TryGet(key); + public PercentilesAggregate PercentileRanks(string key) => TryGet(key); - public TopHitsAggregate TopHits(string key) => this.TryGet(key); + public TopHitsAggregate TopHits(string key) => TryGet(key); public FiltersAggregate Filters(string key) { - var named = this.TryGet(key); + var named = TryGet(key); if (named != null) return named; - var anonymous = this.TryGet(key); + var anonymous = TryGet(key); return anonymous != null ? new FiltersAggregate { Buckets = anonymous.Items.OfType().ToList(), Meta = anonymous.Meta } : null; } - public SingleBucketAggregate Global(string key) => this.TryGet(key); + public SingleBucketAggregate Global(string key) => TryGet(key); - public SingleBucketAggregate Filter(string key) => this.TryGet(key); + public SingleBucketAggregate Filter(string key) => TryGet(key); - public SingleBucketAggregate Missing(string key) => this.TryGet(key); + public SingleBucketAggregate Missing(string key) => TryGet(key); - public SingleBucketAggregate Nested(string key) => this.TryGet(key); + public SingleBucketAggregate Nested(string key) => TryGet(key); - public SingleBucketAggregate ReverseNested(string key) => this.TryGet(key); + public SingleBucketAggregate ReverseNested(string key) => TryGet(key); - public SingleBucketAggregate Children(string key) => this.TryGet(key); + public SingleBucketAggregate Children(string key) => TryGet(key); - public SingleBucketAggregate Sampler(string key) => this.TryGet(key); + public SingleBucketAggregate Sampler(string key) => TryGet(key); - public GeoCentroidAggregate GeoCentroid(string key) => this.TryGet(key); + public GeoCentroidAggregate GeoCentroid(string key) => TryGet(key); public SignificantTermsAggregate SignificantTerms(string key) { - var bucket = this.TryGet(key); + var bucket = TryGet(key); return bucket == null ? null : new SignificantTermsAggregate @@ -133,7 +133,7 @@ public SignificantTermsAggregate SignificantTerms(string key) public SignificantTermsAggregate SignificantText(string key) { - var bucket = this.TryGet(key); + var bucket = TryGet(key); return bucket == null ? null : new SignificantTermsAggregate @@ -147,7 +147,7 @@ public SignificantTermsAggregate SignificantText(string key) public TermsAggregate Terms(string key) { - var bucket = this.TryGet(key); + var bucket = TryGet(key); return bucket == null ? null : new TermsAggregate @@ -179,8 +179,9 @@ public TermsAggregate Terms(string key) public CompositeBucketAggregate Composite(string key) { - var bucket = this.TryGet(key); + var bucket = TryGet(key); if (bucket == null) return null; + return new CompositeBucketAggregate { Buckets = bucket.Items.OfType().ToList(), @@ -189,30 +190,33 @@ public CompositeBucketAggregate Composite(string key) }; } - public MatrixStatsAggregate MatrixStats(string key) => this.TryGet(key); + public MatrixStatsAggregate MatrixStats(string key) => TryGet(key); private TAggregate TryGet(string key) where TAggregate : class, IAggregate { IAggregate agg; - return this.BackingDictionary.TryGetValue(key, out agg) ? agg as TAggregate : null; + return BackingDictionary.TryGetValue(key, out agg) ? agg as TAggregate : null; } private MultiBucketAggregate GetMultiBucketAggregate(string key) where TBucket : IBucket { - var bucket = this.TryGet(key); + var bucket = TryGet(key); if (bucket == null) return null; + return new MultiBucketAggregate { Buckets = bucket.Items.OfType().ToList(), Meta = bucket.Meta, }; } + private MultiBucketAggregate> GetMultiKeyedBucketAggregate(string key) { - var bucket = this.TryGet(key); + var bucket = TryGet(key); if (bucket == null) return null; + return new MultiBucketAggregate> { Buckets = GetKeyedBuckets(bucket.Items).ToList(), @@ -226,7 +230,6 @@ private IEnumerable> GetKeyedBuckets(IEnumerable>(); foreach (var bucket in buckets) - { yield return new KeyedBucket(bucket.BackingDictionary) { Key = (TKey)Convert.ChangeType(bucket.Key, typeof(TKey)), @@ -234,8 +237,6 @@ private IEnumerable> GetKeyedBuckets(IEnumerable(JsonReader reader, JsonSerializer serializer, Dictionary dictionary, string name) + private static void ReadAggregate(JsonReader reader, JsonSerializer serializer, Dictionary dictionary, + string name + ) where TAggregate : IAggregate { reader.Read(); diff --git a/src/Nest/Aggregations/AggregateJsonConverter.cs b/src/Nest/Aggregations/AggregateJsonConverter.cs index d7b0f86c105..3585924fe4e 100644 --- a/src/Nest/Aggregations/AggregateJsonConverter.cs +++ b/src/Nest/Aggregations/AggregateJsonConverter.cs @@ -13,63 +13,6 @@ internal class AggregateJsonConverter : JsonConverter { private static readonly Regex _numeric = new Regex(@"^[\d.]+(\.[\d.]+)?$"); - public override bool CanWrite => false; - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, - JsonSerializer serializer) => this.ReadAggregate(reader, serializer); - - public override bool CanConvert(Type objectType) => objectType == typeof(IAggregate); - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => - throw new NotSupportedException(); - - private static class Parser - { - public const string Values = "values"; - public const string Value = "value"; - public const string Buckets = "buckets"; - public const string DocCountErrorUpperBound = "doc_count_error_upper_bound"; - public const string Count = "count"; - public const string DocCount = "doc_count"; - public const string BgCount = "bg_count"; - public const string Bounds = "bounds"; - public const string Hits = "hits"; - public const string Location = "location"; - public const string Fields = "fields"; - public const string AfterKey = "after_key"; - - public const string Key = "key"; - public const string From = "from"; - public const string To = "to"; - public const string KeyAsString = "key_as_string"; - - public const string Total = "total"; - public const string MaxScore = "max_score"; - - public const string TopLeft = "top_left"; - public const string BottomRight = "bottom_right"; - - public const string AsStringSuffix = "_as_string"; - - public const string Upper = "upper"; - public const string Lower = "lower"; - public const string StdDeviationBoundsAsString = "std_deviation_bounds_as_string"; - - public const string SumOtherDocCount = "sum_other_doc_count"; - - public const string ValueAsString = "value_as_string"; - public const string Keys = "keys"; - - public const string FromAsString = "from_as_string"; - public const string ToAsString = "to_as_string"; - - public const string Score = "score"; - public const string Meta = "meta"; - } - - public static string[] AllReservedAggregationNames { get; } - public static string UsingReservedAggNameFormat { get; } - static AggregateJsonConverter() { AllReservedAggregationNames = typeof(Parser) @@ -91,10 +34,25 @@ static AggregateJsonConverter() + allKeys; } + public static string[] AllReservedAggregationNames { get; } + + public override bool CanWrite => false; + public static string UsingReservedAggNameFormat { get; } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, + JsonSerializer serializer + ) => ReadAggregate(reader, serializer); + + public override bool CanConvert(Type objectType) => objectType == typeof(IAggregate); + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => + throw new NotSupportedException(); + private IAggregate ReadAggregate(JsonReader reader, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) return null; + reader.Read(); if (reader.TokenType != JsonToken.PropertyName) @@ -102,9 +60,9 @@ private IAggregate ReadAggregate(JsonReader reader, JsonSerializer serializer) IAggregate aggregate = null; - var propertyName = (string) reader.Value; + var propertyName = (string)reader.Value; if (_numeric.IsMatch(propertyName)) - aggregate = GetPercentilesAggregate(reader, serializer, oldFormat: true); + aggregate = GetPercentilesAggregate(reader, serializer, true); var meta = propertyName == Parser.Meta ? GetMetadata(serializer, reader) @@ -116,7 +74,7 @@ private IAggregate ReadAggregate(JsonReader reader, JsonSerializer serializer) return aggregate; } - propertyName = (string) reader.Value; + propertyName = (string)reader.Value; switch (propertyName) { case Parser.Values: @@ -132,7 +90,7 @@ private IAggregate ReadAggregate(JsonReader reader, JsonSerializer serializer) var afterKeys = serializer.Deserialize>(reader); reader.Read(); var bucketAggregate = reader.Value.ToString() == Parser.Buckets - ? this.GetMultiBucketAggregate(reader, serializer) as BucketAggregate ?? new BucketAggregate() + ? GetMultiBucketAggregate(reader, serializer) as BucketAggregate ?? new BucketAggregate() : new BucketAggregate(); bucketAggregate.AfterKey = afterKeys; aggregate = bucketAggregate; @@ -170,13 +128,14 @@ private IBucket ReadBucket(JsonReader reader, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) return null; + reader.Read(); if (reader.TokenType != JsonToken.PropertyName) return null; IBucket item; - var property = (string) reader.Value; + var property = (string)reader.Value; switch (property) { case Parser.Key: @@ -211,7 +170,7 @@ private Dictionary GetMetadata(JsonSerializer serializer, JsonRe private IAggregate GetMatrixStatsAggregate(JsonReader reader, JsonSerializer serializer, long? docCount = null) { reader.Read(); - var matrixStats = new MatrixStatsAggregate {DocCount = docCount}; + var matrixStats = new MatrixStatsAggregate { DocCount = docCount }; var array = JArray.Load(reader); matrixStats.Fields = array.ToObject>(); return matrixStats; @@ -230,7 +189,7 @@ private IAggregate GetTopHitsAggregate(JsonReader reader, JsonSerializer seriali reader.Read(); //using request/response serializer here because doc is wrapped in NEST's Hit var s = serializer.GetConnectionSettings().RequestResponseSerializer; - var lazyHits = hits.Select(h => new LazyDocument(h,s)).ToList(); + var lazyHits = hits.Select(h => new LazyDocument(h, s)).ToList(); return new TopHitsAggregate(lazyHits) { Total = total, @@ -241,12 +200,12 @@ private IAggregate GetTopHitsAggregate(JsonReader reader, JsonSerializer seriali private IAggregate GetGeoCentroidAggregate(JsonReader reader, JsonSerializer serializer) { reader.Read(); - var geoCentroid = new GeoCentroidAggregate {Location = serializer.Deserialize(reader)}; + var geoCentroid = new GeoCentroidAggregate { Location = serializer.Deserialize(reader) }; reader.Read(); - if (reader.TokenType == JsonToken.PropertyName && (string) reader.Value == Parser.Count) + if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == Parser.Count) { reader.Read(); - geoCentroid.Count = (long) reader.Value; + geoCentroid.Count = (long)reader.Value; reader.Read(); } return geoCentroid; @@ -258,6 +217,7 @@ private IAggregate GetGeoBoundsAggregate(JsonReader reader, JsonSerializer seria var o = JObject.Load(reader); if (o == null) return null; + var geoBoundsMetric = new GeoBoundsAggregate(); if (o.TryGetValue(Parser.TopLeft, out var topLeftToken) && topLeftToken != null) { @@ -284,7 +244,7 @@ private IAggregate GetPercentilesAggregate(JsonReader reader, JsonSerializer ser reader.Read(); while (reader.TokenType != JsonToken.EndObject) { - var propertyName = (string) reader.Value; + var propertyName = (string)reader.Value; if (propertyName.Contains(Parser.AsStringSuffix)) { reader.Read(); @@ -292,7 +252,7 @@ private IAggregate GetPercentilesAggregate(JsonReader reader, JsonSerializer ser } if (reader.TokenType != JsonToken.EndObject) { - var percentileValue = (string) reader.Value; + var percentileValue = (string)reader.Value; var percentile = double.Parse(percentileValue, CultureInfo.InvariantCulture); reader.Read(); var value = reader.Value as double?; @@ -320,14 +280,13 @@ private IAggregate GetSingleBucketAggregate(JsonReader reader, JsonSerializer se reader.Read(); bgCount = (reader.Value as long?).GetValueOrDefault(0); reader.Read(); - } if ((string)reader.Value == Parser.Fields) return GetMatrixStatsAggregate(reader, serializer, docCount); - if (reader.TokenType == JsonToken.PropertyName && (string) reader.Value == Parser.Buckets) + if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == Parser.Buckets) { - var b = this.GetMultiBucketAggregate(reader, serializer) as BucketAggregate; + var b = GetMultiBucketAggregate(reader, serializer) as BucketAggregate; return new BucketAggregate { BgCount = bgCount, @@ -336,7 +295,7 @@ private IAggregate GetSingleBucketAggregate(JsonReader reader, JsonSerializer se }; } - var nestedAggregations = this.GetSubAggregates(reader, serializer); + var nestedAggregations = GetSubAggregates(reader, serializer); var bucket = new SingleBucketAggregate(nestedAggregations) { DocCount = docCount @@ -350,10 +309,8 @@ private IAggregate GetStatsAggregate(JsonReader reader, JsonSerializer serialize reader.Read(); var count = (reader.Value as long?).GetValueOrDefault(0); reader.Read(); - if (reader.TokenType == JsonToken.EndObject) - { - return new GeoCentroidAggregate {Count = count}; - } + if (reader.TokenType == JsonToken.EndObject) return new GeoCentroidAggregate { Count = count }; + reader.Read(); var min = reader.Value as double?; reader.Read(); @@ -380,7 +337,7 @@ private IAggregate GetStatsAggregate(JsonReader reader, JsonSerializer serialize if (reader.TokenType == JsonToken.EndObject) return statsMetric; - var propertyName = (string) reader.Value; + var propertyName = (string)reader.Value; while (reader.TokenType != JsonToken.EndObject && propertyName.Contains(Parser.AsStringSuffix)) { reader.Read(); @@ -405,13 +362,13 @@ private IAggregate GetExtendedStatsAggregate(StatsAggregate statsMetric, JsonRea }; reader.Read(); - extendedStatsMetric.SumOfSquares = (reader.Value as double?); + extendedStatsMetric.SumOfSquares = reader.Value as double?; reader.Read(); reader.Read(); - extendedStatsMetric.Variance = (reader.Value as double?); + extendedStatsMetric.Variance = reader.Value as double?; reader.Read(); reader.Read(); - extendedStatsMetric.StdDeviation = (reader.Value as double?); + extendedStatsMetric.StdDeviation = reader.Value as double?; reader.Read(); string propertyName; @@ -422,7 +379,7 @@ private IAggregate GetExtendedStatsAggregate(StatsAggregate statsMetric, JsonRea reader.Read(); reader.Read(); - propertyName = (string) reader.Value; + propertyName = (string)reader.Value; if (propertyName == Parser.Upper) { reader.Read(); @@ -430,7 +387,7 @@ private IAggregate GetExtendedStatsAggregate(StatsAggregate statsMetric, JsonRea } reader.Read(); - propertyName = (string) reader.Value; + propertyName = (string)reader.Value; if (propertyName == Parser.Lower) { reader.Read(); @@ -441,7 +398,7 @@ private IAggregate GetExtendedStatsAggregate(StatsAggregate statsMetric, JsonRea reader.Read(); } - propertyName = (string) reader.Value; + propertyName = (string)reader.Value; while (reader.TokenType != JsonToken.EndObject && propertyName.Contains(Parser.AsStringSuffix)) { // std_deviation_bounds is an object, so we need to skip its properties @@ -467,9 +424,9 @@ private Dictionary GetSubAggregates(JsonReader reader, JsonS var currentDepth = reader.Depth; do { - var fieldName = (string) reader.Value; + var fieldName = (string)reader.Value; reader.Read(); - var agg = this.ReadAggregate(reader, serializer); + var agg = ReadAggregate(reader, serializer); nestedAggs.Add(fieldName, agg); reader.Read(); if (reader.Depth == currentDepth && reader.TokenType == JsonToken.EndObject || reader.Depth < currentDepth) @@ -481,14 +438,14 @@ private Dictionary GetSubAggregates(JsonReader reader, JsonS private IAggregate GetMultiBucketAggregate(JsonReader reader, JsonSerializer serializer) { var bucket = new BucketAggregate(); - var propertyName = (string) reader.Value; + var propertyName = (string)reader.Value; if (propertyName == Parser.DocCountErrorUpperBound) { reader.Read(); bucket.DocCountErrorUpperBound = reader.Value as long?; reader.Read(); } - propertyName = (string) reader.Value; + propertyName = (string)reader.Value; if (propertyName == Parser.SumOtherDocCount) { reader.Read(); @@ -506,7 +463,7 @@ private IAggregate GetMultiBucketAggregate(JsonReader reader, JsonSerializer ser { var name = reader.Value.ToString(); reader.Read(); - var innerAgg = this.ReadAggregate(reader, serializer); + var innerAgg = ReadAggregate(reader, serializer); aggs.Add(name, innerAgg); reader.Read(); } @@ -517,6 +474,7 @@ private IAggregate GetMultiBucketAggregate(JsonReader reader, JsonSerializer ser if (reader.TokenType != JsonToken.StartArray) return null; + reader.Read(); //move from start array to start object if (reader.TokenType == JsonToken.EndArray) { @@ -526,7 +484,7 @@ private IAggregate GetMultiBucketAggregate(JsonReader reader, JsonSerializer ser } do { - var item = this.ReadBucket(reader, serializer); + var item = ReadBucket(reader, serializer); items.Add(item); reader.Read(); } while (reader.TokenType != JsonToken.EndArray); @@ -554,7 +512,7 @@ private IAggregate GetValueAggregate(JsonReader reader, JsonSerializer serialize { if (reader.TokenType == JsonToken.PropertyName) { - var propertyName = (string) reader.Value; + var propertyName = (string)reader.Value; if (propertyName == Parser.ValueAsString) { @@ -564,7 +522,7 @@ private IAggregate GetValueAggregate(JsonReader reader, JsonSerializer serialize if (reader.TokenType == JsonToken.PropertyName) { - propertyName = (string) reader.Value; + propertyName = (string)reader.Value; if (propertyName == Parser.Keys) { var keyedValueMetric = new KeyedValueAggregate @@ -618,13 +576,13 @@ public IBucket GetRangeBucket(JsonReader reader, JsonSerializer serializer, stri case Parser.From: reader.Read(); if (reader.ValueType == typeof(double)) - fromDouble = (double) reader.Value; + fromDouble = (double)reader.Value; reader.Read(); break; case Parser.To: reader.Read(); if (reader.ValueType == typeof(double)) - toDouble = (double) reader.Value; + toDouble = (double)reader.Value; reader.Read(); break; case Parser.Key: @@ -650,7 +608,7 @@ public IBucket GetRangeBucket(JsonReader reader, JsonSerializer serializer, stri } } - var nestedAggregations = this.GetSubAggregates(reader, serializer); + var nestedAggregations = GetSubAggregates(reader, serializer); var bucket = new RangeBucket(nestedAggregations) { @@ -676,7 +634,7 @@ private IBucket GetDateHistogramBucket(JsonReader reader, JsonSerializer seriali var docCount = (reader.Value as long?).GetValueOrDefault(0); reader.Read(); - var nestedAggregations = this.GetSubAggregates(reader, serializer); + var nestedAggregations = GetSubAggregates(reader, serializer); var dateHistogram = new DateHistogramBucket(nestedAggregations) { @@ -697,7 +655,7 @@ private IBucket GetKeyedBucket(JsonReader reader, JsonSerializer serializer) var key = reader.Value; reader.Read(); - var propertyName = (string) reader.Value; + var propertyName = (string)reader.Value; if (propertyName == Parser.From || propertyName == Parser.To) return GetRangeBucket(reader, serializer, key as string); @@ -713,7 +671,7 @@ private IBucket GetKeyedBucket(JsonReader reader, JsonSerializer serializer) var docCount = reader.Value as long?; reader.Read(); - var nextProperty = (string) reader.Value; + var nextProperty = (string)reader.Value; if (nextProperty == Parser.Score) return GetSignificantTermsBucket(reader, serializer, key, keyAsString, docCount); @@ -724,7 +682,7 @@ private IBucket GetKeyedBucket(JsonReader reader, JsonSerializer serializer) docCountErrorUpperBound = reader.Value as long?; reader.Read(); } - var nestedAggregates = this.GetSubAggregates(reader, serializer); + var nestedAggregates = GetSubAggregates(reader, serializer); var bucket = new KeyedBucket(nestedAggregates) { Key = key, @@ -747,7 +705,7 @@ private IBucket GetCompositeBucket(JsonReader reader, JsonSerializer serializer) reader.Read(); } - var nestedAggregates = this.GetSubAggregates(reader, serializer); + var nestedAggregates = GetSubAggregates(reader, serializer); return new CompositeBucket(nestedAggregates, key) { DocCount = docCount }; } @@ -759,7 +717,7 @@ private IBucket GetSignificantTermsBucket(JsonReader reader, JsonSerializer seri reader.Read(); var bgCount = reader.Value as long?; reader.Read(); - var nestedAggregations = this.GetSubAggregates(reader, serializer); + var nestedAggregations = GetSubAggregates(reader, serializer); var significantTermItem = new SignificantTermsBucket(nestedAggregations) { Key = key as string, @@ -775,12 +733,56 @@ private IBucket GetFiltersBucket(JsonReader reader, JsonSerializer serializer) reader.Read(); var docCount = (reader.Value as long?).GetValueOrDefault(0); reader.Read(); - var nestedAggregations = this.GetSubAggregates(reader, serializer); + var nestedAggregations = GetSubAggregates(reader, serializer); var filtersBucketItem = new FiltersBucketItem(nestedAggregations) { DocCount = docCount }; return filtersBucketItem; } + + private static class Parser + { + public const string AfterKey = "after_key"; + + public const string AsStringSuffix = "_as_string"; + public const string BgCount = "bg_count"; + public const string BottomRight = "bottom_right"; + public const string Bounds = "bounds"; + public const string Buckets = "buckets"; + public const string Count = "count"; + public const string DocCount = "doc_count"; + public const string DocCountErrorUpperBound = "doc_count_error_upper_bound"; + public const string Fields = "fields"; + public const string From = "from"; + + public const string FromAsString = "from_as_string"; + public const string Hits = "hits"; + + public const string Key = "key"; + public const string KeyAsString = "key_as_string"; + public const string Keys = "keys"; + public const string Location = "location"; + public const string Lower = "lower"; + public const string MaxScore = "max_score"; + public const string Meta = "meta"; + + public const string Score = "score"; + public const string StdDeviationBoundsAsString = "std_deviation_bounds_as_string"; + + public const string SumOtherDocCount = "sum_other_doc_count"; + public const string To = "to"; + public const string ToAsString = "to_as_string"; + + public const string TopLeft = "top_left"; + + public const string Total = "total"; + + public const string Upper = "upper"; + public const string Value = "value"; + + public const string ValueAsString = "value_as_string"; + public const string Values = "values"; + } } } diff --git a/src/Nest/Aggregations/Aggregation.cs b/src/Nest/Aggregations/Aggregation.cs index a718e82731d..afa33ab84ac 100644 --- a/src/Nest/Aggregations/Aggregation.cs +++ b/src/Nest/Aggregations/Aggregation.cs @@ -1,6 +1,6 @@ -using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; +using Newtonsoft.Json; namespace Nest { @@ -10,33 +10,30 @@ namespace Nest [JsonObject(MemberSerialization = MemberSerialization.OptIn)] public interface IAggregation { - /// - /// name of the aggregation - /// - string Name { get; set; } - /// /// metadata to associate with the individual aggregation at request time that /// will be returned in place at response time /// IDictionary Meta { get; set; } + + /// + /// name of the aggregation + /// + string Name { get; set; } } /// public abstract class AggregationBase : IAggregation { - /// - string IAggregation.Name { get; set; } + internal AggregationBase() { } + + protected AggregationBase(string name) => ((IAggregation)this).Name = name; /// public IDictionary Meta { get; set; } - internal AggregationBase() { } - - protected AggregationBase(string name) - { - ((IAggregation)this).Name = name; - } + /// + string IAggregation.Name { get; set; } internal abstract void WrapInContainer(AggregationContainer container); @@ -55,16 +52,16 @@ protected AggregationBase(string name) /// internal class AggregationCombinator : AggregationBase, IAggregation { - internal List Aggregations { get; } = new List(); - - internal override void WrapInContainer(AggregationContainer container) { } - public AggregationCombinator(string name, AggregationBase left, AggregationBase right) : base(name) { - this.AddAggregation(left); - this.AddAggregation(right); + AddAggregation(left); + AddAggregation(right); } + internal List Aggregations { get; } = new List(); + + internal override void WrapInContainer(AggregationContainer container) { } + private void AddAggregation(AggregationBase agg) { switch (agg) @@ -72,10 +69,10 @@ private void AddAggregation(AggregationBase agg) case null: return; case AggregationCombinator combinator when combinator.Aggregations.Any(): - this.Aggregations.AddRange(combinator.Aggregations); + Aggregations.AddRange(combinator.Aggregations); break; default: - this.Aggregations.Add(agg); + Aggregations.Add(agg); break; } } diff --git a/src/Nest/Aggregations/AggregationContainer.cs b/src/Nest/Aggregations/AggregationContainer.cs index beddf797152..fab58e88c56 100644 --- a/src/Nest/Aggregations/AggregationContainer.cs +++ b/src/Nest/Aggregations/AggregationContainer.cs @@ -14,11 +14,12 @@ namespace Nest [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public class AggregationDictionary : IsADictionaryBase { - public AggregationDictionary() {} + public AggregationDictionary() { } + public AggregationDictionary(IDictionary container) : base(container) { } + public AggregationDictionary(Dictionary container) - : base(container.ToDictionary(kv => kv.Key, kv => (IAggregationContainer)kv.Value)) - { } + : base(container.ToDictionary(kv => kv.Key, kv => (IAggregationContainer)kv.Value)) { } public static implicit operator AggregationDictionary(Dictionary container) => new AggregationDictionary(container); @@ -37,6 +38,7 @@ public static implicit operator AggregationDictionary(AggregationBase aggregator b = agg; if (b.Name.IsNullOrEmpty()) throw new ArgumentException($"{aggregator.GetType().Name} .Name is not set!"); + dict.Add(b.Name, agg); } return dict; @@ -45,16 +47,18 @@ public static implicit operator AggregationDictionary(AggregationBase aggregator b = aggregator; if (b.Name.IsNullOrEmpty()) throw new ArgumentException($"{aggregator.GetType().Name} .Name is not set!"); + return new AggregationDictionary { { b.Name, aggregator } }; } - public void Add(string key, AggregationContainer value) => this.BackingDictionary.Add(ValidateKey(key), value); + public void Add(string key, AggregationContainer value) => BackingDictionary.Add(ValidateKey(key), value); protected override string ValidateKey(string key) { if (AggregateJsonConverter.AllReservedAggregationNames.Contains(key)) throw new ArgumentException( string.Format(AggregateJsonConverter.UsingReservedAggNameFormat, key), nameof(key)); + return key; } } @@ -64,78 +68,135 @@ protected override string ValidateKey(string key) [JsonConverter(typeof(ReadAsTypeJsonConverter))] public interface IAggregationContainer { - [JsonProperty("meta")] - [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] - IDictionary Meta { get; set; } + [JsonProperty("adjacency_matrix")] + IAdjacencyMatrixAggregation AdjacencyMatrix { get; set; } + + [JsonProperty("aggs")] + AggregationDictionary Aggregations { get; set; } [JsonProperty("avg")] IAverageAggregation Average { get; set; } + [JsonProperty("avg_bucket")] + IAverageBucketAggregation AverageBucket { get; set; } + + [JsonProperty("bucket_script")] + IBucketScriptAggregation BucketScript { get; set; } + + [JsonProperty("bucket_selector")] + IBucketSelectorAggregation BucketSelector { get; set; } + + [JsonProperty("bucket_sort")] + IBucketSortAggregation BucketSort { get; set; } + + [JsonProperty("cardinality")] + ICardinalityAggregation Cardinality { get; set; } + + [JsonProperty("children")] + IChildrenAggregation Children { get; set; } + + [JsonProperty("composite")] + ICompositeAggregation Composite { get; set; } + + [JsonProperty("cumulative_sum")] + ICumulativeSumAggregation CumulativeSum { get; set; } + [JsonProperty("date_histogram")] IDateHistogramAggregation DateHistogram { get; set; } - [JsonProperty("percentiles")] - IPercentilesAggregation Percentiles { get; set; } - [JsonProperty("date_range")] IDateRangeAggregation DateRange { get; set; } + [JsonProperty("derivative")] + IDerivativeAggregation Derivative { get; set; } + [JsonProperty("extended_stats")] IExtendedStatsAggregation ExtendedStats { get; set; } + [JsonProperty("extended_stats_bucket")] + IExtendedStatsBucketAggregation ExtendedStatsBucket { get; set; } + [JsonProperty("filter")] IFilterAggregation Filter { get; set; } [JsonProperty("filters")] IFiltersAggregation Filters { get; set; } + [JsonProperty("geo_bounds")] + IGeoBoundsAggregation GeoBounds { get; set; } + + [JsonProperty("geo_centroid")] + IGeoCentroidAggregation GeoCentroid { get; set; } + [JsonProperty("geo_distance")] IGeoDistanceAggregation GeoDistance { get; set; } [JsonProperty("geohash_grid")] IGeoHashGridAggregation GeoHash { get; set; } - [JsonProperty("geo_bounds")] - IGeoBoundsAggregation GeoBounds { get; set; } + [JsonProperty("global")] + IGlobalAggregation Global { get; set; } [JsonProperty("histogram")] IHistogramAggregation Histogram { get; set; } - [JsonProperty("global")] - IGlobalAggregation Global { get; set; } - [JsonProperty("ip_range")] IIpRangeAggregation IpRange { get; set; } + [JsonProperty("matrix_stats")] + IMatrixStatsAggregation MatrixStats { get; set; } + [JsonProperty("max")] IMaxAggregation Max { get; set; } + [JsonProperty("max_bucket")] + IMaxBucketAggregation MaxBucket { get; set; } + + [JsonProperty("meta")] + [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] + IDictionary Meta { get; set; } + [JsonProperty("min")] IMinAggregation Min { get; set; } - [JsonProperty("cardinality")] - ICardinalityAggregation Cardinality { get; set; } + [JsonProperty("min_bucket")] + IMinBucketAggregation MinBucket { get; set; } [JsonProperty("missing")] IMissingAggregation Missing { get; set; } + [JsonProperty("moving_avg")] + IMovingAverageAggregation MovingAverage { get; set; } + + [JsonProperty("moving_fn")] + IMovingFunctionAggregation MovingFunction { get; set; } + [JsonProperty("nested")] INestedAggregation Nested { get; set; } - [JsonProperty("reverse_nested")] - IReverseNestedAggregation ReverseNested { get; set; } + [JsonProperty("percentile_ranks")] + IPercentileRanksAggregation PercentileRanks { get; set; } + + [JsonProperty("percentiles")] + IPercentilesAggregation Percentiles { get; set; } + + [JsonProperty("percentiles_bucket")] + IPercentilesBucketAggregation PercentilesBucket { get; set; } [JsonProperty("range")] IRangeAggregation Range { get; set; } - [JsonProperty("stats")] - IStatsAggregation Stats { get; set; } + [JsonProperty("reverse_nested")] + IReverseNestedAggregation ReverseNested { get; set; } - [JsonProperty("sum")] - ISumAggregation Sum { get; set; } + [JsonProperty("sampler")] + ISamplerAggregation Sampler { get; set; } - [JsonProperty("terms")] - ITermsAggregation Terms { get; set; } + [JsonProperty("scripted_metric")] + IScriptedMetricAggregation ScriptedMetric { get; set; } + + [JsonProperty("serial_diff")] + ISerialDifferencingAggregation SerialDifferencing { get; set; } [JsonProperty("significant_terms")] ISignificantTermsAggregation SignificantTerms { get; set; } @@ -143,193 +204,142 @@ public interface IAggregationContainer [JsonProperty("significant_text")] ISignificantTextAggregation SignificantText { get; set; } - [JsonProperty("value_count")] - IValueCountAggregation ValueCount { get; set; } - - [JsonProperty("percentile_ranks")] - IPercentileRanksAggregation PercentileRanks { get; set; } - - [JsonProperty("top_hits")] - ITopHitsAggregation TopHits { get; set; } - - [JsonProperty("children")] - IChildrenAggregation Children { get; set; } - - [JsonProperty("scripted_metric")] - IScriptedMetricAggregation ScriptedMetric { get; set; } - - [JsonProperty("avg_bucket")] - IAverageBucketAggregation AverageBucket { get; set; } - - [JsonProperty("derivative")] - IDerivativeAggregation Derivative { get; set; } - - [JsonProperty("max_bucket")] - IMaxBucketAggregation MaxBucket { get; set; } - - [JsonProperty("min_bucket")] - IMinBucketAggregation MinBucket { get; set; } - - [JsonProperty("sum_bucket")] - ISumBucketAggregation SumBucket { get; set; } + [JsonProperty("stats")] + IStatsAggregation Stats { get; set; } [JsonProperty("stats_bucket")] IStatsBucketAggregation StatsBucket { get; set; } - [JsonProperty("extended_stats_bucket")] - IExtendedStatsBucketAggregation ExtendedStatsBucket { get; set; } - - [JsonProperty("percentiles_bucket")] - IPercentilesBucketAggregation PercentilesBucket { get; set; } - - [JsonProperty("moving_avg")] - IMovingAverageAggregation MovingAverage { get; set; } - - [JsonProperty("moving_fn")] - IMovingFunctionAggregation MovingFunction { get; set; } - - [JsonProperty("cumulative_sum")] - ICumulativeSumAggregation CumulativeSum { get; set; } - - [JsonProperty("serial_diff")] - ISerialDifferencingAggregation SerialDifferencing { get; set; } - - [JsonProperty("bucket_script")] - IBucketScriptAggregation BucketScript { get; set; } - - [JsonProperty("bucket_selector")] - IBucketSelectorAggregation BucketSelector { get; set; } - - [JsonProperty("bucket_sort")] - IBucketSortAggregation BucketSort { get; set; } - - [JsonProperty("sampler")] - ISamplerAggregation Sampler { get; set; } + [JsonProperty("sum")] + ISumAggregation Sum { get; set; } - [JsonProperty("geo_centroid")] - IGeoCentroidAggregation GeoCentroid { get; set; } + [JsonProperty("sum_bucket")] + ISumBucketAggregation SumBucket { get; set; } - [JsonProperty("matrix_stats")] - IMatrixStatsAggregation MatrixStats { get; set; } + [JsonProperty("terms")] + ITermsAggregation Terms { get; set; } - [JsonProperty("adjacency_matrix")] - IAdjacencyMatrixAggregation AdjacencyMatrix { get; set; } + [JsonProperty("top_hits")] + ITopHitsAggregation TopHits { get; set; } - [JsonProperty("composite")] - ICompositeAggregation Composite { get; set; } + [JsonProperty("value_count")] + IValueCountAggregation ValueCount { get; set; } [JsonProperty("weighted_avg")] IWeightedAverageAggregation WeightedAverage { get; set; } - [JsonProperty("aggs")] - AggregationDictionary Aggregations { get; set; } - void Accept(IAggregationVisitor visitor); } public class AggregationContainer : IAggregationContainer { - public IDictionary Meta { get; set; } + public IAdjacencyMatrixAggregation AdjacencyMatrix { get; set; } + + public AggregationDictionary Aggregations { get; set; } public IAverageAggregation Average { get; set; } - public IValueCountAggregation ValueCount { get; set; } - public IMaxAggregation Max { get; set; } - public IMinAggregation Min { get; set; } - public IStatsAggregation Stats { get; set; } - public ISumAggregation Sum { get; set; } - public IExtendedStatsAggregation ExtendedStats { get; set; } - public IDateHistogramAggregation DateHistogram { get; set; } - public IPercentilesAggregation Percentiles { get; set; } + public IAverageBucketAggregation AverageBucket { get; set; } - public IDateRangeAggregation DateRange { get; set; } + public IBucketScriptAggregation BucketScript { get; set; } - public IFilterAggregation Filter { get; set; } + public IBucketSelectorAggregation BucketSelector { get; set; } - public IFiltersAggregation Filters { get; set; } + public IBucketSortAggregation BucketSort { get; set; } - public IGeoDistanceAggregation GeoDistance { get; set; } + public ICardinalityAggregation Cardinality { get; set; } - public IGeoHashGridAggregation GeoHash { get; set; } + public IChildrenAggregation Children { get; set; } - public IGeoBoundsAggregation GeoBounds { get; set; } + public ICompositeAggregation Composite { get; set; } - public IHistogramAggregation Histogram { get; set; } + public ICumulativeSumAggregation CumulativeSum { get; set; } + public IDateHistogramAggregation DateHistogram { get; set; } - public IGlobalAggregation Global { get; set; } + public IDateRangeAggregation DateRange { get; set; } - public IIpRangeAggregation IpRange { get; set; } + public IDerivativeAggregation Derivative { get; set; } + public IExtendedStatsAggregation ExtendedStats { get; set; } - public ICardinalityAggregation Cardinality { get; set; } + public IExtendedStatsBucketAggregation ExtendedStatsBucket { get; set; } - public IMissingAggregation Missing { get; set; } + public IFilterAggregation Filter { get; set; } - public INestedAggregation Nested { get; set; } + public IFiltersAggregation Filters { get; set; } - public IReverseNestedAggregation ReverseNested { get; set; } + public IGeoBoundsAggregation GeoBounds { get; set; } - public IRangeAggregation Range { get; set; } + public IGeoCentroidAggregation GeoCentroid { get; set; } - public ITermsAggregation Terms { get; set; } + public IGeoDistanceAggregation GeoDistance { get; set; } - public ISignificantTermsAggregation SignificantTerms { get; set; } + public IGeoHashGridAggregation GeoHash { get; set; } - public ISignificantTextAggregation SignificantText { get; set; } + public IGlobalAggregation Global { get; set; } - public IPercentileRanksAggregation PercentileRanks { get; set; } + public IHistogramAggregation Histogram { get; set; } - public ITopHitsAggregation TopHits { get; set; } + public IIpRangeAggregation IpRange { get; set; } - public IChildrenAggregation Children { get; set; } + public IMatrixStatsAggregation MatrixStats { get; set; } + public IMaxAggregation Max { get; set; } - public IScriptedMetricAggregation ScriptedMetric { get; set; } + public IMaxBucketAggregation MaxBucket { get; set; } + public IDictionary Meta { get; set; } + public IMinAggregation Min { get; set; } - public IAverageBucketAggregation AverageBucket { get; set; } + public IMinBucketAggregation MinBucket { get; set; } - public IDerivativeAggregation Derivative { get; set; } + public IMissingAggregation Missing { get; set; } - public IMaxBucketAggregation MaxBucket { get; set; } + public IMovingAverageAggregation MovingAverage { get; set; } - public IMinBucketAggregation MinBucket { get; set; } + public IMovingFunctionAggregation MovingFunction { get; set; } - public ISumBucketAggregation SumBucket { get; set; } + public INestedAggregation Nested { get; set; } - public IStatsBucketAggregation StatsBucket { get; set; } + public IPercentileRanksAggregation PercentileRanks { get; set; } - public IExtendedStatsBucketAggregation ExtendedStatsBucket { get; set; } + public IPercentilesAggregation Percentiles { get; set; } public IPercentilesBucketAggregation PercentilesBucket { get; set; } - public IMovingAverageAggregation MovingAverage { get; set; } - - public IMovingFunctionAggregation MovingFunction { get; set; } + public IRangeAggregation Range { get; set; } - public ICumulativeSumAggregation CumulativeSum { get; set; } + public IReverseNestedAggregation ReverseNested { get; set; } - public ISerialDifferencingAggregation SerialDifferencing { get; set; } + public ISamplerAggregation Sampler { get; set; } - public IBucketScriptAggregation BucketScript { get; set; } + public IScriptedMetricAggregation ScriptedMetric { get; set; } - public IBucketSelectorAggregation BucketSelector { get; set; } + public ISerialDifferencingAggregation SerialDifferencing { get; set; } - public IBucketSortAggregation BucketSort { get; set; } + public ISignificantTermsAggregation SignificantTerms { get; set; } - public ISamplerAggregation Sampler { get; set; } + public ISignificantTextAggregation SignificantText { get; set; } + public IStatsAggregation Stats { get; set; } - public IGeoCentroidAggregation GeoCentroid { get; set; } + public IStatsBucketAggregation StatsBucket { get; set; } + public ISumAggregation Sum { get; set; } - public IMatrixStatsAggregation MatrixStats { get; set; } + public ISumBucketAggregation SumBucket { get; set; } - public IAdjacencyMatrixAggregation AdjacencyMatrix { get; set; } + public ITermsAggregation Terms { get; set; } - public ICompositeAggregation Composite { get; set; } + public ITopHitsAggregation TopHits { get; set; } + public IValueCountAggregation ValueCount { get; set; } public IWeightedAverageAggregation WeightedAverage { get; set; } - public AggregationDictionary Aggregations { get; set; } + public void Accept(IAggregationVisitor visitor) + { + if (visitor.Scope == AggregationVisitorScope.Unknown) visitor.Scope = AggregationVisitorScope.Aggregation; + new AggregationWalker().Walk(this, visitor); + } public static implicit operator AggregationContainer(AggregationBase aggregator) { if (aggregator == null) return null; + var container = new AggregationContainer(); aggregator.WrapInContainer(container); var bucket = aggregator as BucketAggregationBase; @@ -340,332 +350,382 @@ public static implicit operator AggregationContainer(AggregationBase aggregator) { var dict = new AggregationDictionary(); foreach (var agg in combinator.Aggregations) - dict.Add(((IAggregation) agg).Name, agg); + dict.Add(((IAggregation)agg).Name, agg); container.Aggregations = dict; } container.Meta = aggregator.Meta; return container; } - - public void Accept(IAggregationVisitor visitor) - { - if (visitor.Scope == AggregationVisitorScope.Unknown) visitor.Scope = AggregationVisitorScope.Aggregation; - new AggregationWalker().Walk(this, visitor); - } } public class AggregationContainerDescriptor : DescriptorBase, IAggregationContainer>, IAggregationContainer where T : class { - IDictionary IAggregationContainer.Meta { get; set; } + IAdjacencyMatrixAggregation IAggregationContainer.AdjacencyMatrix { get; set; } AggregationDictionary IAggregationContainer.Aggregations { get; set; } IAverageAggregation IAggregationContainer.Average { get; set; } - IDateHistogramAggregation IAggregationContainer.DateHistogram { get; set; } - - IPercentilesAggregation IAggregationContainer.Percentiles { get; set; } - - IDateRangeAggregation IAggregationContainer.DateRange { get; set; } - - IExtendedStatsAggregation IAggregationContainer.ExtendedStats { get; set; } + IAverageBucketAggregation IAggregationContainer.AverageBucket { get; set; } - IFilterAggregation IAggregationContainer.Filter { get; set; } + IBucketScriptAggregation IAggregationContainer.BucketScript { get; set; } - IFiltersAggregation IAggregationContainer.Filters { get; set; } + IBucketSelectorAggregation IAggregationContainer.BucketSelector { get; set; } - IGeoDistanceAggregation IAggregationContainer.GeoDistance { get; set; } + IBucketSortAggregation IAggregationContainer.BucketSort { get; set; } - IGeoHashGridAggregation IAggregationContainer.GeoHash { get; set; } + ICardinalityAggregation IAggregationContainer.Cardinality { get; set; } - IGeoBoundsAggregation IAggregationContainer.GeoBounds { get; set; } + IChildrenAggregation IAggregationContainer.Children { get; set; } - IHistogramAggregation IAggregationContainer.Histogram { get; set; } + ICompositeAggregation IAggregationContainer.Composite { get; set; } - IGlobalAggregation IAggregationContainer.Global { get; set; } + ICumulativeSumAggregation IAggregationContainer.CumulativeSum { get; set; } - IIpRangeAggregation IAggregationContainer.IpRange { get; set; } + IDateHistogramAggregation IAggregationContainer.DateHistogram { get; set; } - IMaxAggregation IAggregationContainer.Max { get; set; } + IDateRangeAggregation IAggregationContainer.DateRange { get; set; } - IMinAggregation IAggregationContainer.Min { get; set; } + IDerivativeAggregation IAggregationContainer.Derivative { get; set; } - ICardinalityAggregation IAggregationContainer.Cardinality { get; set; } + IExtendedStatsAggregation IAggregationContainer.ExtendedStats { get; set; } - IMissingAggregation IAggregationContainer.Missing { get; set; } + IExtendedStatsBucketAggregation IAggregationContainer.ExtendedStatsBucket { get; set; } - INestedAggregation IAggregationContainer.Nested { get; set; } + IFilterAggregation IAggregationContainer.Filter { get; set; } - IReverseNestedAggregation IAggregationContainer.ReverseNested { get; set; } + IFiltersAggregation IAggregationContainer.Filters { get; set; } - IRangeAggregation IAggregationContainer.Range { get; set; } + IGeoBoundsAggregation IAggregationContainer.GeoBounds { get; set; } - IStatsAggregation IAggregationContainer.Stats { get; set; } + IGeoCentroidAggregation IAggregationContainer.GeoCentroid { get; set; } - ISumAggregation IAggregationContainer.Sum { get; set; } + IGeoDistanceAggregation IAggregationContainer.GeoDistance { get; set; } - IValueCountAggregation IAggregationContainer.ValueCount { get; set; } + IGeoHashGridAggregation IAggregationContainer.GeoHash { get; set; } - ISignificantTermsAggregation IAggregationContainer.SignificantTerms { get; set; } + IGlobalAggregation IAggregationContainer.Global { get; set; } - ISignificantTextAggregation IAggregationContainer.SignificantText { get; set; } + IHistogramAggregation IAggregationContainer.Histogram { get; set; } - IPercentileRanksAggregation IAggregationContainer.PercentileRanks { get; set; } + IIpRangeAggregation IAggregationContainer.IpRange { get; set; } - ITermsAggregation IAggregationContainer.Terms { get; set; } + IMatrixStatsAggregation IAggregationContainer.MatrixStats { get; set; } - ITopHitsAggregation IAggregationContainer.TopHits { get; set; } + IMaxAggregation IAggregationContainer.Max { get; set; } - IChildrenAggregation IAggregationContainer.Children { get; set; } + IMaxBucketAggregation IAggregationContainer.MaxBucket { get; set; } + IDictionary IAggregationContainer.Meta { get; set; } - IScriptedMetricAggregation IAggregationContainer.ScriptedMetric { get; set; } + IMinAggregation IAggregationContainer.Min { get; set; } - IAverageBucketAggregation IAggregationContainer.AverageBucket { get; set; } + IMinBucketAggregation IAggregationContainer.MinBucket { get; set; } - IDerivativeAggregation IAggregationContainer.Derivative { get; set; } + IMissingAggregation IAggregationContainer.Missing { get; set; } - IMaxBucketAggregation IAggregationContainer.MaxBucket { get; set; } + IMovingAverageAggregation IAggregationContainer.MovingAverage { get; set; } - IMinBucketAggregation IAggregationContainer.MinBucket { get; set; } + IMovingFunctionAggregation IAggregationContainer.MovingFunction { get; set; } - ISumBucketAggregation IAggregationContainer.SumBucket { get; set; } + INestedAggregation IAggregationContainer.Nested { get; set; } - IStatsBucketAggregation IAggregationContainer.StatsBucket { get; set; } + IPercentileRanksAggregation IAggregationContainer.PercentileRanks { get; set; } - IExtendedStatsBucketAggregation IAggregationContainer.ExtendedStatsBucket { get; set; } + IPercentilesAggregation IAggregationContainer.Percentiles { get; set; } IPercentilesBucketAggregation IAggregationContainer.PercentilesBucket { get; set; } - IMovingAverageAggregation IAggregationContainer.MovingAverage { get; set; } + IRangeAggregation IAggregationContainer.Range { get; set; } - IMovingFunctionAggregation IAggregationContainer.MovingFunction { get; set; } + IReverseNestedAggregation IAggregationContainer.ReverseNested { get; set; } - ICumulativeSumAggregation IAggregationContainer.CumulativeSum { get; set; } + ISamplerAggregation IAggregationContainer.Sampler { get; set; } + + IScriptedMetricAggregation IAggregationContainer.ScriptedMetric { get; set; } ISerialDifferencingAggregation IAggregationContainer.SerialDifferencing { get; set; } - IBucketScriptAggregation IAggregationContainer.BucketScript { get; set; } + ISignificantTermsAggregation IAggregationContainer.SignificantTerms { get; set; } - IBucketSelectorAggregation IAggregationContainer.BucketSelector { get; set; } + ISignificantTextAggregation IAggregationContainer.SignificantText { get; set; } - IBucketSortAggregation IAggregationContainer.BucketSort { get; set; } + IStatsAggregation IAggregationContainer.Stats { get; set; } - ISamplerAggregation IAggregationContainer.Sampler { get; set; } + IStatsBucketAggregation IAggregationContainer.StatsBucket { get; set; } - IGeoCentroidAggregation IAggregationContainer.GeoCentroid { get; set; } + ISumAggregation IAggregationContainer.Sum { get; set; } - IMatrixStatsAggregation IAggregationContainer.MatrixStats { get; set; } + ISumBucketAggregation IAggregationContainer.SumBucket { get; set; } - IAdjacencyMatrixAggregation IAggregationContainer.AdjacencyMatrix { get; set; } + ITermsAggregation IAggregationContainer.Terms { get; set; } - ICompositeAggregation IAggregationContainer.Composite { get; set; } + ITopHitsAggregation IAggregationContainer.TopHits { get; set; } + + IValueCountAggregation IAggregationContainer.ValueCount { get; set; } IWeightedAverageAggregation IAggregationContainer.WeightedAverage { get; set; } + public void Accept(IAggregationVisitor visitor) + { + if (visitor.Scope == AggregationVisitorScope.Unknown) visitor.Scope = AggregationVisitorScope.Aggregation; + new AggregationWalker().Walk(this, visitor); + } + public AggregationContainerDescriptor Average(string name, - Func, IAverageAggregation> selector) => + Func, IAverageAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Average = d); public AggregationContainerDescriptor DateHistogram(string name, - Func, IDateHistogramAggregation> selector) => + Func, IDateHistogramAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.DateHistogram = d); public AggregationContainerDescriptor Percentiles(string name, - Func, IPercentilesAggregation> selector) => + Func, IPercentilesAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Percentiles = d); public AggregationContainerDescriptor PercentileRanks(string name, - Func, IPercentileRanksAggregation> selector) => + Func, IPercentileRanksAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.PercentileRanks = d); public AggregationContainerDescriptor DateRange(string name, - Func, IDateRangeAggregation> selector) => + Func, IDateRangeAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.DateRange = d); public AggregationContainerDescriptor ExtendedStats(string name, - Func, IExtendedStatsAggregation> selector) => + Func, IExtendedStatsAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.ExtendedStats = d); public AggregationContainerDescriptor Filter(string name, - Func, IFilterAggregation> selector) => + Func, IFilterAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Filter = d); public AggregationContainerDescriptor Filters(string name, - Func, IFiltersAggregation> selector) => + Func, IFiltersAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Filters = d); public AggregationContainerDescriptor GeoDistance(string name, - Func, IGeoDistanceAggregation> selector) => + Func, IGeoDistanceAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.GeoDistance = d); public AggregationContainerDescriptor GeoHash(string name, - Func, IGeoHashGridAggregation> selector) => + Func, IGeoHashGridAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.GeoHash = d); public AggregationContainerDescriptor GeoBounds(string name, - Func, IGeoBoundsAggregation> selector) => + Func, IGeoBoundsAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.GeoBounds = d); public AggregationContainerDescriptor Histogram(string name, - Func, IHistogramAggregation> selector) => + Func, IHistogramAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Histogram = d); public AggregationContainerDescriptor Global(string name, - Func, IGlobalAggregation> selector) => + Func, IGlobalAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Global = d); public AggregationContainerDescriptor IpRange(string name, - Func, IIpRangeAggregation> selector) => + Func, IIpRangeAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.IpRange = d); public AggregationContainerDescriptor Max(string name, - Func, IMaxAggregation> selector) => + Func, IMaxAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Max = d); public AggregationContainerDescriptor Min(string name, - Func, IMinAggregation> selector) => + Func, IMinAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Min = d); public AggregationContainerDescriptor Cardinality(string name, - Func, ICardinalityAggregation> selector) => + Func, ICardinalityAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Cardinality = d); public AggregationContainerDescriptor Missing(string name, - Func, IMissingAggregation> selector) => + Func, IMissingAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Missing = d); public AggregationContainerDescriptor Nested(string name, - Func, INestedAggregation> selector) => + Func, INestedAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Nested = d); public AggregationContainerDescriptor ReverseNested(string name, - Func, IReverseNestedAggregation> selector) => + Func, IReverseNestedAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.ReverseNested = d); public AggregationContainerDescriptor Range(string name, - Func, IRangeAggregation> selector) => + Func, IRangeAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Range = d); public AggregationContainerDescriptor Stats(string name, - Func, IStatsAggregation> selector) => + Func, IStatsAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Stats = d); public AggregationContainerDescriptor Sum(string name, - Func, ISumAggregation> selector) => + Func, ISumAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Sum = d); public AggregationContainerDescriptor Terms(string name, - Func, ITermsAggregation> selector) => + Func, ITermsAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Terms = d); public AggregationContainerDescriptor SignificantTerms(string name, - Func, ISignificantTermsAggregation> selector) => + Func, ISignificantTermsAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.SignificantTerms = d); public AggregationContainerDescriptor SignificantText(string name, - Func, ISignificantTextAggregation> selector) => + Func, ISignificantTextAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.SignificantText = d); public AggregationContainerDescriptor ValueCount(string name, - Func, IValueCountAggregation> selector) => + Func, IValueCountAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.ValueCount = d); public AggregationContainerDescriptor TopHits(string name, - Func, ITopHitsAggregation> selector) => + Func, ITopHitsAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.TopHits = d); public AggregationContainerDescriptor Children(string name, - Func, IChildrenAggregation> selector) where TChild : class => + Func, IChildrenAggregation> selector + ) where TChild : class => _SetInnerAggregation(name, selector, (a, d) => a.Children = d); public AggregationContainerDescriptor ScriptedMetric(string name, - Func, IScriptedMetricAggregation> selector) => + Func, IScriptedMetricAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.ScriptedMetric = d); public AggregationContainerDescriptor AverageBucket(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.AverageBucket = d); public AggregationContainerDescriptor Derivative(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Derivative = d); public AggregationContainerDescriptor MaxBucket(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.MaxBucket = d); public AggregationContainerDescriptor MinBucket(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.MinBucket = d); public AggregationContainerDescriptor SumBucket(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.SumBucket = d); public AggregationContainerDescriptor StatsBucket(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.StatsBucket = d); public AggregationContainerDescriptor ExtendedStatsBucket(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.ExtendedStatsBucket = d); public AggregationContainerDescriptor PercentilesBucket(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.PercentilesBucket = d); public AggregationContainerDescriptor MovingAverage(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.MovingAverage = d); public AggregationContainerDescriptor MovingFunction(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.MovingFunction = d); public AggregationContainerDescriptor CumulativeSum(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.CumulativeSum = d); public AggregationContainerDescriptor SerialDifferencing(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.SerialDifferencing = d); public AggregationContainerDescriptor BucketScript(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.BucketScript = d); public AggregationContainerDescriptor BucketSelector(string name, - Func selector) => + Func selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.BucketSelector = d); public AggregationContainerDescriptor BucketSort(string name, - Func, IBucketSortAggregation> selector) => + Func, IBucketSortAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.BucketSort = d); public AggregationContainerDescriptor Sampler(string name, - Func, ISamplerAggregation> selector) => + Func, ISamplerAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Sampler = d); public AggregationContainerDescriptor GeoCentroid(string name, - Func, IGeoCentroidAggregation> selector) => + Func, IGeoCentroidAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.GeoCentroid = d); public AggregationContainerDescriptor MatrixStats(string name, - Func, IMatrixStatsAggregation> selector) => + Func, IMatrixStatsAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.MatrixStats = d); public AggregationContainerDescriptor AdjacencyMatrix(string name, - Func, IAdjacencyMatrixAggregation> selector) => + Func, IAdjacencyMatrixAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.AdjacencyMatrix = d); public AggregationContainerDescriptor Composite(string name, - Func, ICompositeAggregation> selector) => + Func, ICompositeAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.Composite = d); public AggregationContainerDescriptor WeightedAverage(string name, - Func, IWeightedAverageAggregation> selector) => + Func, IWeightedAverageAggregation> selector + ) => _SetInnerAggregation(name, selector, (a, d) => a.WeightedAverage = d); /// @@ -703,12 +763,6 @@ Func selector return this; } - public void Accept(IAggregationVisitor visitor) - { - if (visitor.Scope == AggregationVisitorScope.Unknown) visitor.Scope = AggregationVisitorScope.Aggregation; - new AggregationWalker().Walk(this, visitor); - } - //always evaluate to false so that each side of && equation is evaluated public static bool operator false(AggregationContainerDescriptor a) => false; @@ -724,7 +778,7 @@ public void Accept(IAggregationVisitor visitor) var d = new AggregationContainerDescriptor(); var leftAggs = (IDictionary)((IAggregationContainer)left).Aggregations; var rightAggs = (IDictionary)((IAggregationContainer)right).Aggregations; - foreach(var kv in rightAggs) + foreach (var kv in rightAggs) { if (leftAggs.ContainsKey(kv.Key)) { @@ -737,6 +791,5 @@ public void Accept(IAggregationVisitor visitor) ((IAggregationContainer)d).Aggregations = ((IAggregationContainer)left).Aggregations; return d; } - } } diff --git a/src/Nest/Aggregations/AggregationJsonConverter.cs b/src/Nest/Aggregations/AggregationJsonConverter.cs index 7457eb38b5b..0efa771dbf2 100644 --- a/src/Nest/Aggregations/AggregationJsonConverter.cs +++ b/src/Nest/Aggregations/AggregationJsonConverter.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Nest +namespace Nest { internal class AggregationJsonConverter : ReadAsTypeJsonConverter - where TReadAs : class - { } + where TReadAs : class { } } diff --git a/src/Nest/Aggregations/Bucket/AdjacencyMatrix/AdjacencyMatrixAggregation.cs b/src/Nest/Aggregations/Bucket/AdjacencyMatrix/AdjacencyMatrixAggregation.cs index c65c15e8ae5..95bdb97ffba 100644 --- a/src/Nest/Aggregations/Bucket/AdjacencyMatrix/AdjacencyMatrixAggregation.cs +++ b/src/Nest/Aggregations/Bucket/AdjacencyMatrix/AdjacencyMatrixAggregation.cs @@ -24,13 +24,12 @@ public AdjacencyMatrixAggregation(string name) : base(name) { } public class AdjacencyMatrixAggregationDescriptor : BucketAggregationDescriptorBase, IAdjacencyMatrixAggregation, T> - , IAdjacencyMatrixAggregation + , IAdjacencyMatrixAggregation where T : class { INamedFiltersContainer IAdjacencyMatrixAggregation.Filters { get; set; } public AdjacencyMatrixAggregationDescriptor Filters(Func, IPromise> selector) => Assign(a => a.Filters = selector?.Invoke(new NamedFiltersContainerDescriptor())?.Value); - } } diff --git a/src/Nest/Aggregations/Bucket/Bucket.cs b/src/Nest/Aggregations/Bucket/Bucket.cs index a3f24607efd..0a327f7ba4f 100644 --- a/src/Nest/Aggregations/Bucket/Bucket.cs +++ b/src/Nest/Aggregations/Bucket/Bucket.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Nest { diff --git a/src/Nest/Aggregations/Bucket/BucketAggregate.cs b/src/Nest/Aggregations/Bucket/BucketAggregate.cs index 0d47b6568c7..a65dfb5af16 100644 --- a/src/Nest/Aggregations/Bucket/BucketAggregate.cs +++ b/src/Nest/Aggregations/Bucket/BucketAggregate.cs @@ -3,7 +3,7 @@ namespace Nest { - public abstract class BucketAggregateBase : AggregateDictionary , IAggregate + public abstract class BucketAggregateBase : AggregateDictionary, IAggregate { protected BucketAggregateBase(IReadOnlyDictionary aggregations) : base(aggregations) { } @@ -36,17 +36,17 @@ public SingleBucketAggregate(IReadOnlyDictionary aggregation public class MultiBucketAggregate : IAggregate where TBucket : IBucket { - /// - public IReadOnlyDictionary Meta { get; set; } - /// /// The buckets into which results are grouped /// public IReadOnlyCollection Buckets { get; set; } = EmptyReadOnly.Collection; + + /// + public IReadOnlyDictionary Meta { get; set; } } /// - /// Aggregation response of + /// Aggregation response of /// public class CompositeBucketAggregate : MultiBucketAggregate { @@ -54,7 +54,7 @@ public class CompositeBucketAggregate : MultiBucketAggregate /// The composite key of the last bucket returned /// in the response before any filtering by pipeline aggregations. /// If all buckets are filtered/removed by pipeline aggregations, - /// will contain the composite key of the last bucket before filtering. + /// will contain the composite key of the last bucket before filtering. /// /// Valid for Elasticsearch 6.3.0+ public CompositeKey AfterKey { get; set; } @@ -63,12 +63,12 @@ public class CompositeBucketAggregate : MultiBucketAggregate // Intermediate object used for deserialization public class BucketAggregate : IAggregate { - public IReadOnlyCollection Items { get; set; } = EmptyReadOnly.Collection; + public IReadOnlyDictionary AfterKey { get; set; } = EmptyReadOnly.Dictionary; + public long BgCount { get; set; } + public long DocCount { get; set; } public long? DocCountErrorUpperBound { get; set; } - public long? SumOtherDocCount { get; set; } + public IReadOnlyCollection Items { get; set; } = EmptyReadOnly.Collection; public IReadOnlyDictionary Meta { get; set; } = EmptyReadOnly.Dictionary; - public long DocCount { get; set; } - public long BgCount { get; set; } - public IReadOnlyDictionary AfterKey { get; set; } = EmptyReadOnly.Dictionary; + public long? SumOtherDocCount { get; set; } } } diff --git a/src/Nest/Aggregations/Bucket/BucketAggregation.cs b/src/Nest/Aggregations/Bucket/BucketAggregation.cs index c83a7011a06..f287d20259f 100644 --- a/src/Nest/Aggregations/Bucket/BucketAggregation.cs +++ b/src/Nest/Aggregations/Bucket/BucketAggregation.cs @@ -10,30 +10,29 @@ public interface IBucketAggregation : IAggregation public abstract class BucketAggregationBase : AggregationBase, IBucketAggregation { - public AggregationDictionary Aggregations { get; set; } - internal BucketAggregationBase() { } protected BucketAggregationBase(string name) : base(name) { } + + public AggregationDictionary Aggregations { get; set; } } public abstract class BucketAggregationDescriptorBase : IBucketAggregation, IDescriptor where TBucketAggregation : BucketAggregationDescriptorBase - , TBucketAggregationInterface, IBucketAggregation + , TBucketAggregationInterface, IBucketAggregation where T : class where TBucketAggregationInterface : class, IBucketAggregation { + protected TBucketAggregationInterface Self => (TBucketAggregation)this; AggregationDictionary IBucketAggregation.Aggregations { get; set; } - protected TBucketAggregation Assign(Action assigner) => - Fluent.Assign(((TBucketAggregation)this), assigner); - - protected TBucketAggregationInterface Self => (TBucketAggregation)this; + IDictionary IAggregation.Meta { get; set; } string IAggregation.Name { get; set; } - IDictionary IAggregation.Meta { get; set; } + protected TBucketAggregation Assign(Action assigner) => + Fluent.Assign((TBucketAggregation)this, assigner); public TBucketAggregation Aggregations(Func, IAggregationContainer> selector) => Assign(a => a.Aggregations = selector?.Invoke(new AggregationContainerDescriptor())?.Aggregations); @@ -44,5 +43,4 @@ public TBucketAggregation Aggregations(AggregationDictionary aggregations) => public TBucketAggregation Meta(Func, FluentDictionary> selector) => Assign(a => a.Meta = selector?.Invoke(new FluentDictionary())); } - } diff --git a/src/Nest/Aggregations/Bucket/Children/ChildrenAggregation.cs b/src/Nest/Aggregations/Bucket/Children/ChildrenAggregation.cs index a5bcdc8ec6b..03dbf5874fa 100644 --- a/src/Nest/Aggregations/Bucket/Children/ChildrenAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Children/ChildrenAggregation.cs @@ -14,14 +14,11 @@ public interface IChildrenAggregation : IBucketAggregation public class ChildrenAggregation : BucketAggregationBase, IChildrenAggregation { - public RelationName Type { get; set; } - internal ChildrenAggregation() { } - public ChildrenAggregation(string name, RelationName type) : base(name) - { - this.Type = type; - } + public ChildrenAggregation(string name, RelationName type) : base(name) => Type = type; + + public RelationName Type { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.Children = this; } diff --git a/src/Nest/Aggregations/Bucket/Composite/CompositeAggregation.cs b/src/Nest/Aggregations/Bucket/Composite/CompositeAggregation.cs index 5e9a8b6805e..d70ff267791 100644 --- a/src/Nest/Aggregations/Bucket/Composite/CompositeAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Composite/CompositeAggregation.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq.Expressions; using Newtonsoft.Json; namespace Nest @@ -13,10 +12,11 @@ namespace Nest public interface ICompositeAggregation : IBucketAggregation { /// - /// Controls the sources that should be used to build the composite buckets + /// Used to retrieve the composite buckets that are after the + /// last composite buckets returned in a previous round /// - [JsonProperty("sources")] - IEnumerable Sources { get; set; } + [JsonProperty("after")] + object After { get; set; } /// /// Defines how many composite buckets should be returned. @@ -28,50 +28,51 @@ public interface ICompositeAggregation : IBucketAggregation int? Size { get; set; } /// - /// Used to retrieve the composite buckets that are after the - /// last composite buckets returned in a previous round + /// Controls the sources that should be used to build the composite buckets /// - [JsonProperty("after")] - object After { get; set; } + [JsonProperty("sources")] + IEnumerable Sources { get; set; } } - /// + /// public class CompositeAggregation : BucketAggregationBase, ICompositeAggregation { internal CompositeAggregation() { } public CompositeAggregation(string name) : base(name) { } - internal override void WrapInContainer(AggregationContainer c) => c.Composite = this; - /// - public IEnumerable Sources { get; set; } + public object After { get; set; } /// public int? Size { get; set; } /// - public object After { get; set; } + public IEnumerable Sources { get; set; } + + internal override void WrapInContainer(AggregationContainer c) => c.Composite = this; } - /// + /// public class CompositeAggregationDescriptor : BucketAggregationDescriptorBase, ICompositeAggregation, T> , ICompositeAggregation where T : class { - IEnumerable ICompositeAggregation.Sources { get; set; } - int? ICompositeAggregation.Size { get; set; } object ICompositeAggregation.After { get; set; } + int? ICompositeAggregation.Size { get; set; } + IEnumerable ICompositeAggregation.Sources { get; set; } - /// - public CompositeAggregationDescriptor Sources(Func, IPromise>> selector) => + /// + public CompositeAggregationDescriptor Sources( + Func, IPromise>> selector + ) => Assign(a => a.Sources = selector?.Invoke(new CompositeAggregationSourcesDescriptor())?.Value); - /// + /// public CompositeAggregationDescriptor Size(int? size) => Assign(a => a.Size = size); - /// + /// public CompositeAggregationDescriptor After(object after) => Assign(a => a.After = after); } } diff --git a/src/Nest/Aggregations/Bucket/Composite/CompositeAggregationSource.cs b/src/Nest/Aggregations/Bucket/Composite/CompositeAggregationSource.cs index cb736b1f704..a7ea04f992f 100644 --- a/src/Nest/Aggregations/Bucket/Composite/CompositeAggregationSource.cs +++ b/src/Nest/Aggregations/Bucket/Composite/CompositeAggregationSource.cs @@ -8,54 +8,47 @@ namespace Nest { /// - /// A values source for + /// A values source for /// [ContractJsonConverter(typeof(CompositeAggregationSourceConverter))] public interface ICompositeAggregationSource { /// - /// The name of the source + /// The field from which to extract value /// - [JsonIgnore] - string Name { get; set; } + [JsonProperty("field")] + Field Field { get; set; } /// - /// The type of the source + /// By default documents without a value for a given source are ignored. It is possible to include + /// them in the response as null by setting this to true /// - [JsonIgnore] - string SourceType { get; } + [JsonProperty("missing_bucket")] + bool? MissingBucket { get; set; } /// - /// The field from which to extract value + /// The name of the source /// - [JsonProperty("field")] - Field Field { get; set; } + [JsonIgnore] + string Name { get; set; } /// /// Defines the direction of sorting for each - /// value source. Defaults to + /// value source. Defaults to /// [JsonProperty("order")] SortOrder? Order { get; set; } /// - /// By default documents without a value for a given source are ignored. It is possible to include - /// them in the response as null by setting this to true + /// The type of the source /// - [JsonProperty("missing_bucket")] - bool? MissingBucket { get; set; } + [JsonIgnore] + string SourceType { get; } } /// public abstract class CompositeAggregationSourceBase : ICompositeAggregationSource { - /// - string ICompositeAggregationSource.Name { get; set; } - string ICompositeAggregationSource.SourceType => SourceType; - - /// - protected abstract string SourceType { get; } - internal CompositeAggregationSourceBase() { } protected CompositeAggregationSourceBase(string name) => @@ -64,34 +57,48 @@ protected CompositeAggregationSourceBase(string name) => /// public Field Field { get; set; } + /// + public bool? MissingBucket { get; set; } + /// public SortOrder? Order { get; set; } + /// + protected abstract string SourceType { get; } + /// - public bool? MissingBucket { get; set; } + string ICompositeAggregationSource.Name { get; set; } + + string ICompositeAggregationSource.SourceType => SourceType; } - /// - public class CompositeAggregationSourcesDescriptor : - DescriptorPromiseBase, IList> + /// + public class CompositeAggregationSourcesDescriptor + : DescriptorPromiseBase, IList> where T : class { - public CompositeAggregationSourcesDescriptor() : base(new List()) {} + public CompositeAggregationSourcesDescriptor() : base(new List()) { } - /// - public CompositeAggregationSourcesDescriptor Terms(string name, Func, ITermsCompositeAggregationSource> selector) => + /// + public CompositeAggregationSourcesDescriptor Terms(string name, + Func, ITermsCompositeAggregationSource> selector + ) => Assign(a => a.Add(selector?.Invoke(new TermsCompositeAggregationSourceDescriptor(name)))); - /// - public CompositeAggregationSourcesDescriptor Histogram(string name, Func, IHistogramCompositeAggregationSource> selector) => + /// + public CompositeAggregationSourcesDescriptor Histogram(string name, + Func, IHistogramCompositeAggregationSource> selector + ) => Assign(a => a.Add(selector?.Invoke(new HistogramCompositeAggregationSourceDescriptor(name)))); - /// - public CompositeAggregationSourcesDescriptor DateHistogram(string name, Func, IDateHistogramCompositeAggregationSource> selector) => + /// + public CompositeAggregationSourcesDescriptor DateHistogram(string name, + Func, IDateHistogramCompositeAggregationSource> selector + ) => Assign(a => a.Add(selector?.Invoke(new DateHistogramCompositeAggregationSourceDescriptor(name)))); } - /// + /// public abstract class CompositeAggregationSourceDescriptorBase : DescriptorBase, ICompositeAggregationSource where TDescriptor : CompositeAggregationSourceDescriptorBase, TInterface @@ -99,28 +106,29 @@ public abstract class CompositeAggregationSourceDescriptorBase _sourceType; - Field ICompositeAggregationSource.Field { get; set; } - SortOrder? ICompositeAggregationSource.Order { get; set; } - bool? ICompositeAggregationSource.MissingBucket { get; set; } - protected CompositeAggregationSourceDescriptorBase(string name, string sourceType) { _sourceType = sourceType; Self.Name = name; } - /// + Field ICompositeAggregationSource.Field { get; set; } + bool? ICompositeAggregationSource.MissingBucket { get; set; } + + string ICompositeAggregationSource.Name { get; set; } + SortOrder? ICompositeAggregationSource.Order { get; set; } + string ICompositeAggregationSource.SourceType => _sourceType; + + /// public TDescriptor Field(Field field) => Assign(a => a.Field = field); - /// - public TDescriptor Field(Expression> objectPath) => Assign(a => a.Field = objectPath); + /// + public TDescriptor Field(Expression> objectPath) => Assign(a => a.Field = objectPath); - /// + /// public TDescriptor Order(SortOrder? order) => Assign(a => a.Order = order); - /// + /// public TDescriptor MissingBucket(bool? includeMissing = true) => Assign(a => a.MissingBucket = includeMissing); } @@ -158,11 +166,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist protected override void SerializeJson(JsonWriter writer, object value, ICompositeAggregationSource castValue, JsonSerializer serializer) { writer.WriteStartObject(); - writer.WritePropertyName(castValue.Name); - writer.WriteStartObject(); - writer.WritePropertyName(castValue.SourceType); - base.Reserialize(writer, value, serializer); - writer.WriteEndObject(); + writer.WritePropertyName(castValue.Name); + writer.WriteStartObject(); + writer.WritePropertyName(castValue.SourceType); + Reserialize(writer, value, serializer); + writer.WriteEndObject(); writer.WriteEndObject(); } } diff --git a/src/Nest/Aggregations/Bucket/Composite/CompositeBucket.cs b/src/Nest/Aggregations/Bucket/Composite/CompositeBucket.cs index 72c95479d35..2eb228e7435 100644 --- a/src/Nest/Aggregations/Bucket/Composite/CompositeBucket.cs +++ b/src/Nest/Aggregations/Bucket/Composite/CompositeBucket.cs @@ -12,26 +12,24 @@ public CompositeBucket(IReadOnlyDictionary dict, CompositeKe Key = key; /// - /// The bucket key + /// The count of documents /// - public CompositeKey Key { get; } + public long? DocCount { get; set; } /// - /// The count of documents + /// The bucket key /// - public long? DocCount { get; set; } + public CompositeKey Key { get; } } /// - /// A key for a + /// A key for a /// public class CompositeKey : IsAReadOnlyDictionaryBase { private static readonly DateTimeOffset Epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero); - public CompositeKey(IReadOnlyDictionary backingDictionary) : base(backingDictionary) - { - } + public CompositeKey(IReadOnlyDictionary backingDictionary) : base(backingDictionary) { } /// /// Tries to get a value with the given key as a string. Returns false if the key does @@ -92,7 +90,7 @@ public bool TryGetValue(string key, out DateTimeOffset value) private bool TryGetValue(string key, out TValue value) { - if (!this.BackingDictionary.TryGetValue(key, out var obj)) + if (!BackingDictionary.TryGetValue(key, out var obj)) { value = default(TValue); return false; @@ -100,7 +98,7 @@ private bool TryGetValue(string key, out TValue value) try { - value = (TValue) Convert.ChangeType(obj, typeof(TValue)); + value = (TValue)Convert.ChangeType(obj, typeof(TValue)); return true; } catch diff --git a/src/Nest/Aggregations/Bucket/Composite/DateHistogramCompositeAggregationSource.cs b/src/Nest/Aggregations/Bucket/Composite/DateHistogramCompositeAggregationSource.cs index fc700b44987..8cca5eb08ad 100644 --- a/src/Nest/Aggregations/Bucket/Composite/DateHistogramCompositeAggregationSource.cs +++ b/src/Nest/Aggregations/Bucket/Composite/DateHistogramCompositeAggregationSource.cs @@ -10,7 +10,14 @@ namespace Nest public interface IDateHistogramCompositeAggregationSource : ICompositeAggregationSource { /// - /// The interval to use when bucketing documents + /// Return a formatted date string as the key instead an epoch long + /// + /// Valid for Elasticsearch 6.3.0+ + [JsonProperty("format")] + string Format { get; set; } + + /// + /// The interval to use when bucketing documents /// [JsonProperty("interval")] Union Interval { get; set; } @@ -22,56 +29,49 @@ public interface IDateHistogramCompositeAggregationSource : ICompositeAggregatio /// [JsonProperty("time_zone")] string Timezone { get; set; } - - /// - /// Return a formatted date string as the key instead an epoch long - /// - /// Valid for Elasticsearch 6.3.0+ - [JsonProperty("format")] - string Format { get; set; } } - /// + /// public class DateHistogramCompositeAggregationSource : CompositeAggregationSourceBase, IDateHistogramCompositeAggregationSource { - public DateHistogramCompositeAggregationSource(string name) : base(name) {} + public DateHistogramCompositeAggregationSource(string name) : base(name) { } /// - public Union Interval { get; set; } + public string Format { get; set; } /// - public string Timezone { get; set; } + public Union Interval { get; set; } /// - public string Format { get; set; } + public string Timezone { get; set; } /// protected override string SourceType => "date_histogram"; } - /// + /// public class DateHistogramCompositeAggregationSourceDescriptor : CompositeAggregationSourceDescriptorBase, IDateHistogramCompositeAggregationSource, T>, IDateHistogramCompositeAggregationSource { - Union IDateHistogramCompositeAggregationSource.Interval { get; set; } - string IDateHistogramCompositeAggregationSource.Timezone { get; set; } - string IDateHistogramCompositeAggregationSource.Format { get; set; } + public DateHistogramCompositeAggregationSourceDescriptor(string name) : base(name, "date_histogram") { } - public DateHistogramCompositeAggregationSourceDescriptor(string name) : base(name, "date_histogram") {} + string IDateHistogramCompositeAggregationSource.Format { get; set; } + Union IDateHistogramCompositeAggregationSource.Interval { get; set; } + string IDateHistogramCompositeAggregationSource.Timezone { get; set; } - /// + /// public DateHistogramCompositeAggregationSourceDescriptor Interval(DateInterval? interval) => Assign(a => a.Interval = interval); - /// + /// public DateHistogramCompositeAggregationSourceDescriptor Interval(Time interval) => Assign(a => a.Interval = interval); - /// + /// public DateHistogramCompositeAggregationSourceDescriptor Timezone(string timezone) => Assign(a => a.Timezone = timezone); - /// + /// public DateHistogramCompositeAggregationSourceDescriptor Format(string format) => Assign(a => a.Format = format); } } diff --git a/src/Nest/Aggregations/Bucket/Composite/HistogramCompositeAggregationSource.cs b/src/Nest/Aggregations/Bucket/Composite/HistogramCompositeAggregationSource.cs index b9ff0522168..d3ab6b9dfcd 100644 --- a/src/Nest/Aggregations/Bucket/Composite/HistogramCompositeAggregationSource.cs +++ b/src/Nest/Aggregations/Bucket/Composite/HistogramCompositeAggregationSource.cs @@ -11,48 +11,49 @@ namespace Nest /// public interface IHistogramCompositeAggregationSource : ICompositeAggregationSource { - /// - /// A script to create the values for the composite buckets - /// - [JsonProperty("script")] - IScript Script { get; set; } - /// /// The interval to use when bucketing documents /// [JsonProperty("interval")] double? Interval { get; set; } + + /// + /// A script to create the values for the composite buckets + /// + [JsonProperty("script")] + IScript Script { get; set; } } - /// + /// public class HistogramCompositeAggregationSource : CompositeAggregationSourceBase, IHistogramCompositeAggregationSource { - public HistogramCompositeAggregationSource(string name) : base(name) {} + public HistogramCompositeAggregationSource(string name) : base(name) { } /// - public IScript Script { get; set; } + public double? Interval { get; set; } /// - public double? Interval { get; set; } + public IScript Script { get; set; } /// protected override string SourceType => "histogram"; } - /// + /// public class HistogramCompositeAggregationSourceDescriptor - : CompositeAggregationSourceDescriptorBase, IHistogramCompositeAggregationSource, T>, IHistogramCompositeAggregationSource + : CompositeAggregationSourceDescriptorBase, IHistogramCompositeAggregationSource, T>, + IHistogramCompositeAggregationSource { + public HistogramCompositeAggregationSourceDescriptor(string name) : base(name, "histogram") { } + double? IHistogramCompositeAggregationSource.Interval { get; set; } IScript IHistogramCompositeAggregationSource.Script { get; set; } - public HistogramCompositeAggregationSourceDescriptor(string name) : base(name, "histogram") {} - - /// + /// public HistogramCompositeAggregationSourceDescriptor Interval(double? interval) => Assign(a => a.Interval = interval); - /// + /// public HistogramCompositeAggregationSourceDescriptor Script(Func selector) => Assign(a => a.Script = selector?.Invoke(new ScriptDescriptor())); } diff --git a/src/Nest/Aggregations/Bucket/Composite/TermsCompositeAggregationSource.cs b/src/Nest/Aggregations/Bucket/Composite/TermsCompositeAggregationSource.cs index 27e09850f6a..45202289d7d 100644 --- a/src/Nest/Aggregations/Bucket/Composite/TermsCompositeAggregationSource.cs +++ b/src/Nest/Aggregations/Bucket/Composite/TermsCompositeAggregationSource.cs @@ -3,7 +3,6 @@ namespace Nest { - /// /// A values source that is equivalent to a simple terms aggregation. /// The values are extracted from a field or a script exactly like the terms aggregation. @@ -17,10 +16,10 @@ public interface ITermsCompositeAggregationSource : ICompositeAggregationSource IScript Script { get; set; } } - /// + /// public class TermsCompositeAggregationSource : CompositeAggregationSourceBase, ITermsCompositeAggregationSource { - public TermsCompositeAggregationSource(string name) : base(name) {} + public TermsCompositeAggregationSource(string name) : base(name) { } /// public IScript Script { get; set; } @@ -29,15 +28,16 @@ public TermsCompositeAggregationSource(string name) : base(name) {} protected override string SourceType => "terms"; } - /// + /// public class TermsCompositeAggregationSourceDescriptor - : CompositeAggregationSourceDescriptorBase, ITermsCompositeAggregationSource, T>, ITermsCompositeAggregationSource + : CompositeAggregationSourceDescriptorBase, ITermsCompositeAggregationSource, T>, + ITermsCompositeAggregationSource { - IScript ITermsCompositeAggregationSource.Script { get; set; } + public TermsCompositeAggregationSourceDescriptor(string name) : base(name, "terms") { } - public TermsCompositeAggregationSourceDescriptor(string name) : base(name, "terms") {} + IScript ITermsCompositeAggregationSource.Script { get; set; } - /// + /// public TermsCompositeAggregationSourceDescriptor Script(Func selector) => Assign(a => a.Script = selector?.Invoke(new ScriptDescriptor())); } diff --git a/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs b/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs index 136fd1e9782..469577c23b1 100644 --- a/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs +++ b/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramAggregation.cs @@ -9,26 +9,23 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IDateHistogramAggregation : IBucketAggregation { + [JsonProperty("extended_bounds")] + ExtendedBounds ExtendedBounds { get; set; } + [JsonProperty("field")] Field Field { get; set; } - [JsonProperty("script")] - IScript Script { get; set; } - - [JsonProperty("params")] - IDictionary Params { get; set; } + [JsonProperty("format")] + string Format { get; set; } [JsonProperty("interval")] Union Interval { get; set; } - [JsonProperty("format")] - string Format { get; set; } - [JsonProperty("min_doc_count")] int? MinimumDocumentCount { get; set; } - [JsonProperty("time_zone")] - string TimeZone { get; set; } + [JsonProperty("missing")] + DateTime? Missing { get; set; } [JsonProperty("offset")] string Offset { get; set; } @@ -36,41 +33,46 @@ public interface IDateHistogramAggregation : IBucketAggregation [JsonProperty("order")] HistogramOrder Order { get; set; } - [JsonProperty("extended_bounds")] - ExtendedBounds ExtendedBounds { get; set; } + [JsonProperty("params")] + IDictionary Params { get; set; } - [JsonProperty("missing")] - DateTime? Missing { get; set; } + [JsonProperty("script")] + IScript Script { get; set; } + + [JsonProperty("time_zone")] + string TimeZone { get; set; } } public class DateHistogramAggregation : BucketAggregationBase, IDateHistogramAggregation { private string _format; + + internal DateHistogramAggregation() { } + + public DateHistogramAggregation(string name) : base(name) { } + + public ExtendedBounds ExtendedBounds { get; set; } public Field Field { get; set; } - public IScript Script { get; set; } - public IDictionary Params { get; set; } - public Union Interval { get; set; } public string Format { get => !string.IsNullOrEmpty(_format) && - !_format.Contains("date_optional_time") && - (ExtendedBounds != null || Missing.HasValue) - ? _format + "||date_optional_time" - : _format; + !_format.Contains("date_optional_time") && + (ExtendedBounds != null || Missing.HasValue) + ? _format + "||date_optional_time" + : _format; set => _format = value; } + public Union Interval { get; set; } + public int? MinimumDocumentCount { get; set; } - public string TimeZone { get; set; } + public DateTime? Missing { get; set; } public string Offset { get; set; } public HistogramOrder Order { get; set; } - public ExtendedBounds ExtendedBounds { get; set; } - public DateTime? Missing { get; set; } - - internal DateHistogramAggregation() { } - - public DateHistogramAggregation(string name) : base(name) { } + public IDictionary Params { get; set; } + public IScript Script { get; set; } + public string TimeZone { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.DateHistogram = this; } @@ -81,35 +83,35 @@ public class DateHistogramAggregationDescriptor where T : class { private string _format; - Field IDateHistogramAggregation.Field { get; set; } - IScript IDateHistogramAggregation.Script { get; set; } - - IDictionary IDateHistogramAggregation.Params { get; set; } - - Union IDateHistogramAggregation.Interval { get; set; } + ExtendedBounds IDateHistogramAggregation.ExtendedBounds { get; set; } + Field IDateHistogramAggregation.Field { get; set; } string IDateHistogramAggregation.Format { get => !string.IsNullOrEmpty(_format) && - !_format.Contains("date_optional_time") && - (Self.ExtendedBounds != null || Self.Missing.HasValue) - ? _format + "||date_optional_time" - : _format; + !_format.Contains("date_optional_time") && + (Self.ExtendedBounds != null || Self.Missing.HasValue) + ? _format + "||date_optional_time" + : _format; set => _format = value; } + Union IDateHistogramAggregation.Interval { get; set; } + int? IDateHistogramAggregation.MinimumDocumentCount { get; set; } - string IDateHistogramAggregation.TimeZone { get; set; } + DateTime? IDateHistogramAggregation.Missing { get; set; } string IDateHistogramAggregation.Offset { get; set; } HistogramOrder IDateHistogramAggregation.Order { get; set; } - ExtendedBounds IDateHistogramAggregation.ExtendedBounds { get; set; } + IDictionary IDateHistogramAggregation.Params { get; set; } - DateTime? IDateHistogramAggregation.Missing { get; set; } + IScript IDateHistogramAggregation.Script { get; set; } + + string IDateHistogramAggregation.TimeZone { get; set; } public DateHistogramAggregationDescriptor Field(Field field) => Assign(a => a.Field = field); @@ -143,7 +145,7 @@ public DateHistogramAggregationDescriptor OrderDescending(string key) => Assign(a => a.Order = new HistogramOrder { Key = key, Order = SortOrder.Descending }); public DateHistogramAggregationDescriptor ExtendedBounds(DateMath min, DateMath max) => - Assign(a=>a.ExtendedBounds = new ExtendedBounds { Minimum = min, Maximum = max }); + Assign(a => a.ExtendedBounds = new ExtendedBounds { Minimum = min, Maximum = max }); public DateHistogramAggregationDescriptor Missing(DateTime? missing) => Assign(a => a.Missing = missing); } diff --git a/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramBucket.cs b/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramBucket.cs index 6c655595dd6..34cce9f6523 100644 --- a/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramBucket.cs +++ b/src/Nest/Aggregations/Bucket/DateHistogram/DateHistogramBucket.cs @@ -1,18 +1,15 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Nest { public class DateHistogramBucket : KeyedBucket { - private static readonly long EpochTicks = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero).Ticks; + private static readonly long EpochTicks = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero).Ticks; public DateHistogramBucket(IReadOnlyDictionary dict) : base(dict) { } // Get a DateTime form of the returned key - public DateTime Date => new DateTime(EpochTicks + ((long)this.Key * TimeSpan.TicksPerMillisecond), DateTimeKind.Utc); + public DateTime Date => new DateTime(EpochTicks + (long)Key * TimeSpan.TicksPerMillisecond, DateTimeKind.Utc); } } diff --git a/src/Nest/Aggregations/Bucket/DateHistogram/DateInterval.cs b/src/Nest/Aggregations/Bucket/DateHistogram/DateInterval.cs index 2b219c36381..91982ab408c 100644 --- a/src/Nest/Aggregations/Bucket/DateHistogram/DateInterval.cs +++ b/src/Nest/Aggregations/Bucket/DateHistogram/DateInterval.cs @@ -8,21 +8,27 @@ namespace Nest public enum DateInterval { [EnumMember(Value = "second")] - Second, + Second, + [EnumMember(Value = "minute")] - Minute, + Minute, + [EnumMember(Value = "hour")] - Hour, + Hour, + [EnumMember(Value = "day")] Day, + [EnumMember(Value = "week")] - Week, + Week, + [EnumMember(Value = "month")] - Month, + Month, + [EnumMember(Value = "quarter")] - Quarter, + Quarter, + [EnumMember(Value = "year")] Year } - } diff --git a/src/Nest/Aggregations/Bucket/DateRange/DateRangeAggregation.cs b/src/Nest/Aggregations/Bucket/DateRange/DateRangeAggregation.cs index 5d8b5d5a014..e904609ff3e 100644 --- a/src/Nest/Aggregations/Bucket/DateRange/DateRangeAggregation.cs +++ b/src/Nest/Aggregations/Bucket/DateRange/DateRangeAggregation.cs @@ -25,15 +25,15 @@ public interface IDateRangeAggregation : IBucketAggregation public class DateRangeAggregation : BucketAggregationBase, IDateRangeAggregation { + internal DateRangeAggregation() { } + + public DateRangeAggregation(string name) : base(name) { } + public Field Field { get; set; } public string Format { get; set; } public IEnumerable Ranges { get; set; } public string TimeZone { get; set; } - internal DateRangeAggregation() { } - - public DateRangeAggregation(string name) : base(name) { } - internal override void WrapInContainer(AggregationContainer c) => c.DateRange = this; } @@ -57,14 +57,14 @@ public class DateRangeAggregationDescriptor public DateRangeAggregationDescriptor Format(string format) => Assign(a => a.Format = format); public DateRangeAggregationDescriptor Ranges(params IDateRangeExpression[] ranges) => - Assign(a=>a.Ranges = ranges.ToListOrNullIfEmpty()); + Assign(a => a.Ranges = ranges.ToListOrNullIfEmpty()); public DateRangeAggregationDescriptor TimeZone(string timeZone) => Assign(a => a.TimeZone = timeZone); public DateRangeAggregationDescriptor Ranges(params Func[] ranges) => - Assign(a=>a.Ranges = ranges?.Select(r=>r(new DateRangeExpressionDescriptor())).ToListOrNullIfEmpty()); + Assign(a => a.Ranges = ranges?.Select(r => r(new DateRangeExpressionDescriptor())).ToListOrNullIfEmpty()); public DateRangeAggregationDescriptor Ranges(IEnumerable> ranges) => - Assign(a=>a.Ranges = ranges?.Select(r=>r(new DateRangeExpressionDescriptor())).ToListOrNullIfEmpty()); + Assign(a => a.Ranges = ranges?.Select(r => r(new DateRangeExpressionDescriptor())).ToListOrNullIfEmpty()); } } diff --git a/src/Nest/Aggregations/Bucket/DateRange/DateRangeExpression.cs b/src/Nest/Aggregations/Bucket/DateRange/DateRangeExpression.cs index b1472e4ce78..f8b10c834be 100644 --- a/src/Nest/Aggregations/Bucket/DateRange/DateRangeExpression.cs +++ b/src/Nest/Aggregations/Bucket/DateRange/DateRangeExpression.cs @@ -8,32 +8,35 @@ public interface IDateRangeExpression [JsonProperty("from")] DateMath From { get; set; } - [JsonProperty("to")] - DateMath To { get; set; } - [JsonProperty("key")] string Key { get; set; } + + [JsonProperty("to")] + DateMath To { get; set; } } public class DateRangeExpression : IDateRangeExpression { public DateMath From { get; set; } - public DateMath To { get; set; } - public string Key { get; set; } + + public DateMath To { get; set; } } public class DateRangeExpressionDescriptor : DescriptorBase, IDateRangeExpression { DateMath IDateRangeExpression.From { get; set; } - public DateRangeExpressionDescriptor From(DateMath from) => Assign(a => a.From = from); + + string IDateRangeExpression.Key { get; set; } DateMath IDateRangeExpression.To { get; set; } + + public DateRangeExpressionDescriptor From(DateMath from) => Assign(a => a.From = from); + public DateRangeExpressionDescriptor To(DateMath to) => Assign(a => a.To = to); - string IDateRangeExpression.Key { get; set; } public DateRangeExpressionDescriptor Key(string key) => Assign(a => a.Key = key); } } diff --git a/src/Nest/Aggregations/Bucket/Filter/FilterAggregation.cs b/src/Nest/Aggregations/Bucket/Filter/FilterAggregation.cs index 89b7fbf90b7..9ca113729ef 100644 --- a/src/Nest/Aggregations/Bucket/Filter/FilterAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Filter/FilterAggregation.cs @@ -13,24 +13,23 @@ public interface IFilterAggregation : IBucketAggregation public class FilterAggregation : BucketAggregationBase, IFilterAggregation { - public QueryContainer Filter { get; set; } - internal FilterAggregation() { } public FilterAggregation(string name) : base(name) { } + public QueryContainer Filter { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.Filter = this; } public class FilterAggregationDescriptor - : BucketAggregationDescriptorBase,IFilterAggregation, T> + : BucketAggregationDescriptorBase, IFilterAggregation, T> , IFilterAggregation where T : class { QueryContainer IFilterAggregation.Filter { get; set; } public FilterAggregationDescriptor Filter(Func, QueryContainer> selector) => - Assign(a=> a.Filter = selector?.Invoke(new QueryContainerDescriptor())); - + Assign(a => a.Filter = selector?.Invoke(new QueryContainerDescriptor())); } } diff --git a/src/Nest/Aggregations/Bucket/Filter/FilterAggregationJsonConverter.cs b/src/Nest/Aggregations/Bucket/Filter/FilterAggregationJsonConverter.cs index f20ead0b1ad..35faa34d500 100644 --- a/src/Nest/Aggregations/Bucket/Filter/FilterAggregationJsonConverter.cs +++ b/src/Nest/Aggregations/Bucket/Filter/FilterAggregationJsonConverter.cs @@ -19,7 +19,8 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s writer.WriteStartObject(); writer.WriteEndObject(); return; - }; + } + ; serializer.Serialize(writer, f.Filter); } @@ -27,6 +28,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) return null; + var container = new QueryContainer(); serializer.Populate(reader, container); var agg = new FilterAggregation(); @@ -34,5 +36,4 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return agg; } } - } diff --git a/src/Nest/Aggregations/Bucket/Filters/FiltersAggregate.cs b/src/Nest/Aggregations/Bucket/Filters/FiltersAggregate.cs index 9370d1498cd..1c85a5a95c4 100644 --- a/src/Nest/Aggregations/Bucket/Filters/FiltersAggregate.cs +++ b/src/Nest/Aggregations/Bucket/Filters/FiltersAggregate.cs @@ -1,5 +1,4 @@ - -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; namespace Nest @@ -25,13 +24,13 @@ public FiltersBucketItem(IReadOnlyDictionary dict) : base(di public class FiltersAggregate : BucketAggregateBase { public FiltersAggregate() : base(EmptyReadOnly.Dictionary) { } - public FiltersAggregate(IReadOnlyDictionary aggregations) : base(aggregations) { } - - public SingleBucketAggregate NamedBucket(string key) => this.Global(key); - public IList AnonymousBuckets() => this.Buckets?.ToList(); + public FiltersAggregate(IReadOnlyDictionary aggregations) : base(aggregations) { } public IReadOnlyCollection Buckets { get; set; } = EmptyReadOnly.Collection; + public SingleBucketAggregate NamedBucket(string key) => Global(key); + + public IList AnonymousBuckets() => Buckets?.ToList(); } } diff --git a/src/Nest/Aggregations/Bucket/Filters/FiltersAggregation.cs b/src/Nest/Aggregations/Bucket/Filters/FiltersAggregation.cs index bda9bd8b4f9..28f972394df 100644 --- a/src/Nest/Aggregations/Bucket/Filters/FiltersAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Filters/FiltersAggregation.cs @@ -21,6 +21,10 @@ public interface IFiltersAggregation : IBucketAggregation public class FiltersAggregation : BucketAggregationBase, IFiltersAggregation { + internal FiltersAggregation() { } + + public FiltersAggregation(string name) : base(name) { } + public Union> Filters { get; set; } /// @@ -36,27 +40,23 @@ public class FiltersAggregation : BucketAggregationBase, IFiltersAggregation /// /// Gets or sets the key for the other bucket to a value other than the default "_other_". - /// Setting this parameter will implicitly set the parameter to true + /// Setting this parameter will implicitly set the parameter to true /// public string OtherBucketKey { get; set; } - internal FiltersAggregation() { } - - public FiltersAggregation(string name) : base(name) { } - internal override void WrapInContainer(AggregationContainer c) => c.Filters = this; } public class FiltersAggregationDescriptor : BucketAggregationDescriptorBase, IFiltersAggregation, T> - , IFiltersAggregation + , IFiltersAggregation where T : class { Union> IFiltersAggregation.Filters { get; set; } - bool? IFiltersAggregation.OtherBucket{ get; set; } + bool? IFiltersAggregation.OtherBucket { get; set; } - string IFiltersAggregation.OtherBucketKey{ get; set; } + string IFiltersAggregation.OtherBucketKey { get; set; } /// /// Adds a bucket to the response which will contain all documents @@ -68,27 +68,27 @@ public class FiltersAggregationDescriptor /// the other bucket. /// /// whether to set the other bucket - /// the + /// the public FiltersAggregationDescriptor OtherBucket(bool? otherBucket = true) => Assign(a => a.OtherBucket = otherBucket); /// /// Sets the key for the other bucket to a value other than the default "_other_". - /// Setting this parameter will implicitly set the parameter to true + /// Setting this parameter will implicitly set the parameter to true /// /// the name for the other bucket - /// the + /// the public FiltersAggregationDescriptor OtherBucketKey(string otherBucketKey) => Assign(a => a.OtherBucketKey = otherBucketKey); public FiltersAggregationDescriptor NamedFilters(Func, IPromise> selector) => - Assign(a => a.Filters = new Union>(selector?.Invoke(new NamedFiltersContainerDescriptor())?.Value)); + Assign(a => a.Filters = + new Union>(selector?.Invoke(new NamedFiltersContainerDescriptor())?.Value)); public FiltersAggregationDescriptor AnonymousFilters(params Func, QueryContainer>[] selectors) => - Assign(a => a.Filters = selectors.Select(s=>s?.Invoke(new QueryContainerDescriptor())).ToList()); + Assign(a => a.Filters = selectors.Select(s => s?.Invoke(new QueryContainerDescriptor())).ToList()); public FiltersAggregationDescriptor AnonymousFilters(IEnumerable, QueryContainer>> selectors) => - Assign(a => a.Filters = selectors.Select(s=>s?.Invoke(new QueryContainerDescriptor())).ToList()); - + Assign(a => a.Filters = selectors.Select(s => s?.Invoke(new QueryContainerDescriptor())).ToList()); } } diff --git a/src/Nest/Aggregations/Bucket/Filters/NamedFiltersContainer.cs b/src/Nest/Aggregations/Bucket/Filters/NamedFiltersContainer.cs index a5cb7d69c7b..18d0443b65a 100644 --- a/src/Nest/Aggregations/Bucket/Filters/NamedFiltersContainer.cs +++ b/src/Nest/Aggregations/Bucket/Filters/NamedFiltersContainer.cs @@ -8,19 +8,22 @@ namespace Nest [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public interface INamedFiltersContainer : IIsADictionary { } - public class NamedFiltersContainer: IsADictionaryBase, INamedFiltersContainer + public class NamedFiltersContainer : IsADictionaryBase, INamedFiltersContainer { - public NamedFiltersContainer() {} + public NamedFiltersContainer() { } + public NamedFiltersContainer(IDictionary container) : base(container) { } + public NamedFiltersContainer(Dictionary container) - : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => (IQueryContainer)kv.Value)) - { } + : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => (IQueryContainer)kv.Value)) { } public void Add(string name, IQueryContainer filter) => BackingDictionary.Add(name, filter); + public void Add(string name, QueryContainer filter) => BackingDictionary.Add(name, filter); } - public class NamedFiltersContainerDescriptor : IsADictionaryDescriptorBase, INamedFiltersContainer, string, IQueryContainer> + public class NamedFiltersContainerDescriptor + : IsADictionaryDescriptorBase, INamedFiltersContainer, string, IQueryContainer> where T : class { public NamedFiltersContainerDescriptor() : base(new NamedFiltersContainer()) { } @@ -33,7 +36,5 @@ public NamedFiltersContainerDescriptor Filter(string name, Func Filter(string name, Func, QueryContainer> selector) where TOther : class => Assign(name, selector?.Invoke(new QueryContainerDescriptor())); - } - } diff --git a/src/Nest/Aggregations/Bucket/GeoDistance/GeoDistanceAggregation.cs b/src/Nest/Aggregations/Bucket/GeoDistance/GeoDistanceAggregation.cs index abd9e00f5de..859ab2e48be 100644 --- a/src/Nest/Aggregations/Bucket/GeoDistance/GeoDistanceAggregation.cs +++ b/src/Nest/Aggregations/Bucket/GeoDistance/GeoDistanceAggregation.cs @@ -10,57 +10,54 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IGeoDistanceAggregation : IBucketAggregation { + [JsonProperty("distance_type")] + GeoDistanceType? DistanceType { get; set; } + [JsonProperty("field")] Field Field { get; set; } [JsonProperty("origin")] GeoLocation Origin { get; set; } - [JsonProperty("unit")] - DistanceUnit? Unit { get; set; } - - [JsonProperty("distance_type")] - GeoDistanceType? DistanceType { get; set; } - [JsonProperty("ranges")] IEnumerable Ranges { get; set; } + [JsonProperty("unit")] + DistanceUnit? Unit { get; set; } } public class GeoDistanceAggregation : BucketAggregationBase, IGeoDistanceAggregation { - public Field Field { get; set; } - - public GeoLocation Origin { get; set; } + internal GeoDistanceAggregation() { } - public DistanceUnit? Unit { get; set; } + public GeoDistanceAggregation(string name) : base(name) { } public GeoDistanceType? DistanceType { get; set; } + public Field Field { get; set; } - public IEnumerable Ranges { get; set; } + public GeoLocation Origin { get; set; } - internal GeoDistanceAggregation() { } + public IEnumerable Ranges { get; set; } - public GeoDistanceAggregation(string name) : base(name) { } + public DistanceUnit? Unit { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.GeoDistance = this; } - public class GeoDistanceAggregationDescriptor : - BucketAggregationDescriptorBase, IGeoDistanceAggregation, T> + public class GeoDistanceAggregationDescriptor + : BucketAggregationDescriptorBase, IGeoDistanceAggregation, T> , IGeoDistanceAggregation where T : class { + GeoDistanceType? IGeoDistanceAggregation.DistanceType { get; set; } Field IGeoDistanceAggregation.Field { get; set; } GeoLocation IGeoDistanceAggregation.Origin { get; set; } - DistanceUnit? IGeoDistanceAggregation.Unit { get; set; } - - GeoDistanceType? IGeoDistanceAggregation.DistanceType { get; set; } - IEnumerable IGeoDistanceAggregation.Ranges { get; set; } + DistanceUnit? IGeoDistanceAggregation.Unit { get; set; } + public GeoDistanceAggregationDescriptor Field(Field field) => Assign(a => a.Field = field); public GeoDistanceAggregationDescriptor Field(Expression> field) => Assign(a => a.Field = field); diff --git a/src/Nest/Aggregations/Bucket/GeoHashGrid/GeoHashGridAggregation.cs b/src/Nest/Aggregations/Bucket/GeoHashGrid/GeoHashGridAggregation.cs index b816bebf52c..d61e82f404c 100644 --- a/src/Nest/Aggregations/Bucket/GeoHashGrid/GeoHashGridAggregation.cs +++ b/src/Nest/Aggregations/Bucket/GeoHashGrid/GeoHashGridAggregation.cs @@ -11,27 +11,27 @@ public interface IGeoHashGridAggregation : IBucketAggregation [JsonProperty("field")] Field Field { get; set; } - [JsonProperty("size")] - int? Size { get; set; } + [JsonProperty("precision")] + GeoHashPrecision? Precision { get; set; } [JsonProperty("shard_size")] int? ShardSize { get; set; } - [JsonProperty("precision")] - GeoHashPrecision? Precision { get; set; } + [JsonProperty("size")] + int? Size { get; set; } } public class GeoHashGridAggregation : BucketAggregationBase, IGeoHashGridAggregation { - public Field Field { get; set; } - public int? Size { get; set; } - public int? ShardSize { get; set; } - public GeoHashPrecision? Precision { get; set; } - internal GeoHashGridAggregation() { } public GeoHashGridAggregation(string name) : base(name) { } + public Field Field { get; set; } + public GeoHashPrecision? Precision { get; set; } + public int? ShardSize { get; set; } + public int? Size { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.GeoHash = this; } @@ -42,11 +42,11 @@ public class GeoHashGridAggregationDescriptor { Field IGeoHashGridAggregation.Field { get; set; } - int? IGeoHashGridAggregation.Size { get; set; } + GeoHashPrecision? IGeoHashGridAggregation.Precision { get; set; } int? IGeoHashGridAggregation.ShardSize { get; set; } - GeoHashPrecision? IGeoHashGridAggregation.Precision { get; set; } + int? IGeoHashGridAggregation.Size { get; set; } public GeoHashGridAggregationDescriptor Field(Field field) => Assign(a => a.Field = field); diff --git a/src/Nest/Aggregations/Bucket/Global/GlobalAggregation.cs b/src/Nest/Aggregations/Bucket/Global/GlobalAggregation.cs index 4a2f080e1dc..6fec34a3b11 100644 --- a/src/Nest/Aggregations/Bucket/Global/GlobalAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Global/GlobalAggregation.cs @@ -2,7 +2,6 @@ namespace Nest { - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IGlobalAggregation : IBucketAggregation { } @@ -16,8 +15,8 @@ public GlobalAggregation(string name) : base(name) { } internal override void WrapInContainer(AggregationContainer c) => c.Global = this; } - public class GlobalAggregationDescriptor + public class GlobalAggregationDescriptor : BucketAggregationDescriptorBase, IGlobalAggregation, T> , IGlobalAggregation where T : class { } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Bucket/Histogram/ExtendedBounds.cs b/src/Nest/Aggregations/Bucket/Histogram/ExtendedBounds.cs index c3ef9951885..12e58c0e3a2 100644 --- a/src/Nest/Aggregations/Bucket/Histogram/ExtendedBounds.cs +++ b/src/Nest/Aggregations/Bucket/Histogram/ExtendedBounds.cs @@ -4,10 +4,10 @@ namespace Nest { public class ExtendedBounds { - [JsonProperty("min")] - public T Minimum { get; set; } - [JsonProperty("max")] public T Maximum { get; set; } + + [JsonProperty("min")] + public T Minimum { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Bucket/Histogram/HistogramAggregation.cs b/src/Nest/Aggregations/Bucket/Histogram/HistogramAggregation.cs index 7d359ccb712..7e8b6777dcb 100644 --- a/src/Nest/Aggregations/Bucket/Histogram/HistogramAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Histogram/HistogramAggregation.cs @@ -8,45 +8,45 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IHistogramAggregation : IBucketAggregation { + [JsonProperty("extended_bounds")] + ExtendedBounds ExtendedBounds { get; set; } + [JsonProperty("field")] Field Field { get; set; } - [JsonProperty("script")] - IScript Script { get; set; } - [JsonProperty("interval")] double? Interval { get; set; } [JsonProperty("min_doc_count")] int? MinimumDocumentCount { get; set; } - [JsonProperty("order")] - HistogramOrder Order { get; set; } - - [JsonProperty("extended_bounds")] - ExtendedBounds ExtendedBounds { get; set; } + [JsonProperty("missing")] + double? Missing { get; set; } [JsonProperty("offset")] double? Offset { get; set; } - [JsonProperty("missing")] - double? Missing { get; set; } + [JsonProperty("order")] + HistogramOrder Order { get; set; } + + [JsonProperty("script")] + IScript Script { get; set; } } public class HistogramAggregation : BucketAggregationBase, IHistogramAggregation { + internal HistogramAggregation() { } + + public HistogramAggregation(string name) : base(name) { } + + public ExtendedBounds ExtendedBounds { get; set; } public Field Field { get; set; } - public IScript Script { get; set; } public double? Interval { get; set; } public int? MinimumDocumentCount { get; set; } - public HistogramOrder Order { get; set; } - public ExtendedBounds ExtendedBounds { get; set; } - public double? Offset { get; set; } public double? Missing { get; set; } - - internal HistogramAggregation() { } - - public HistogramAggregation(string name) : base(name) { } + public double? Offset { get; set; } + public HistogramOrder Order { get; set; } + public IScript Script { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.Histogram = this; } @@ -55,21 +55,20 @@ public class HistogramAggregationDescriptor : BucketAggregationDescriptorBase, IHistogramAggregation, T>, IHistogramAggregation where T : class { + ExtendedBounds IHistogramAggregation.ExtendedBounds { get; set; } Field IHistogramAggregation.Field { get; set; } - IScript IHistogramAggregation.Script { get; set; } - double? IHistogramAggregation.Interval { get; set; } int? IHistogramAggregation.MinimumDocumentCount { get; set; } - HistogramOrder IHistogramAggregation.Order { get; set; } - - ExtendedBounds IHistogramAggregation.ExtendedBounds { get; set; } + double? IHistogramAggregation.Missing { get; set; } double? IHistogramAggregation.Offset { get; set; } - double? IHistogramAggregation.Missing { get; set; } + HistogramOrder IHistogramAggregation.Order { get; set; } + + IScript IHistogramAggregation.Script { get; set; } public HistogramAggregationDescriptor Field(Field field) => Assign(a => a.Field = field); diff --git a/src/Nest/Aggregations/Bucket/Histogram/HistogramOrder.cs b/src/Nest/Aggregations/Bucket/Histogram/HistogramOrder.cs index 176c610248d..2903ebe7e26 100644 --- a/src/Nest/Aggregations/Bucket/Histogram/HistogramOrder.cs +++ b/src/Nest/Aggregations/Bucket/Histogram/HistogramOrder.cs @@ -5,14 +5,12 @@ namespace Nest [JsonConverter(typeof(KeyValueJsonConverter))] public class HistogramOrder { - public string Key { get; set; } - public SortOrder Order { get; set; } - public static HistogramOrder CountAscending => new HistogramOrder { Key = "_count", Order = SortOrder.Ascending }; public static HistogramOrder CountDescending => new HistogramOrder { Key = "_count", Order = SortOrder.Descending }; + public string Key { get; set; } public static HistogramOrder KeyAscending => new HistogramOrder { Key = "_key", Order = SortOrder.Ascending }; public static HistogramOrder KeyDescending => new HistogramOrder { Key = "_key", Order = SortOrder.Descending }; - + public SortOrder Order { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Bucket/IpRange/IpRange.cs b/src/Nest/Aggregations/Bucket/IpRange/IpRange.cs index a79beed37c7..b84b6aa1abf 100644 --- a/src/Nest/Aggregations/Bucket/IpRange/IpRange.cs +++ b/src/Nest/Aggregations/Bucket/IpRange/IpRange.cs @@ -9,20 +9,20 @@ public interface IIpRange [JsonProperty("from")] string From { get; set; } - [JsonProperty("to")] - string To { get; set; } - [JsonProperty("mask")] string Mask { get; set; } + + [JsonProperty("to")] + string To { get; set; } } public class IpRange : IIpRange { public string From { get; set; } - public string To { get; set; } - public string Mask { get; set; } + + public string To { get; set; } } public class IpRangeDescriptor @@ -33,7 +33,9 @@ public class IpRangeDescriptor string IIpRange.To { get; set; } public IpRangeDescriptor From(string from) => Assign(a => a.From = from); + public IpRangeDescriptor To(string to) => Assign(a => a.To = to); + public IpRangeDescriptor Mask(string mask) => Assign(a => a.Mask = mask); } } diff --git a/src/Nest/Aggregations/Bucket/IpRange/IpRangeAggregation.cs b/src/Nest/Aggregations/Bucket/IpRange/IpRangeAggregation.cs index e6c179393aa..54e14f964b3 100644 --- a/src/Nest/Aggregations/Bucket/IpRange/IpRangeAggregation.cs +++ b/src/Nest/Aggregations/Bucket/IpRange/IpRangeAggregation.cs @@ -19,18 +19,18 @@ public interface IIpRangeAggregation : IBucketAggregation public class IpRangeAggregation : BucketAggregationBase, IIpRangeAggregation { - public Field Field { get; set; } - public IEnumerable Ranges { get; set; } - internal IpRangeAggregation() { } public IpRangeAggregation(string name) : base(name) { } + public Field Field { get; set; } + public IEnumerable Ranges { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.IpRange = this; } - public class IpRangeAggregationDescriptor : - BucketAggregationDescriptorBase,IIpRangeAggregation, T> + public class IpRangeAggregationDescriptor + : BucketAggregationDescriptorBase, IIpRangeAggregation, T> , IIpRangeAggregation where T : class { diff --git a/src/Nest/Aggregations/Bucket/KeyedBucket.cs b/src/Nest/Aggregations/Bucket/KeyedBucket.cs index 4577f9cc0e4..7817ee9ac62 100644 --- a/src/Nest/Aggregations/Bucket/KeyedBucket.cs +++ b/src/Nest/Aggregations/Bucket/KeyedBucket.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Nest { @@ -9,10 +6,11 @@ public class KeyedBucket : BucketBase { public KeyedBucket(IReadOnlyDictionary dict) : base(dict) { } - public TKey Key { get; set; } - public string KeyAsString { get; set; } public long? DocCount { get; set; } public long? DocCountErrorUpperBound { get; set; } + + public TKey Key { get; set; } + public string KeyAsString { get; set; } } } diff --git a/src/Nest/Aggregations/Bucket/Missing/MissingAggregation.cs b/src/Nest/Aggregations/Bucket/Missing/MissingAggregation.cs index 1c14dd97680..4a5789bfd1d 100644 --- a/src/Nest/Aggregations/Bucket/Missing/MissingAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Missing/MissingAggregation.cs @@ -14,17 +14,17 @@ public interface IMissingAggregation : IBucketAggregation public class MissingAggregation : BucketAggregationBase, IMissingAggregation { - public Field Field { get; set; } - internal MissingAggregation() { } public MissingAggregation(string name) : base(name) { } + public Field Field { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.Missing = this; } public class MissingAggregationDescriptor - : BucketAggregationDescriptorBase,IMissingAggregation, T> + : BucketAggregationDescriptorBase, IMissingAggregation, T> , IMissingAggregation where T : class { diff --git a/src/Nest/Aggregations/Bucket/Nested/NestedAggregation.cs b/src/Nest/Aggregations/Bucket/Nested/NestedAggregation.cs index 0e1a27c857c..f806b5a39bb 100644 --- a/src/Nest/Aggregations/Bucket/Nested/NestedAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Nested/NestedAggregation.cs @@ -9,17 +9,17 @@ namespace Nest public interface INestedAggregation : IBucketAggregation { [JsonProperty("path")] - Field Path { get; set;} + Field Path { get; set; } } public class NestedAggregation : BucketAggregationBase, INestedAggregation { - public Field Path { get; set; } - internal NestedAggregation() { } public NestedAggregation(string name) : base(name) { } + public Field Path { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.Nested = this; } diff --git a/src/Nest/Aggregations/Bucket/Range/RangeAggregation.cs b/src/Nest/Aggregations/Bucket/Range/RangeAggregation.cs index b36396a59a4..da951727be7 100644 --- a/src/Nest/Aggregations/Bucket/Range/RangeAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Range/RangeAggregation.cs @@ -13,22 +13,23 @@ public interface IRangeAggregation : IBucketAggregation [JsonProperty("field")] Field Field { get; set; } - [JsonProperty("script")] - IScript Script { get; set; } - [JsonProperty("ranges")] IEnumerable Ranges { get; set; } + + [JsonProperty("script")] + IScript Script { get; set; } } public class RangeAggregation : BucketAggregationBase, IRangeAggregation { - public Field Field { get; set; } - public IScript Script { get; set; } - public IEnumerable Ranges { get; set; } internal RangeAggregation() { } public RangeAggregation(string name) : base(name) { } + public Field Field { get; set; } + public IEnumerable Ranges { get; set; } + public IScript Script { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.Range = this; } @@ -38,10 +39,10 @@ public class RangeAggregationDescriptor { Field IRangeAggregation.Field { get; set; } - IScript IRangeAggregation.Script { get; set; } - IEnumerable IRangeAggregation.Ranges { get; set; } + IScript IRangeAggregation.Script { get; set; } + public RangeAggregationDescriptor Field(Field field) => Assign(a => a.Field = field); public RangeAggregationDescriptor Field(Expression> field) => Assign(a => a.Field = field); diff --git a/src/Nest/Aggregations/Bucket/Range/RangeBucket.cs b/src/Nest/Aggregations/Bucket/Range/RangeBucket.cs index 20f11969d58..490e9a7a3f4 100644 --- a/src/Nest/Aggregations/Bucket/Range/RangeBucket.cs +++ b/src/Nest/Aggregations/Bucket/Range/RangeBucket.cs @@ -6,11 +6,12 @@ public class RangeBucket : BucketBase, IBucket { public RangeBucket(IReadOnlyDictionary dict) : base(dict) { } - public string Key { get; set; } + public long DocCount { get; set; } public double? From { get; set; } public string FromAsString { get; set; } + + public string Key { get; set; } public double? To { get; set; } public string ToAsString { get; set; } - public long DocCount { get; set; } } } diff --git a/src/Nest/Aggregations/Bucket/ReverseNested/ReverseNestedAggregation.cs b/src/Nest/Aggregations/Bucket/ReverseNested/ReverseNestedAggregation.cs index 098fde530ff..e4e9377e3fd 100644 --- a/src/Nest/Aggregations/Bucket/ReverseNested/ReverseNestedAggregation.cs +++ b/src/Nest/Aggregations/Bucket/ReverseNested/ReverseNestedAggregation.cs @@ -14,18 +14,18 @@ public interface IReverseNestedAggregation : IBucketAggregation public class ReverseNestedAggregation : BucketAggregationBase, IReverseNestedAggregation { - [JsonProperty("path")] - public Field Path { get; set; } - internal ReverseNestedAggregation() { } public ReverseNestedAggregation(string name) : base(name) { } + [JsonProperty("path")] + public Field Path { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.ReverseNested = this; } public class ReverseNestedAggregationDescriptor - : BucketAggregationDescriptorBase,IReverseNestedAggregation, T> + : BucketAggregationDescriptorBase, IReverseNestedAggregation, T> , IReverseNestedAggregation where T : class { diff --git a/src/Nest/Aggregations/Bucket/Sampler/SamplerAggregation.cs b/src/Nest/Aggregations/Bucket/Sampler/SamplerAggregation.cs index 1f28e64638a..da703030afc 100644 --- a/src/Nest/Aggregations/Bucket/Sampler/SamplerAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Sampler/SamplerAggregation.cs @@ -1,5 +1,4 @@ using System; -using System.Linq.Expressions; using Newtonsoft.Json; namespace Nest @@ -8,8 +7,8 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface ISamplerAggregation : IBucketAggregation { - [JsonProperty("shard_size")] - int? ShardSize { get; set; } + [JsonProperty("execution_hint")] + SamplerAggregationExecutionHint? ExecutionHint { get; set; } [JsonProperty("max_docs_per_value")] int? MaxDocsPerValue { get; set; } @@ -17,21 +16,21 @@ public interface ISamplerAggregation : IBucketAggregation [JsonProperty("script")] IScript Script { get; set; } - [JsonProperty("execution_hint")] - SamplerAggregationExecutionHint? ExecutionHint { get; set; } + [JsonProperty("shard_size")] + int? ShardSize { get; set; } } public class SamplerAggregation : BucketAggregationBase, ISamplerAggregation { + internal SamplerAggregation() { } + + public SamplerAggregation(string name) : base(name) { } + public SamplerAggregationExecutionHint? ExecutionHint { get; set; } public int? MaxDocsPerValue { get; set; } public IScript Script { get; set; } public int? ShardSize { get; set; } - internal SamplerAggregation() { } - - public SamplerAggregation(string name) : base(name) { } - internal override void WrapInContainer(AggregationContainer c) => c.Sampler = this; } diff --git a/src/Nest/Aggregations/Bucket/Sampler/SamplerAggregationExecutionHint.cs b/src/Nest/Aggregations/Bucket/Sampler/SamplerAggregationExecutionHint.cs index de04ff9104f..16f7a8c4921 100644 --- a/src/Nest/Aggregations/Bucket/Sampler/SamplerAggregationExecutionHint.cs +++ b/src/Nest/Aggregations/Bucket/Sampler/SamplerAggregationExecutionHint.cs @@ -9,9 +9,11 @@ public enum SamplerAggregationExecutionHint { [EnumMember(Value = "map")] Map, - [EnumMember(Value = "global_ordinals")] + + [EnumMember(Value = "global_ordinals")] GlobalOrdinals, - [EnumMember(Value = "bytes_hash")] + + [EnumMember(Value = "bytes_hash")] BytesHash } } diff --git a/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/ChiSquareHeuristic.cs b/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/ChiSquareHeuristic.cs index 09d3640805b..438b9989146 100644 --- a/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/ChiSquareHeuristic.cs +++ b/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/ChiSquareHeuristic.cs @@ -6,17 +6,17 @@ namespace Nest [JsonConverter(typeof(ReadAsTypeJsonConverter))] public interface IChiSquareHeuristic { - [JsonProperty("include_negatives")] - bool? IncludeNegatives { get; set; } - [JsonProperty("background_is_superset")] bool? BackgroundIsSuperSet { get; set; } + + [JsonProperty("include_negatives")] + bool? IncludeNegatives { get; set; } } public class ChiSquareHeuristic : IChiSquareHeuristic { - public bool? IncludeNegatives { get; set; } public bool? BackgroundIsSuperSet { get; set; } + public bool? IncludeNegatives { get; set; } } public class ChiSquareHeuristicDescriptor diff --git a/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/MutualInformationHeuristic.cs b/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/MutualInformationHeuristic.cs index 8fb00aa7355..c4be34af93e 100644 --- a/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/MutualInformationHeuristic.cs +++ b/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/MutualInformationHeuristic.cs @@ -6,24 +6,24 @@ namespace Nest [JsonConverter(typeof(ReadAsTypeJsonConverter))] public interface IMutualInformationHeuristic { - [JsonProperty("include_negatives")] - bool? IncludeNegatives { get; set; } - [JsonProperty("background_is_superset")] bool? BackgroundIsSuperSet { get; set; } + + [JsonProperty("include_negatives")] + bool? IncludeNegatives { get; set; } } public class MutualInformationHeuristic : IMutualInformationHeuristic { - public bool? IncludeNegatives { get; set; } public bool? BackgroundIsSuperSet { get; set; } + public bool? IncludeNegatives { get; set; } } public class MutualInformationHeuristicDescriptor : DescriptorBase, IMutualInformationHeuristic { - bool? IMutualInformationHeuristic.IncludeNegatives { get; set; } bool? IMutualInformationHeuristic.BackgroundIsSuperSet { get; set; } + bool? IMutualInformationHeuristic.IncludeNegatives { get; set; } public MutualInformationHeuristicDescriptor IncludeNegatives(bool? includeNegatives = true) => Assign(a => a.IncludeNegatives = includeNegatives); diff --git a/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/PercentageScoreHeuristic.cs b/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/PercentageScoreHeuristic.cs index 16782ff88dc..6305fa96236 100644 --- a/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/PercentageScoreHeuristic.cs +++ b/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/PercentageScoreHeuristic.cs @@ -8,7 +8,6 @@ public interface IPercentageScoreHeuristic { } public class PercentageScoreHeuristic { } - public class PercentageScoreHeuristicDescriptor - : DescriptorBase, IPercentageScoreHeuristic - { } -} \ No newline at end of file + public class PercentageScoreHeuristicDescriptor + : DescriptorBase, IPercentageScoreHeuristic { } +} diff --git a/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/ScriptedHeuristic.cs b/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/ScriptedHeuristic.cs index 20b4dda9489..c4e1bb5d91a 100644 --- a/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/ScriptedHeuristic.cs +++ b/src/Nest/Aggregations/Bucket/SignificantTerms/Heuristics/ScriptedHeuristic.cs @@ -5,7 +5,7 @@ namespace Nest { [JsonObject] [JsonConverter(typeof(ReadAsTypeJsonConverter))] - public interface IScriptedHeuristic + public interface IScriptedHeuristic { [JsonProperty("script")] IScript Script { get; set; } @@ -16,7 +16,7 @@ public class ScriptedHeuristic : IScriptedHeuristic public IScript Script { get; set; } } - public class ScriptedHeuristicDescriptor + public class ScriptedHeuristicDescriptor : DescriptorBase, IScriptedHeuristic { IScript IScriptedHeuristic.Script { get; set; } @@ -26,4 +26,4 @@ public class ScriptedHeuristicDescriptor public ScriptedHeuristicDescriptor Script(Func scriptSelector) => Assign(a => a.Script = scriptSelector?.Invoke(new ScriptDescriptor())); } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregate.cs b/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregate.cs index 61f452a18a2..d15d2c3941c 100644 --- a/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregate.cs +++ b/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregate.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Nest +namespace Nest { public class SignificantTermsAggregate : MultiBucketAggregate { - public long DocCount { get; set; } public long? BgCount { get; set; } + public long DocCount { get; set; } } } diff --git a/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregation.cs b/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregation.cs index 92180e0a143..0f9f81735c3 100644 --- a/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregation.cs +++ b/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregation.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Linq.Expressions; using Newtonsoft.Json; @@ -11,46 +10,43 @@ namespace Nest public interface ISignificantTermsAggregation : IBucketAggregation { /// - /// The field on which to run the aggregation + /// The default source of statistical information for background term + /// frequencies is the entire index. This scope can be narrowed + /// through the use of a background filter to focus in on significant + /// terms within a narrower context /// - [JsonProperty("field")] - Field Field { get; set; } + [JsonProperty("background_filter")] + QueryContainer BackgroundFilter { get; set; } /// - /// Defines how many term buckets should be returned out of the overall - /// terms list + /// Use chi square to calculate significance score /// - [JsonProperty("size")] - int? Size { get; set; } + [JsonProperty("chi_square")] + IChiSquareHeuristic ChiSquare { get; set; } /// - /// Controls the number of candidate terms produced by each shard from which - /// the of terms is selected. + /// Exclude term values for which buckets will be created. /// - [JsonProperty("shard_size")] - int? ShardSize { get; set; } + [JsonProperty("exclude")] + SignificantTermsIncludeExclude Exclude { get; set; } /// - /// Return only terms that match equal to or more than a configurable - /// number of hits + /// Determines the mechanism by which aggregations are executed /// - [JsonProperty("min_doc_count")] - long? MinimumDocumentCount { get; set; } + [JsonProperty("execution_hint")] + TermsAggregationExecutionHint? ExecutionHint { get; set; } /// - /// Regulates the certainty a shard has if the term should actually be added to the candidate - /// list or not with respect to the . - /// Terms will only be considered if their local shard frequency within - /// the set is higher than the . + /// The field on which to run the aggregation /// - [JsonProperty("shard_min_doc_count")] - long? ShardMinimumDocumentCount { get; set; } + [JsonProperty("field")] + Field Field { get; set; } /// - /// Determines the mechanism by which aggregations are executed + /// Use Google normalized distance to calculate significance score /// - [JsonProperty("execution_hint")] - TermsAggregationExecutionHint? ExecutionHint { get; set; } + [JsonProperty("gnd")] + IGoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } /// /// Include term values for which buckets will be created. @@ -59,10 +55,11 @@ public interface ISignificantTermsAggregation : IBucketAggregation SignificantTermsIncludeExclude Include { get; set; } /// - /// Exclude term values for which buckets will be created. + /// Return only terms that match equal to or more than a configurable + /// number of hits /// - [JsonProperty("exclude")] - SignificantTermsIncludeExclude Exclude { get; set; } + [JsonProperty("min_doc_count")] + long? MinimumDocumentCount { get; set; } /// /// Use mutual information to calculate significance score @@ -70,24 +67,14 @@ public interface ISignificantTermsAggregation : IBucketAggregation [JsonProperty("mutual_information")] IMutualInformationHeuristic MutualInformation { get; set; } - /// - /// Use chi square to calculate significance score - /// - [JsonProperty("chi_square")] - IChiSquareHeuristic ChiSquare { get; set; } - - /// - /// Use Google normalized distance to calculate significance score - /// - [JsonProperty("gnd")] - IGoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } - /// /// Use percentage to calculate significance score. - /// A simple calculation of the number of documents in the foreground + /// + /// A simple calculation of the number of documents in the foreground /// sample with a term divided by the number of documents in the background /// with the term. By default this produces a score greater than zero - /// and less than one. + /// and less than one. + /// /// [JsonProperty("percentage")] IPercentageScoreHeuristic PercentageScore { get; set; } @@ -99,49 +86,76 @@ public interface ISignificantTermsAggregation : IBucketAggregation IScriptedHeuristic Script { get; set; } /// - /// The default source of statistical information for background term - /// frequencies is the entire index. This scope can be narrowed - /// through the use of a background filter to focus in on significant - /// terms within a narrower context + /// Regulates the certainty a shard has if the term should actually be added to the candidate + /// list or not with respect to the . + /// Terms will only be considered if their local shard frequency within + /// the set is higher than the . /// - [JsonProperty("background_filter")] - QueryContainer BackgroundFilter { get; set; } + [JsonProperty("shard_min_doc_count")] + long? ShardMinimumDocumentCount { get; set; } + + /// + /// Controls the number of candidate terms produced by each shard from which + /// the of terms is selected. + /// + [JsonProperty("shard_size")] + int? ShardSize { get; set; } + + /// + /// Defines how many term buckets should be returned out of the overall + /// terms list + /// + [JsonProperty("size")] + int? Size { get; set; } } public class SignificantTermsAggregation : BucketAggregationBase, ISignificantTermsAggregation { + internal SignificantTermsAggregation() { } + + public SignificantTermsAggregation(string name) : base(name) { } + /// - public Field Field { get; set; } + public QueryContainer BackgroundFilter { get; set; } + /// - public int? Size { get; set; } + public IChiSquareHeuristic ChiSquare { get; set; } + /// - public int? ShardSize { get; set; } + public SignificantTermsIncludeExclude Exclude { get; set; } + /// - public long? MinimumDocumentCount { get; set; } + public TermsAggregationExecutionHint? ExecutionHint { get; set; } + /// - public long? ShardMinimumDocumentCount { get; set; } + public Field Field { get; set; } + /// - public TermsAggregationExecutionHint? ExecutionHint { get; set; } + public IGoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } + /// public SignificantTermsIncludeExclude Include { get; set; } + /// - public SignificantTermsIncludeExclude Exclude { get; set; } + public long? MinimumDocumentCount { get; set; } + /// public IMutualInformationHeuristic MutualInformation { get; set; } - /// - public IChiSquareHeuristic ChiSquare { get; set; } - /// - public IGoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } + /// public IPercentageScoreHeuristic PercentageScore { get; set; } + /// public IScriptedHeuristic Script { get; set; } + /// - public QueryContainer BackgroundFilter { get; set; } + public long? ShardMinimumDocumentCount { get; set; } - internal SignificantTermsAggregation() { } + /// + public int? ShardSize { get; set; } - public SignificantTermsAggregation(string name) : base(name) { } + /// + public int? Size { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.SignificantTerms = this; } @@ -151,33 +165,32 @@ public class SignificantTermsAggregationDescriptor , ISignificantTermsAggregation where T : class { - Field ISignificantTermsAggregation.Field { get; set; } - - int? ISignificantTermsAggregation.Size { get; set; } - - int? ISignificantTermsAggregation.ShardSize { get; set; } + QueryContainer ISignificantTermsAggregation.BackgroundFilter { get; set; } - long? ISignificantTermsAggregation.MinimumDocumentCount { get; set; } + IChiSquareHeuristic ISignificantTermsAggregation.ChiSquare { get; set; } - long? ISignificantTermsAggregation.ShardMinimumDocumentCount { get; set; } + SignificantTermsIncludeExclude ISignificantTermsAggregation.Exclude { get; set; } TermsAggregationExecutionHint? ISignificantTermsAggregation.ExecutionHint { get; set; } + Field ISignificantTermsAggregation.Field { get; set; } + + IGoogleNormalizedDistanceHeuristic ISignificantTermsAggregation.GoogleNormalizedDistance { get; set; } SignificantTermsIncludeExclude ISignificantTermsAggregation.Include { get; set; } - SignificantTermsIncludeExclude ISignificantTermsAggregation.Exclude { get; set; } + long? ISignificantTermsAggregation.MinimumDocumentCount { get; set; } IMutualInformationHeuristic ISignificantTermsAggregation.MutualInformation { get; set; } - IChiSquareHeuristic ISignificantTermsAggregation.ChiSquare { get; set; } - - IGoogleNormalizedDistanceHeuristic ISignificantTermsAggregation.GoogleNormalizedDistance { get; set; } - IPercentageScoreHeuristic ISignificantTermsAggregation.PercentageScore { get; set; } IScriptedHeuristic ISignificantTermsAggregation.Script { get; set; } - QueryContainer ISignificantTermsAggregation.BackgroundFilter { get; set; } + long? ISignificantTermsAggregation.ShardMinimumDocumentCount { get; set; } + + int? ISignificantTermsAggregation.ShardSize { get; set; } + + int? ISignificantTermsAggregation.Size { get; set; } /// public SignificantTermsAggregationDescriptor Field(Field field) => Assign(a => a.Field = field); @@ -219,7 +232,9 @@ public SignificantTermsAggregationDescriptor ShardMinimumDocumentCount(long? Assign(a => a.ShardMinimumDocumentCount = shardMinimumDocumentCount); /// - public SignificantTermsAggregationDescriptor MutualInformation(Func mutualInformationSelector = null) => + public SignificantTermsAggregationDescriptor MutualInformation( + Func mutualInformationSelector = null + ) => Assign(a => a.MutualInformation = mutualInformationSelector.InvokeOrDefault(new MutualInformationHeuristicDescriptor())); /// @@ -227,11 +242,15 @@ public SignificantTermsAggregationDescriptor ChiSquare(Func a.ChiSquare = chiSquareSelector.InvokeOrDefault(new ChiSquareHeuristicDescriptor())); /// - public SignificantTermsAggregationDescriptor GoogleNormalizedDistance(Func gndSelector) => + public SignificantTermsAggregationDescriptor GoogleNormalizedDistance( + Func gndSelector + ) => Assign(a => a.GoogleNormalizedDistance = gndSelector.InvokeOrDefault(new GoogleNormalizedDistanceHeuristicDescriptor())); /// - public SignificantTermsAggregationDescriptor PercentageScore(Func percentageScoreSelector) => + public SignificantTermsAggregationDescriptor PercentageScore( + Func percentageScoreSelector + ) => Assign(a => a.PercentageScore = percentageScoreSelector.InvokeOrDefault(new PercentageScoreHeuristicDescriptor())); /// diff --git a/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsBucket.cs b/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsBucket.cs index db04ad36936..6be5df8b49d 100644 --- a/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsBucket.cs +++ b/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsBucket.cs @@ -6,9 +6,10 @@ public class SignificantTermsBucket : BucketBase, IBucket { public SignificantTermsBucket(IReadOnlyDictionary dict) : base(dict) { } - public string Key { get; set; } public long BgCount { get; set; } public long DocCount { get; set; } + + public string Key { get; set; } public double Score { get; set; } } } diff --git a/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsIncludeExclude.cs b/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsIncludeExclude.cs index b47dd4e1ead..7578bbcbeed 100644 --- a/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsIncludeExclude.cs +++ b/src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsIncludeExclude.cs @@ -7,15 +7,15 @@ namespace Nest [JsonConverter(typeof(SignificantTermsIncludeExcludeJsonConverter))] public class SignificantTermsIncludeExclude { + public SignificantTermsIncludeExclude(string pattern) => Pattern = pattern; + + public SignificantTermsIncludeExclude(IEnumerable values) => Values = values; + [JsonIgnore] public string Pattern { get; set; } [JsonIgnore] public IEnumerable Values { get; set; } - - public SignificantTermsIncludeExclude(string pattern) => Pattern = pattern; - - public SignificantTermsIncludeExclude(IEnumerable values) => Values = values; } internal class SignificantTermsIncludeExcludeJsonConverter : JsonConverter diff --git a/src/Nest/Aggregations/Bucket/SignificantText/SignificantTextAggregation.cs b/src/Nest/Aggregations/Bucket/SignificantText/SignificantTextAggregation.cs index c76196a0939..2a9cf7245c2 100644 --- a/src/Nest/Aggregations/Bucket/SignificantText/SignificantTextAggregation.cs +++ b/src/Nest/Aggregations/Bucket/SignificantText/SignificantTextAggregation.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Linq.Expressions; using Newtonsoft.Json; @@ -14,46 +13,49 @@ namespace Nest public interface ISignificantTextAggregation : IBucketAggregation { /// - /// The field on which to run the aggregation + /// The default source of statistical information for background term + /// frequencies is the entire index. This scope can be narrowed + /// through the use of a background filter to focus in on significant + /// terms within a narrower context /// - [JsonProperty("field")] - Field Field { get; set; } + [JsonProperty("background_filter")] + QueryContainer BackgroundFilter { get; set; } /// - /// Defines how many term buckets should be returned out of the overall - /// terms list + /// Use chi square to calculate significance score /// - [JsonProperty("size")] - int? Size { get; set; } + [JsonProperty("chi_square")] + IChiSquareHeuristic ChiSquare { get; set; } /// - /// Controls the number of candidate terms produced by each shard from which - /// the of terms is selected. + /// Exclude term values for which buckets will be created. /// - [JsonProperty("shard_size")] - int? ShardSize { get; set; } + [JsonProperty("exclude")] + SignificantTermsIncludeExclude Exclude { get; set; } /// - /// Return only terms that match equal to or more than a configurable - /// number of hits + /// Determines the mechanism by which aggregations are executed /// - [JsonProperty("min_doc_count")] - long? MinimumDocumentCount { get; set; } + [JsonProperty("execution_hint")] + TermsAggregationExecutionHint? ExecutionHint { get; set; } /// - /// Regulates the certainty a shard has if the term should actually be added to the candidate - /// list or not with respect to the . - /// Terms will only be considered if their local shard frequency within - /// the set is higher than the . + /// The field on which to run the aggregation /// - [JsonProperty("shard_min_doc_count")] - long? ShardMinimumDocumentCount { get; set; } + [JsonProperty("field")] + Field Field { get; set; } /// - /// Determines the mechanism by which aggregations are executed + /// Whether to filter out near-duplicate text /// - [JsonProperty("execution_hint")] - TermsAggregationExecutionHint? ExecutionHint { get; set; } + [JsonProperty("filter_duplicate_text")] + bool? FilterDuplicateText { get; set; } + + /// + /// Use Google normalized distance to calculate significance score + /// + [JsonProperty("gnd")] + IGoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } /// /// Include term values for which buckets will be created. @@ -62,10 +64,11 @@ public interface ISignificantTextAggregation : IBucketAggregation SignificantTermsIncludeExclude Include { get; set; } /// - /// Exclude term values for which buckets will be created. + /// Return only terms that match equal to or more than a configurable + /// number of hits /// - [JsonProperty("exclude")] - SignificantTermsIncludeExclude Exclude { get; set; } + [JsonProperty("min_doc_count")] + long? MinimumDocumentCount { get; set; } /// /// Use mutual information to calculate significance score @@ -73,24 +76,14 @@ public interface ISignificantTextAggregation : IBucketAggregation [JsonProperty("mutual_information")] IMutualInformationHeuristic MutualInformation { get; set; } - /// - /// Use chi square to calculate significance score - /// - [JsonProperty("chi_square")] - IChiSquareHeuristic ChiSquare { get; set; } - - /// - /// Use Google normalized distance to calculate significance score - /// - [JsonProperty("gnd")] - IGoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } - /// /// Use percentage to calculate significance score. - /// A simple calculation of the number of documents in the foreground + /// + /// A simple calculation of the number of documents in the foreground /// sample with a term divided by the number of documents in the background /// with the term. By default this produces a score greater than zero - /// and less than one. + /// and less than one. + /// /// [JsonProperty("percentage")] IPercentageScoreHeuristic PercentageScore { get; set; } @@ -102,19 +95,27 @@ public interface ISignificantTextAggregation : IBucketAggregation IScriptedHeuristic Script { get; set; } /// - /// The default source of statistical information for background term - /// frequencies is the entire index. This scope can be narrowed - /// through the use of a background filter to focus in on significant - /// terms within a narrower context + /// Regulates the certainty a shard has if the term should actually be added to the candidate + /// list or not with respect to the . + /// Terms will only be considered if their local shard frequency within + /// the set is higher than the . /// - [JsonProperty("background_filter")] - QueryContainer BackgroundFilter { get; set; } + [JsonProperty("shard_min_doc_count")] + long? ShardMinimumDocumentCount { get; set; } /// - /// Whether to filter out near-duplicate text + /// Controls the number of candidate terms produced by each shard from which + /// the of terms is selected. /// - [JsonProperty("filter_duplicate_text")] - bool? FilterDuplicateText { get; set; } + [JsonProperty("shard_size")] + int? ShardSize { get; set; } + + /// + /// Defines how many term buckets should be returned out of the overall + /// terms list + /// + [JsonProperty("size")] + int? Size { get; set; } /// /// Ordinarily the indexed field name and the original JSON field being @@ -122,165 +123,185 @@ public interface ISignificantTextAggregation : IBucketAggregation /// mappings using features like copy_to the source JSON field(s) /// and the indexed field being aggregated can differ. /// In these cases it is possible to list the JSON _source fields - /// from which text will be analyzed using + /// from which text will be analyzed using /// [JsonProperty("source_fields")] Fields SourceFields { get; set; } } - /// + /// public class SignificantTextAggregation : BucketAggregationBase, ISignificantTextAggregation { + internal SignificantTextAggregation() { } + + public SignificantTextAggregation(string name) : base(name) { } + /// - public Field Field { get; set; } + public QueryContainer BackgroundFilter { get; set; } + /// - public int? Size { get; set; } + public IChiSquareHeuristic ChiSquare { get; set; } + /// - public int? ShardSize { get; set; } + public SignificantTermsIncludeExclude Exclude { get; set; } + /// - public long? MinimumDocumentCount { get; set; } + public TermsAggregationExecutionHint? ExecutionHint { get; set; } + /// - public long? ShardMinimumDocumentCount { get; set; } + public Field Field { get; set; } + /// - public TermsAggregationExecutionHint? ExecutionHint { get; set; } + public bool? FilterDuplicateText { get; set; } + + /// + public IGoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } + /// public SignificantTermsIncludeExclude Include { get; set; } + /// - public SignificantTermsIncludeExclude Exclude { get; set; } + public long? MinimumDocumentCount { get; set; } + /// public IMutualInformationHeuristic MutualInformation { get; set; } - /// - public IChiSquareHeuristic ChiSquare { get; set; } - /// - public IGoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } + /// public IPercentageScoreHeuristic PercentageScore { get; set; } + /// public IScriptedHeuristic Script { get; set; } + /// - public QueryContainer BackgroundFilter { get; set; } - /// - public bool? FilterDuplicateText { get; set; } + public long? ShardMinimumDocumentCount { get; set; } + /// - public Fields SourceFields { get; set; } + public int? ShardSize { get; set; } - internal SignificantTextAggregation() { } + /// + public int? Size { get; set; } - public SignificantTextAggregation(string name) : base(name) { } + /// + public Fields SourceFields { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.SignificantText = this; } - /// + /// public class SignificantTextAggregationDescriptor : BucketAggregationDescriptorBase, ISignificantTextAggregation, T> , ISignificantTextAggregation where T : class { - Field ISignificantTextAggregation.Field { get; set; } + QueryContainer ISignificantTextAggregation.BackgroundFilter { get; set; } - int? ISignificantTextAggregation.Size { get; set; } + IChiSquareHeuristic ISignificantTextAggregation.ChiSquare { get; set; } - int? ISignificantTextAggregation.ShardSize { get; set; } + SignificantTermsIncludeExclude ISignificantTextAggregation.Exclude { get; set; } - long? ISignificantTextAggregation.MinimumDocumentCount { get; set; } + TermsAggregationExecutionHint? ISignificantTextAggregation.ExecutionHint { get; set; } + Field ISignificantTextAggregation.Field { get; set; } - long? ISignificantTextAggregation.ShardMinimumDocumentCount { get; set; } + bool? ISignificantTextAggregation.FilterDuplicateText { get; set; } - TermsAggregationExecutionHint? ISignificantTextAggregation.ExecutionHint { get; set; } + IGoogleNormalizedDistanceHeuristic ISignificantTextAggregation.GoogleNormalizedDistance { get; set; } SignificantTermsIncludeExclude ISignificantTextAggregation.Include { get; set; } - SignificantTermsIncludeExclude ISignificantTextAggregation.Exclude { get; set; } + long? ISignificantTextAggregation.MinimumDocumentCount { get; set; } IMutualInformationHeuristic ISignificantTextAggregation.MutualInformation { get; set; } - IChiSquareHeuristic ISignificantTextAggregation.ChiSquare { get; set; } - - IGoogleNormalizedDistanceHeuristic ISignificantTextAggregation.GoogleNormalizedDistance { get; set; } - IPercentageScoreHeuristic ISignificantTextAggregation.PercentageScore { get; set; } IScriptedHeuristic ISignificantTextAggregation.Script { get; set; } - QueryContainer ISignificantTextAggregation.BackgroundFilter { get; set; } + long? ISignificantTextAggregation.ShardMinimumDocumentCount { get; set; } - bool? ISignificantTextAggregation.FilterDuplicateText { get; set; } + int? ISignificantTextAggregation.ShardSize { get; set; } + + int? ISignificantTextAggregation.Size { get; set; } Fields ISignificantTextAggregation.SourceFields { get; set; } - /// + /// public SignificantTextAggregationDescriptor Field(Field field) => Assign(a => a.Field = field); - /// + /// public SignificantTextAggregationDescriptor Field(Expression> field) => Assign(a => a.Field = field); - /// + /// public SignificantTextAggregationDescriptor Size(int? size) => Assign(a => a.Size = size); - /// + /// public SignificantTextAggregationDescriptor ExecutionHint(TermsAggregationExecutionHint? hint) => Assign(a => a.ExecutionHint = hint); - /// + /// public SignificantTextAggregationDescriptor Include(string includePattern) => Assign(a => a.Include = new SignificantTermsIncludeExclude(includePattern)); - /// + /// public SignificantTextAggregationDescriptor Include(IEnumerable values) => Assign(a => a.Include = new SignificantTermsIncludeExclude(values)); - /// + /// public SignificantTextAggregationDescriptor Exclude(string excludePattern) => Assign(a => a.Exclude = new SignificantTermsIncludeExclude(excludePattern)); - /// + /// public SignificantTextAggregationDescriptor Exclude(IEnumerable values) => Assign(a => a.Exclude = new SignificantTermsIncludeExclude(values)); - /// + /// public SignificantTextAggregationDescriptor ShardSize(int? shardSize) => Assign(a => a.ShardSize = shardSize); - /// + /// public SignificantTextAggregationDescriptor MinimumDocumentCount(long? minimumDocumentCount) => Assign(a => a.MinimumDocumentCount = minimumDocumentCount); - /// + /// public SignificantTextAggregationDescriptor ShardMinimumDocumentCount(long? shardMinimumDocumentCount) => Assign(a => a.ShardMinimumDocumentCount = shardMinimumDocumentCount); - /// - public SignificantTextAggregationDescriptor MutualInformation(Func mutualInformationSelector = null) => + /// + public SignificantTextAggregationDescriptor MutualInformation( + Func mutualInformationSelector = null + ) => Assign(a => a.MutualInformation = mutualInformationSelector.InvokeOrDefault(new MutualInformationHeuristicDescriptor())); - /// + /// public SignificantTextAggregationDescriptor ChiSquare(Func chiSquareSelector) => Assign(a => a.ChiSquare = chiSquareSelector.InvokeOrDefault(new ChiSquareHeuristicDescriptor())); - /// - public SignificantTextAggregationDescriptor GoogleNormalizedDistance(Func gndSelector) => + /// + public SignificantTextAggregationDescriptor GoogleNormalizedDistance( + Func gndSelector + ) => Assign(a => a.GoogleNormalizedDistance = gndSelector.InvokeOrDefault(new GoogleNormalizedDistanceHeuristicDescriptor())); - /// - public SignificantTextAggregationDescriptor PercentageScore(Func percentageScoreSelector) => + /// + public SignificantTextAggregationDescriptor PercentageScore( + Func percentageScoreSelector + ) => Assign(a => a.PercentageScore = percentageScoreSelector.InvokeOrDefault(new PercentageScoreHeuristicDescriptor())); - /// + /// public SignificantTextAggregationDescriptor Script(Func scriptSelector) => Assign(a => a.Script = scriptSelector?.Invoke(new ScriptedHeuristicDescriptor())); - /// + /// public SignificantTextAggregationDescriptor BackgroundFilter(Func, QueryContainer> selector) => Assign(a => a.BackgroundFilter = selector?.Invoke(new QueryContainerDescriptor())); - /// - public SignificantTextAggregationDescriptor FilterDuplicateText(bool? filterDuplicateText = true) => Assign(a => a.FilterDuplicateText = filterDuplicateText); + /// + public SignificantTextAggregationDescriptor FilterDuplicateText(bool? filterDuplicateText = true) => + Assign(a => a.FilterDuplicateText = filterDuplicateText); - /// + /// public SignificantTextAggregationDescriptor SourceFields(Func, IPromise> sourceFields) => Assign(a => a.SourceFields = sourceFields?.Invoke(new FieldsDescriptor())?.Value); - /// + /// public SignificantTextAggregationDescriptor SourceFields(Fields sourceFields) => Assign(a => a.SourceFields = sourceFields); - } } diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsAggregate.cs b/src/Nest/Aggregations/Bucket/Terms/TermsAggregate.cs index b88eb8e8c73..d177a1d3d40 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsAggregate.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsAggregate.cs @@ -1,9 +1,8 @@ namespace Nest { - public class TermsAggregate : MultiBucketAggregate> - { + public class TermsAggregate : MultiBucketAggregate> + { public long? DocCountErrorUpperBound { get; set; } public long? SumOtherDocCount { get; set; } - - } + } } diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsAggregation.cs b/src/Nest/Aggregations/Bucket/Terms/TermsAggregation.cs index aed0865f013..1b25292a56e 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsAggregation.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsAggregation.cs @@ -9,61 +9,61 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface ITermsAggregation : IBucketAggregation { - [JsonProperty("field")] - Field Field { get; set; } + [JsonProperty("collect_mode")] + TermsAggregationCollectMode? CollectMode { get; set; } - [JsonProperty("script")] - IScript Script { get; set; } + [JsonProperty("exclude")] + TermsExclude Exclude { get; set; } - [JsonProperty("size")] - int? Size { get; set; } + [JsonProperty("execution_hint")] + TermsAggregationExecutionHint? ExecutionHint { get; set; } - [JsonProperty("shard_size")] - int? ShardSize { get; set; } + [JsonProperty("field")] + Field Field { get; set; } + + [JsonProperty("include")] + TermsInclude Include { get; set; } [JsonProperty("min_doc_count")] int? MinimumDocumentCount { get; set; } - [JsonProperty("execution_hint")] - TermsAggregationExecutionHint? ExecutionHint { get; set; } + [JsonProperty("missing")] + object Missing { get; set; } [JsonProperty("order")] IList Order { get; set; } - [JsonProperty("include")] - TermsInclude Include { get; set; } - - [JsonProperty("exclude")] - TermsExclude Exclude { get; set; } + [JsonProperty("script")] + IScript Script { get; set; } - [JsonProperty("collect_mode")] - TermsAggregationCollectMode? CollectMode { get; set; } + [JsonProperty("shard_size")] + int? ShardSize { get; set; } [JsonProperty("show_term_doc_count_error")] bool? ShowTermDocCountError { get; set; } - [JsonProperty("missing")] - object Missing { get; set; } + [JsonProperty("size")] + int? Size { get; set; } } public class TermsAggregation : BucketAggregationBase, ITermsAggregation { - public Field Field { get; set; } - public IScript Script { get; set; } - public int? Size { get; set; } - public int? ShardSize { get; set; } - public int? MinimumDocumentCount { get; set; } + internal TermsAggregation() { } + + public TermsAggregation(string name) : base(name) { } + + public TermsAggregationCollectMode? CollectMode { get; set; } + public TermsExclude Exclude { get; set; } public TermsAggregationExecutionHint? ExecutionHint { get; set; } - public IList Order { get; set; } + public Field Field { get; set; } public TermsInclude Include { get; set; } - public TermsExclude Exclude { get; set; } - public TermsAggregationCollectMode? CollectMode { get; set; } + public int? MinimumDocumentCount { get; set; } public object Missing { get; set; } + public IList Order { get; set; } + public IScript Script { get; set; } + public int? ShardSize { get; set; } public bool? ShowTermDocCountError { get; set; } - - internal TermsAggregation() { } - - public TermsAggregation(string name) : base(name) { } + public int? Size { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.Terms = this; } @@ -72,30 +72,29 @@ public class TermsAggregationDescriptor : BucketAggregationDescriptorBase, ITermsAggregation, T>, ITermsAggregation where T : class { - Field ITermsAggregation.Field { get; set; } + TermsAggregationCollectMode? ITermsAggregation.CollectMode { get; set; } - IScript ITermsAggregation.Script { get; set; } + TermsExclude ITermsAggregation.Exclude { get; set; } - int? ITermsAggregation.Size { get; set; } + TermsAggregationExecutionHint? ITermsAggregation.ExecutionHint { get; set; } + Field ITermsAggregation.Field { get; set; } - int? ITermsAggregation.ShardSize { get; set; } + TermsInclude ITermsAggregation.Include { get; set; } int? ITermsAggregation.MinimumDocumentCount { get; set; } - TermsAggregationExecutionHint? ITermsAggregation.ExecutionHint { get; set; } + object ITermsAggregation.Missing { get; set; } IList ITermsAggregation.Order { get; set; } - TermsInclude ITermsAggregation.Include { get; set; } - - TermsExclude ITermsAggregation.Exclude { get; set; } - - TermsAggregationCollectMode? ITermsAggregation.CollectMode { get; set; } + IScript ITermsAggregation.Script { get; set; } - object ITermsAggregation.Missing { get; set; } + int? ITermsAggregation.ShardSize { get; set; } bool? ITermsAggregation.ShowTermDocCountError { get; set; } + int? ITermsAggregation.Size { get; set; } + public TermsAggregationDescriptor Field(Field field) => Assign(a => a.Field = field); public TermsAggregationDescriptor Field(Expression> field) => Assign(a => a.Field = field); @@ -138,6 +137,7 @@ public TermsAggregationDescriptor CollectMode(TermsAggregationCollectMode? co public TermsAggregationDescriptor Missing(object missing) => Assign(a => a.Missing = missing); - public TermsAggregationDescriptor ShowTermDocCountError(bool? showTermDocCountError = true) => Assign(a => a.ShowTermDocCountError = showTermDocCountError); + public TermsAggregationDescriptor ShowTermDocCountError(bool? showTermDocCountError = true) => + Assign(a => a.ShowTermDocCountError = showTermDocCountError); } } diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsAggregationCollectMode.cs b/src/Nest/Aggregations/Bucket/Terms/TermsAggregationCollectMode.cs index bc394690548..267d86a58ae 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsAggregationCollectMode.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsAggregationCollectMode.cs @@ -11,14 +11,15 @@ namespace Nest public enum TermsAggregationCollectMode { /// - /// Order by using field values directly in order to aggregate data per-bucket + /// Order by using field values directly in order to aggregate data per-bucket /// [EnumMember(Value = "depth_first")] DepthFirst, + /// /// Order by using ordinals of the field values instead of the values themselves /// [EnumMember(Value = "breadth_first")] BreadthFirst } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsAggregationExecutionHint.cs b/src/Nest/Aggregations/Bucket/Terms/TermsAggregationExecutionHint.cs index 533ccfc14f9..146d353040d 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsAggregationExecutionHint.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsAggregationExecutionHint.cs @@ -11,24 +11,27 @@ namespace Nest public enum TermsAggregationExecutionHint { /// - /// Order by using field values directly in order to aggregate data per-bucket + /// Order by using field values directly in order to aggregate data per-bucket /// [EnumMember(Value = "map")] Map, + /// /// Order by using ordinals of the field and preemptively allocating one bucket per ordinal value /// [EnumMember(Value = "global_ordinals")] GlobalOrdinals, + /// /// Order by using ordinals of the field and dynamically allocating one bucket per ordinal value /// [EnumMember(Value = "global_ordinals_hash")] GlobalOrdinalsHash, + /// /// Order by using per-segment ordinals to compute counts and remap these counts to global counts using global ordinals /// [EnumMember(Value = "global_ordinals_low_cardinality")] GlobalOrdinalsLowCardinality } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsExclude.cs b/src/Nest/Aggregations/Bucket/Terms/TermsExclude.cs index 08a4d530eee..e22a7111c76 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsExclude.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsExclude.cs @@ -10,29 +10,29 @@ namespace Nest public class TermsExclude { /// - /// The regular expression pattern to determine terms to exclude from the response - /// - [JsonIgnore] - public string Pattern { get; set; } - - /// - /// Collection of terms to exclude from the response - /// - [JsonIgnore] - public IEnumerable Values { get; set; } - - /// - /// Creates an instance of that uses a regular expression pattern + /// Creates an instance of that uses a regular expression pattern /// to determine the terms to exclude from the response /// /// The regular expression pattern public TermsExclude(string pattern) => Pattern = pattern; /// - /// Creates an instance of that uses a collection of terms + /// Creates an instance of that uses a collection of terms /// to exclude from the response /// /// The exact terms to exclude public TermsExclude(IEnumerable values) => Values = values; + + /// + /// The regular expression pattern to determine terms to exclude from the response + /// + [JsonIgnore] + public string Pattern { get; set; } + + /// + /// Collection of terms to exclude from the response + /// + [JsonIgnore] + public IEnumerable Values { get; set; } } } diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsExcludeJsonConverter.cs b/src/Nest/Aggregations/Bucket/Terms/TermsExcludeJsonConverter.cs index a000ba4bf46..9dbf85881f4 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsExcludeJsonConverter.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsExcludeJsonConverter.cs @@ -40,4 +40,4 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s writer.WriteValue(termsExclude.Pattern); } } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsInclude.cs b/src/Nest/Aggregations/Bucket/Terms/TermsInclude.cs index b036181c26b..702da055ec4 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsInclude.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsInclude.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using Newtonsoft.Json; @@ -11,22 +10,30 @@ namespace Nest public class TermsInclude { /// - /// The regular expression pattern to determine terms to include in the response + /// Creates an instance of that uses a regular expression pattern + /// to determine the terms to include in the response /// - [JsonIgnore] - public string Pattern { get; set; } + /// The regular expression pattern + public TermsInclude(string pattern) => Pattern = pattern; /// - /// Collection of terms to include in the response + /// Creates an instance of that uses a collection of terms + /// to include in the response /// - [JsonIgnore] - public IEnumerable Values { get; set; } + /// The exact terms to include + public TermsInclude(IEnumerable values) => Values = values; /// - /// The current partition of terms we are interested in + /// Creates an instance of that partitions the terms into a number of + /// partitions to receive in multiple requests. Used to process many unique terms /// - [JsonProperty("partition")] - public long? Partition { get; set; } + /// The 0-based partition number for this request + /// The total number of partitions + public TermsInclude(long partition, long numberOfPartitions) + { + Partition = partition; + NumberOfPartitions = numberOfPartitions; + } /// /// The total number of paritions we are interested in @@ -35,29 +42,21 @@ public class TermsInclude public long? NumberOfPartitions { get; set; } /// - /// Creates an instance of that uses a regular expression pattern - /// to determine the terms to include in the response + /// The current partition of terms we are interested in /// - /// The regular expression pattern - public TermsInclude(string pattern) => Pattern = pattern; + [JsonProperty("partition")] + public long? Partition { get; set; } /// - /// Creates an instance of that uses a collection of terms - /// to include in the response + /// The regular expression pattern to determine terms to include in the response /// - /// The exact terms to include - public TermsInclude(IEnumerable values) => Values = values; + [JsonIgnore] + public string Pattern { get; set; } /// - /// Creates an instance of that partitions the terms into a number of - /// partitions to receive in multiple requests. Used to process many unique terms + /// Collection of terms to include in the response /// - /// The 0-based partition number for this request - /// The total number of partitions - public TermsInclude(long partition, long numberOfPartitions) - { - Partition = partition; - NumberOfPartitions = numberOfPartitions; - } + [JsonIgnore] + public IEnumerable Values { get; set; } } } diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsIncludeJsonConverter.cs b/src/Nest/Aggregations/Bucket/Terms/TermsIncludeJsonConverter.cs index 7ce678ef75f..4fa3742f50a 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsIncludeJsonConverter.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsIncludeJsonConverter.cs @@ -16,7 +16,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist switch (reader.TokenType) { case JsonToken.StartArray: - termsInclude =new TermsInclude(serializer.Deserialize>(reader)); + termsInclude = new TermsInclude(serializer.Deserialize>(reader)); break; case JsonToken.StartObject: long partition = 0; diff --git a/src/Nest/Aggregations/Bucket/Terms/TermsOrder.cs b/src/Nest/Aggregations/Bucket/Terms/TermsOrder.cs index b7d77b6c66d..bced94033ce 100644 --- a/src/Nest/Aggregations/Bucket/Terms/TermsOrder.cs +++ b/src/Nest/Aggregations/Bucket/Terms/TermsOrder.cs @@ -6,16 +6,17 @@ namespace Nest [JsonConverter(typeof(KeyValueJsonConverter))] public class TermsOrder { + public static TermsOrder CountAscending => new TermsOrder { Key = "_count", Order = SortOrder.Ascending }; + public static TermsOrder CountDescending => new TermsOrder { Key = "_count", Order = SortOrder.Descending }; public string Key { get; set; } + public static TermsOrder KeyAscending => new TermsOrder { Key = "_key", Order = SortOrder.Ascending }; + public static TermsOrder KeyDescending => new TermsOrder { Key = "_key", Order = SortOrder.Descending }; public SortOrder Order { get; set; } - public static TermsOrder CountAscending => new TermsOrder { Key = "_count", Order = SortOrder.Ascending }; - public static TermsOrder CountDescending => new TermsOrder { Key = "_count", Order = SortOrder.Descending }; [Obsolete("Deprecated in Elasticsearch 6.0. Use KeyAscending")] public static TermsOrder TermAscending => new TermsOrder { Key = "_key", Order = SortOrder.Ascending }; + [Obsolete("Deprecated in Elasticsearch 6.0. Use KeyDescending")] public static TermsOrder TermDescending => new TermsOrder { Key = "_key", Order = SortOrder.Descending }; - public static TermsOrder KeyAscending => new TermsOrder { Key = "_key", Order = SortOrder.Ascending }; - public static TermsOrder KeyDescending => new TermsOrder { Key = "_key", Order = SortOrder.Descending }; } } diff --git a/src/Nest/Aggregations/Matrix/MatrixAggregate.cs b/src/Nest/Aggregations/Matrix/MatrixAggregate.cs index a00055ff240..5673a6e2ba2 100644 --- a/src/Nest/Aggregations/Matrix/MatrixAggregate.cs +++ b/src/Nest/Aggregations/Matrix/MatrixAggregate.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Nest { diff --git a/src/Nest/Aggregations/Matrix/MatrixAggregation.cs b/src/Nest/Aggregations/Matrix/MatrixAggregation.cs index 7e83e05c6c2..d34ce5f4f13 100644 --- a/src/Nest/Aggregations/Matrix/MatrixAggregation.cs +++ b/src/Nest/Aggregations/Matrix/MatrixAggregation.cs @@ -1,10 +1,6 @@ -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Threading.Tasks; +using Newtonsoft.Json; namespace Nest { @@ -21,10 +17,7 @@ public abstract class MatrixAggregationBase : AggregationBase, IMatrixAggregatio { internal MatrixAggregationBase() { } - protected MatrixAggregationBase(string name, Fields field) : base(name) - { - this.Fields = field; - } + protected MatrixAggregationBase(string name, Fields field) : base(name) => Fields = field; public Fields Fields { get; set; } diff --git a/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsAggregate.cs b/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsAggregate.cs index edab5fa89be..db8c28b0fc5 100644 --- a/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsAggregate.cs +++ b/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsAggregate.cs @@ -1,40 +1,34 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Nest { - [JsonObject] public class MatrixStatsField { - [JsonProperty("name")] - public string Name { get; set; } + [JsonProperty("correlation")] + public Dictionary Correlation { get; set; } [JsonProperty("count")] public int Count { get; set; } + [JsonProperty("covariance")] + public Dictionary Covariance { get; set; } + + [JsonProperty("kurtosis")] + public double Kurtosis { get; set; } + [JsonProperty("mean")] public double Mean { get; set; } - [JsonProperty("variance")] - public double Variance { get; set; } + [JsonProperty("name")] + public string Name { get; set; } [JsonProperty("skewness")] public double Skewness { get; set; } - [JsonProperty("kurtosis")] - public double Kurtosis { get; set; } - - [JsonProperty("covariance")] - public Dictionary Covariance { get; set; } - - [JsonProperty("correlation")] - public Dictionary Correlation { get; set; } - + [JsonProperty("variance")] + public double Variance { get; set; } } [JsonObject] diff --git a/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsAggregation.cs b/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsAggregation.cs index 06e550d8f5c..6d9641e51e1 100644 --- a/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsAggregation.cs +++ b/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsAggregation.cs @@ -1,9 +1,4 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Nest { @@ -28,7 +23,7 @@ public MatrixStatsAggregation(string name, Fields fields) : base(name, fields) { public class MatrixStatsAggregationDescriptor : MatrixAggregationDescriptorBase, IMatrixStatsAggregation, T> - , IMatrixStatsAggregation + , IMatrixStatsAggregation where T : class { MatrixStatsMode? IMatrixStatsAggregation.Mode { get; set; } diff --git a/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsMode.cs b/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsMode.cs index 659b57837f9..9dd08161a70 100644 --- a/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsMode.cs +++ b/src/Nest/Aggregations/Matrix/MatrixStats/MatrixStatsMode.cs @@ -1,11 +1,6 @@ -using Newtonsoft.Json; +using System.Runtime.Serialization; +using Newtonsoft.Json; using Newtonsoft.Json.Converters; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; namespace Nest { @@ -22,21 +17,25 @@ public enum MatrixStatsMode /// [EnumMember(Value = "avg")] Avg, + /// /// Pick the lowest value. /// [EnumMember(Value = "min")] Min, + /// - /// Pick the highest value. + /// Pick the highest value. /// [EnumMember(Value = "max")] Max, + /// /// Use the sum of all values. /// [EnumMember(Value = "sum")] Sum, + /// /// Use the median of all values. /// diff --git a/src/Nest/Aggregations/Metric/Average/AverageAggregation.cs b/src/Nest/Aggregations/Metric/Average/AverageAggregation.cs index 08e77057a23..2539eba4cb1 100644 --- a/src/Nest/Aggregations/Metric/Average/AverageAggregation.cs +++ b/src/Nest/Aggregations/Metric/Average/AverageAggregation.cs @@ -15,8 +15,8 @@ public AverageAggregation(string name, Field field) : base(name, field) { } internal override void WrapInContainer(AggregationContainer c) => c.Average = this; } - public class AverageAggregationDescriptor + public class AverageAggregationDescriptor : MetricAggregationDescriptorBase, IAverageAggregation, T> - , IAverageAggregation + , IAverageAggregation where T : class { } } diff --git a/src/Nest/Aggregations/Metric/Cardinality/CardinalityAggregation.cs b/src/Nest/Aggregations/Metric/Cardinality/CardinalityAggregation.cs index 885a2ea1597..0338ac4a68d 100644 --- a/src/Nest/Aggregations/Metric/Cardinality/CardinalityAggregation.cs +++ b/src/Nest/Aggregations/Metric/Cardinality/CardinalityAggregation.cs @@ -15,13 +15,13 @@ public interface ICardinalityAggregation : IMetricAggregation public class CardinalityAggregation : MetricAggregationBase, ICardinalityAggregation { - public int? PrecisionThreshold { get; set; } - public bool? Rehash { get; set; } - internal CardinalityAggregation() { } public CardinalityAggregation(string name, Field field) : base(name, field) { } + public int? PrecisionThreshold { get; set; } + public bool? Rehash { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.Cardinality = this; } @@ -38,6 +38,5 @@ public CardinalityAggregationDescriptor PrecisionThreshold(int? precisionThre => Assign(a => a.PrecisionThreshold = precisionThreshold); public CardinalityAggregationDescriptor Rehash(bool? rehash = true) => Assign(a => a.Rehash = rehash); - } } diff --git a/src/Nest/Aggregations/Metric/ExtendedStats/ExtendedStatsAggregate.cs b/src/Nest/Aggregations/Metric/ExtendedStats/ExtendedStatsAggregate.cs index 8945ccf3b1e..fdec3f71267 100644 --- a/src/Nest/Aggregations/Metric/ExtendedStats/ExtendedStatsAggregate.cs +++ b/src/Nest/Aggregations/Metric/ExtendedStats/ExtendedStatsAggregate.cs @@ -2,20 +2,20 @@ { public class ExtendedStatsAggregate : MetricAggregateBase { + public double? Average { get; set; } public long Count { get; set; } - public double? Min { get; set; } public double? Max { get; set; } - public double? Average { get; set; } + public double? Min { get; set; } + public double? StdDeviation { get; set; } + public StandardDeviationBounds StdDeviationBounds { get; set; } public double? Sum { get; set; } public double? SumOfSquares { get; set; } public double? Variance { get; set; } - public double? StdDeviation { get; set; } - public StandardDeviationBounds StdDeviationBounds { get; set; } } public class StandardDeviationBounds { - public double? Upper { get; set; } public double? Lower { get; set; } + public double? Upper { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsAggregate.cs b/src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsAggregate.cs index 9fde9789ed0..3aee6736de4 100644 --- a/src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsAggregate.cs +++ b/src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsAggregate.cs @@ -2,17 +2,14 @@ { public class GeoBoundsAggregate : MetricAggregateBase { - public GeoBoundsAggregate() - { - Bounds = new GeoBounds(); - } + public GeoBoundsAggregate() => Bounds = new GeoBounds(); public GeoBounds Bounds { get; set; } } public class GeoBounds { - public LatLon TopLeft { get; set; } public LatLon BottomRight { get; set; } + public LatLon TopLeft { get; set; } } } diff --git a/src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsAggregation.cs b/src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsAggregation.cs index 5393c6f5f74..6ea24ed1e6e 100644 --- a/src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsAggregation.cs +++ b/src/Nest/Aggregations/Metric/GeoBounds/GeoBoundsAggregation.cs @@ -12,12 +12,12 @@ public interface IGeoBoundsAggregation : IMetricAggregation public class GeoBoundsAggregation : MetricAggregationBase, IGeoBoundsAggregation { - public bool? WrapLongitude { get; set; } - internal GeoBoundsAggregation() { } public GeoBoundsAggregation(string name, Field field) : base(name, field) { } + public bool? WrapLongitude { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.GeoBounds = this; } diff --git a/src/Nest/Aggregations/Metric/GeoCentroid/GeoCentroidAggregate.cs b/src/Nest/Aggregations/Metric/GeoCentroid/GeoCentroidAggregate.cs index 079f967607c..fbbf81a39cf 100644 --- a/src/Nest/Aggregations/Metric/GeoCentroid/GeoCentroidAggregate.cs +++ b/src/Nest/Aggregations/Metric/GeoCentroid/GeoCentroidAggregate.cs @@ -4,9 +4,10 @@ namespace Nest { public class GeoCentroidAggregate : MetricAggregateBase { - [JsonProperty("location")] - public GeoLocation Location { get; set; } [JsonProperty("count")] public long Count { get; set; } + + [JsonProperty("location")] + public GeoLocation Location { get; set; } } } diff --git a/src/Nest/Aggregations/Metric/GeoCentroid/GeoCentroidAggregation.cs b/src/Nest/Aggregations/Metric/GeoCentroid/GeoCentroidAggregation.cs index 43ef8ee3ca8..d653ea65313 100644 --- a/src/Nest/Aggregations/Metric/GeoCentroid/GeoCentroidAggregation.cs +++ b/src/Nest/Aggregations/Metric/GeoCentroid/GeoCentroidAggregation.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -23,7 +18,5 @@ public GeoCentroidAggregation(string name, Field field) : base(name, field) { } public class GeoCentroidAggregationDescriptor : MetricAggregationDescriptorBase, IGeoCentroidAggregation, T> , IGeoCentroidAggregation - where T : class - { - } + where T : class { } } diff --git a/src/Nest/Aggregations/Metric/Max/MaxAggregation.cs b/src/Nest/Aggregations/Metric/Max/MaxAggregation.cs index 5cf419108a4..5b9599a4715 100644 --- a/src/Nest/Aggregations/Metric/Max/MaxAggregation.cs +++ b/src/Nest/Aggregations/Metric/Max/MaxAggregation.cs @@ -15,8 +15,8 @@ public MaxAggregation(string name, Field field) : base(name, field) { } internal override void WrapInContainer(AggregationContainer c) => c.Max = this; } - public class MaxAggregationDescriptor + public class MaxAggregationDescriptor : MetricAggregationDescriptorBase, IMaxAggregation, T> - , IMaxAggregation + , IMaxAggregation where T : class { } } diff --git a/src/Nest/Aggregations/Metric/MetricAggregate.cs b/src/Nest/Aggregations/Metric/MetricAggregate.cs index ef6b67b8fba..81d5b53e8b0 100644 --- a/src/Nest/Aggregations/Metric/MetricAggregate.cs +++ b/src/Nest/Aggregations/Metric/MetricAggregate.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Nest @@ -7,6 +6,6 @@ namespace Nest public abstract class MetricAggregateBase : IAggregate { [JsonProperty("meta")] - public IReadOnlyDictionary Meta { get; set; } = EmptyReadOnly.Dictionary; + public IReadOnlyDictionary Meta { get; set; } = EmptyReadOnly.Dictionary; } } diff --git a/src/Nest/Aggregations/Metric/MetricAggregation.cs b/src/Nest/Aggregations/Metric/MetricAggregation.cs index eb429e81b02..d8141e0748b 100644 --- a/src/Nest/Aggregations/Metric/MetricAggregation.cs +++ b/src/Nest/Aggregations/Metric/MetricAggregation.cs @@ -10,40 +10,40 @@ public interface IMetricAggregation : IAggregation [JsonProperty("field")] Field Field { get; set; } - [JsonProperty("script")] - IScript Script { get; set; } - [JsonProperty("missing")] double? Missing { get; set; } + + [JsonProperty("script")] + IScript Script { get; set; } } public abstract class MetricAggregationBase : AggregationBase, IMetricAggregation { internal MetricAggregationBase() { } - protected MetricAggregationBase(string name, Field field) : base(name) => this.Field = field; + protected MetricAggregationBase(string name, Field field) : base(name) => Field = field; public Field Field { get; set; } - public virtual IScript Script { get; set; } public double? Missing { get; set; } + public virtual IScript Script { get; set; } } public abstract class MetricAggregationDescriptorBase - : DescriptorBase, IMetricAggregation + : DescriptorBase, IMetricAggregation where TMetricAggregation : MetricAggregationDescriptorBase - , TMetricAggregationInterface, IMetricAggregation + , TMetricAggregationInterface, IMetricAggregation where T : class where TMetricAggregationInterface : class, IMetricAggregation { Field IMetricAggregation.Field { get; set; } - IScript IMetricAggregation.Script { get; set; } + IDictionary IAggregation.Meta { get; set; } double? IMetricAggregation.Missing { get; set; } string IAggregation.Name { get; set; } - IDictionary IAggregation.Meta { get; set; } + IScript IMetricAggregation.Script { get; set; } public TMetricAggregation Field(Field field) => Assign(a => a.Field = field); diff --git a/src/Nest/Aggregations/Metric/Min/MinAggregation.cs b/src/Nest/Aggregations/Metric/Min/MinAggregation.cs index 39e5545979d..bd804f481d3 100644 --- a/src/Nest/Aggregations/Metric/Min/MinAggregation.cs +++ b/src/Nest/Aggregations/Metric/Min/MinAggregation.cs @@ -15,8 +15,8 @@ public MinAggregation(string name, Field field) : base(name, field) { } internal override void WrapInContainer(AggregationContainer c) => c.Min = this; } - public class MinAggregationDescriptor + public class MinAggregationDescriptor : MetricAggregationDescriptorBase, IMinAggregation, T> - , IMinAggregation + , IMinAggregation where T : class { } } diff --git a/src/Nest/Aggregations/Metric/PercentileRanks/PercentileRanksAggregation.cs b/src/Nest/Aggregations/Metric/PercentileRanks/PercentileRanksAggregation.cs index 496af2553a2..fc26bf8b125 100644 --- a/src/Nest/Aggregations/Metric/PercentileRanks/PercentileRanksAggregation.cs +++ b/src/Nest/Aggregations/Metric/PercentileRanks/PercentileRanksAggregation.cs @@ -7,29 +7,28 @@ namespace Nest [ContractJsonConverter(typeof(PercentileRanksAggregationJsonConverter))] public interface IPercentileRanksAggregation : IMetricAggregation { - IEnumerable Values { get; set; } IPercentilesMethod Method { get; set; } + IEnumerable Values { get; set; } } public class PercentileRanksAggregation : MetricAggregationBase, IPercentileRanksAggregation { - public IEnumerable Values { get; set; } - public IPercentilesMethod Method { get; set; } - internal PercentileRanksAggregation() { } public PercentileRanksAggregation(string name, Field field) : base(name, field) { } + public IPercentilesMethod Method { get; set; } + public IEnumerable Values { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.PercentileRanks = this; } - public class PercentileRanksAggregationDescriptor + public class PercentileRanksAggregationDescriptor : MetricAggregationDescriptorBase, IPercentileRanksAggregation, T>, IPercentileRanksAggregation where T : class { - IEnumerable IPercentileRanksAggregation.Values { get; set; } - IPercentilesMethod IPercentileRanksAggregation.Method { get; set; } + IEnumerable IPercentileRanksAggregation.Values { get; set; } public PercentileRanksAggregationDescriptor Values(IEnumerable values) => Assign(a => a.Values = values?.ToList()); diff --git a/src/Nest/Aggregations/Metric/PercentileRanks/PercentileRanksAggregationJsonConverter.cs b/src/Nest/Aggregations/Metric/PercentileRanks/PercentileRanksAggregationJsonConverter.cs index 72b15201678..cc3546fcc2f 100644 --- a/src/Nest/Aggregations/Metric/PercentileRanks/PercentileRanksAggregationJsonConverter.cs +++ b/src/Nest/Aggregations/Metric/PercentileRanks/PercentileRanksAggregationJsonConverter.cs @@ -19,13 +19,16 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist percentileRanks.Method = ReadMethodProperty(properties); if (properties.ContainsKey("values")) percentileRanks.Values = properties["values"].ToObject>(); - return percentileRanks;; + return percentileRanks; + + ; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var percentileRanks = value as IPercentileRanksAggregation; if (percentileRanks == null) return; + writer.WriteStartObject(); WriteMetricProperties(percentileRanks, writer, serializer); if (percentileRanks.Values != null) diff --git a/src/Nest/Aggregations/Metric/Percentiles/PercentilesAggregation.cs b/src/Nest/Aggregations/Metric/Percentiles/PercentilesAggregation.cs index 886c0c5c2d7..4ad15f7cfa3 100644 --- a/src/Nest/Aggregations/Metric/Percentiles/PercentilesAggregation.cs +++ b/src/Nest/Aggregations/Metric/Percentiles/PercentilesAggregation.cs @@ -7,38 +7,37 @@ namespace Nest [ContractJsonConverter(typeof(PercentilesAggregationJsonConverter))] public interface IPercentilesAggregation : IMetricAggregation { - IEnumerable Percents { get; set; } IPercentilesMethod Method { get; set; } + IEnumerable Percents { get; set; } } public class PercentilesAggregation : MetricAggregationBase, IPercentilesAggregation { - public IEnumerable Percents { get; set; } - public IPercentilesMethod Method { get; set; } - internal PercentilesAggregation() { } - public PercentilesAggregation(string name, Field field) : base(name, field) { } + public PercentilesAggregation(string name, Field field) : base(name, field) { } + + public IPercentilesMethod Method { get; set; } + public IEnumerable Percents { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.Percentiles = this; } - public class PercentilesAggregationDescriptor + public class PercentilesAggregationDescriptor : MetricAggregationDescriptorBase, IPercentilesAggregation, T> - , IPercentilesAggregation + , IPercentilesAggregation where T : class { - IEnumerable IPercentilesAggregation.Percents { get; set; } - IPercentilesMethod IPercentilesAggregation.Method { get; set; } + IEnumerable IPercentilesAggregation.Percents { get; set; } - public PercentilesAggregationDescriptor Percents(IEnumerable percentages) => + public PercentilesAggregationDescriptor Percents(IEnumerable percentages) => Assign(a => a.Percents = percentages?.ToList()); - public PercentilesAggregationDescriptor Percents(params double[] percentages) => + public PercentilesAggregationDescriptor Percents(params double[] percentages) => Assign(a => a.Percents = percentages?.ToList()); - public PercentilesAggregationDescriptor Method(Func methodSelector) => + public PercentilesAggregationDescriptor Method(Func methodSelector) => Assign(a => a.Method = methodSelector?.Invoke(new PercentilesMethodDescriptor())); } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Metric/Percentiles/PercentilesAggregationJsonConverter.cs b/src/Nest/Aggregations/Metric/Percentiles/PercentilesAggregationJsonConverter.cs index aed0f3b634a..457bda12d8f 100644 --- a/src/Nest/Aggregations/Metric/Percentiles/PercentilesAggregationJsonConverter.cs +++ b/src/Nest/Aggregations/Metric/Percentiles/PercentilesAggregationJsonConverter.cs @@ -54,6 +54,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s { var percentiles = value as IPercentilesAggregation; if (percentiles == null) return; + writer.WriteStartObject(); WriteMetricProperties(percentiles, writer, serializer); if (percentiles.Percents != null) @@ -98,7 +99,6 @@ protected void WriteMethodProperty(IPercentilesMethod method, JsonWriter writer, protected void WriteMetricProperties(IMetricAggregation metric, JsonWriter writer, JsonSerializer serializer) { - if (metric.Field != null) { var settings = serializer.GetConnectionSettings(); diff --git a/src/Nest/Aggregations/Metric/Percentiles/PercentilesMetricAggregate.cs b/src/Nest/Aggregations/Metric/Percentiles/PercentilesMetricAggregate.cs index 044418220b6..d50b0e75b78 100644 --- a/src/Nest/Aggregations/Metric/Percentiles/PercentilesMetricAggregate.cs +++ b/src/Nest/Aggregations/Metric/Percentiles/PercentilesMetricAggregate.cs @@ -2,7 +2,6 @@ namespace Nest { - public class PercentileItem { public double Percentile { get; internal set; } @@ -13,4 +12,4 @@ public class PercentilesAggregate : MetricAggregateBase { public IList Items { get; internal set; } = new List(); } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Metric/ScriptedMetric/ScriptedMetricAggregate.cs b/src/Nest/Aggregations/Metric/ScriptedMetric/ScriptedMetricAggregate.cs index 097b26e8493..fe9e9c88697 100644 --- a/src/Nest/Aggregations/Metric/ScriptedMetric/ScriptedMetricAggregate.cs +++ b/src/Nest/Aggregations/Metric/ScriptedMetric/ScriptedMetricAggregate.cs @@ -1,24 +1,21 @@ - -using System; -using Newtonsoft.Json.Linq; +using System; namespace Nest { public class ScriptedMetricAggregate : MetricAggregateBase { private readonly object _value; + internal ScriptedMetricAggregate(object value) => _value = value; + public ScriptedMetricAggregate() { } /// /// Get the result of the scripted metric aggregation as T /// /// The type that best represents the result of your scripted metric aggrgation - public T Value() - { - return this._value is LazyDocument lazyDocument - ? lazyDocument.As() - : (T)Convert.ChangeType(this._value, typeof(T)); - } + public T Value() => _value is LazyDocument lazyDocument + ? lazyDocument.As() + : (T)Convert.ChangeType(_value, typeof(T)); } } diff --git a/src/Nest/Aggregations/Metric/ScriptedMetric/ScriptedMetricAggregation.cs b/src/Nest/Aggregations/Metric/ScriptedMetric/ScriptedMetricAggregation.cs index 4462e7fb1d3..c458c49161c 100644 --- a/src/Nest/Aggregations/Metric/ScriptedMetric/ScriptedMetricAggregation.cs +++ b/src/Nest/Aggregations/Metric/ScriptedMetric/ScriptedMetricAggregation.cs @@ -8,64 +8,70 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IScriptedMetricAggregation : IMetricAggregation { + [JsonProperty("combine_script")] + IScript CombineScript { get; set; } + [JsonProperty("init_script")] IScript InitScript { get; set; } - + [JsonProperty("map_script")] IScript MapScript { get; set; } - [JsonProperty("combine_script")] - IScript CombineScript { get; set; } + [JsonProperty("params")] + IDictionary Params { get; set; } [JsonProperty("reduce_script")] IScript ReduceScript { get; set; } - - [JsonProperty("params")] - IDictionary Params { get; set; } } public class ScriptedMetricAggregation : MetricAggregationBase, IScriptedMetricAggregation { - public IScript InitScript { get; set; } - public IScript MapScript { get; set; } - public IScript CombineScript { get; set; } - public IScript ReduceScript { get; set; } - public IDictionary Params { get; set; } - internal ScriptedMetricAggregation() { } public ScriptedMetricAggregation(string name) : base(name, null) { } + public IScript CombineScript { get; set; } + public IScript InitScript { get; set; } + public IScript MapScript { get; set; } + public IDictionary Params { get; set; } + public IScript ReduceScript { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.ScriptedMetric = this; } + public class ScriptedMetricAggregationDescriptor : MetricAggregationDescriptorBase, IScriptedMetricAggregation, T> - , IScriptedMetricAggregation + , IScriptedMetricAggregation where T : class { + IScript IScriptedMetricAggregation.CombineScript { get; set; } IScript IScriptedMetricAggregation.InitScript { get; set; } IScript IScriptedMetricAggregation.MapScript { get; set; } - IScript IScriptedMetricAggregation.CombineScript { get; set; } - IScript IScriptedMetricAggregation.ReduceScript { get; set; } IDictionary IScriptedMetricAggregation.Params { get; set; } + IScript IScriptedMetricAggregation.ReduceScript { get; set; } public ScriptedMetricAggregationDescriptor InitScript(string script) => Assign(a => a.InitScript = (InlineScript)script); - public ScriptedMetricAggregationDescriptor InitScript(Func scriptSelector) => + + public ScriptedMetricAggregationDescriptor InitScript(Func scriptSelector) => Assign(a => a.InitScript = scriptSelector?.Invoke(new ScriptDescriptor())); public ScriptedMetricAggregationDescriptor MapScript(string script) => Assign(a => a.MapScript = (InlineScript)script); - public ScriptedMetricAggregationDescriptor MapScript(Func scriptSelector) => + + public ScriptedMetricAggregationDescriptor MapScript(Func scriptSelector) => Assign(a => a.MapScript = scriptSelector?.Invoke(new ScriptDescriptor())); public ScriptedMetricAggregationDescriptor CombineScript(string script) => Assign(a => a.CombineScript = (InlineScript)script); - public ScriptedMetricAggregationDescriptor CombineScript(Func scriptSelector) => + + public ScriptedMetricAggregationDescriptor CombineScript(Func scriptSelector) => Assign(a => a.CombineScript = scriptSelector?.Invoke(new ScriptDescriptor())); public ScriptedMetricAggregationDescriptor ReduceScript(string script) => Assign(a => a.ReduceScript = (InlineScript)script); - public ScriptedMetricAggregationDescriptor ReduceScript(Func scriptSelector) => + + public ScriptedMetricAggregationDescriptor ReduceScript(Func scriptSelector) => Assign(a => a.ReduceScript = scriptSelector?.Invoke(new ScriptDescriptor())); - public ScriptedMetricAggregationDescriptor Params(Func, FluentDictionary> paramSelector) => - Assign(a => a.Params = paramSelector?.Invoke(new FluentDictionary())); + public ScriptedMetricAggregationDescriptor + Params(Func, FluentDictionary> paramSelector) => + Assign(a => a.Params = paramSelector?.Invoke(new FluentDictionary())); } } diff --git a/src/Nest/Aggregations/Metric/Stats/StatsAggregate.cs b/src/Nest/Aggregations/Metric/Stats/StatsAggregate.cs index 84eb9d6c805..33eff2af25c 100644 --- a/src/Nest/Aggregations/Metric/Stats/StatsAggregate.cs +++ b/src/Nest/Aggregations/Metric/Stats/StatsAggregate.cs @@ -2,10 +2,10 @@ { public class StatsAggregate : MetricAggregateBase { + public double? Average { get; set; } public long Count { get; set; } - public double? Min { get; set; } public double? Max { get; set; } - public double? Average { get; set; } + public double? Min { get; set; } public double? Sum { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Metric/Sum/SumAggregation.cs b/src/Nest/Aggregations/Metric/Sum/SumAggregation.cs index c55dc191a35..148928447cd 100644 --- a/src/Nest/Aggregations/Metric/Sum/SumAggregation.cs +++ b/src/Nest/Aggregations/Metric/Sum/SumAggregation.cs @@ -15,8 +15,8 @@ public SumAggregation(string name, Field field) : base(name, field) { } internal override void WrapInContainer(AggregationContainer c) => c.Sum = this; } - public class SumAggregationDescriptor + public class SumAggregationDescriptor : MetricAggregationDescriptorBase, ISumAggregation, T> - , ISumAggregation + , ISumAggregation where T : class { } } diff --git a/src/Nest/Aggregations/Metric/TopHits/TopHitsAggregate.cs b/src/Nest/Aggregations/Metric/TopHits/TopHitsAggregate.cs index 1050b9130fa..31cc245237f 100644 --- a/src/Nest/Aggregations/Metric/TopHits/TopHitsAggregate.cs +++ b/src/Nest/Aggregations/Metric/TopHits/TopHitsAggregate.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Nest { @@ -9,25 +7,22 @@ public class TopHitsAggregate : MetricAggregateBase { private readonly IList _hits; - public long Total { get; set; } + public TopHitsAggregate() { } - public double? MaxScore { get; set; } + internal TopHitsAggregate(IList hits) => _hits = hits; - public TopHitsAggregate() { } + public double? MaxScore { get; set; } - internal TopHitsAggregate(IList hits) - { - _hits = hits; - } + public long Total { get; set; } private IEnumerable> ConvertHits() where TDocument : class => _hits.Select(h => h.As>()); public IReadOnlyCollection> Hits() where TDocument : class => - this.ConvertHits().ToList().AsReadOnly(); + ConvertHits().ToList().AsReadOnly(); public IReadOnlyCollection Documents() where TDocument : class => - this.ConvertHits().Select(h => h.Source).ToList().AsReadOnly(); + ConvertHits().Select(h => h.Source).ToList().AsReadOnly(); } } diff --git a/src/Nest/Aggregations/Metric/TopHits/TopHitsAggregation.cs b/src/Nest/Aggregations/Metric/TopHits/TopHitsAggregation.cs index 9ec0eba2196..2575cbdd36e 100644 --- a/src/Nest/Aggregations/Metric/TopHits/TopHitsAggregation.cs +++ b/src/Nest/Aggregations/Metric/TopHits/TopHitsAggregation.cs @@ -8,9 +8,22 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface ITopHitsAggregation : IMetricAggregation { + [JsonProperty("docvalue_fields")] + Fields DocValueFields { get; set; } + + [JsonProperty("explain")] + bool? Explain { get; set; } + [JsonProperty("from")] int? From { get; set; } + [JsonProperty("highlight")] + IHighlight Highlight { get; set; } + + [JsonProperty("script_fields")] + [JsonConverter(typeof(ReadAsTypeJsonConverter))] + IScriptFields ScriptFields { get; set; } + [JsonProperty("size")] int? Size { get; set; } @@ -20,46 +33,33 @@ public interface ITopHitsAggregation : IMetricAggregation [JsonProperty("_source")] Union Source { get; set; } - [JsonProperty("highlight")] - IHighlight Highlight { get; set; } - - [JsonProperty("explain")] - bool? Explain { get; set; } - - [JsonProperty("script_fields")] - [JsonConverter(typeof(ReadAsTypeJsonConverter))] - IScriptFields ScriptFields { get; set; } - [JsonProperty("stored_fields")] Fields StoredFields { get; set; } - [JsonProperty("docvalue_fields")] - Fields DocValueFields { get; set; } + [JsonProperty("track_scores")] + bool? TrackScores { get; set; } [JsonProperty("version")] bool? Version { get; set; } - - [JsonProperty("track_scores")] - bool? TrackScores { get; set; } } public class TopHitsAggregation : MetricAggregationBase, ITopHitsAggregation { + internal TopHitsAggregation() { } + + public TopHitsAggregation(string name) : base(name, null) { } + + public Fields DocValueFields { get; set; } + public bool? Explain { get; set; } public int? From { get; set; } + public IHighlight Highlight { get; set; } + public IScriptFields ScriptFields { get; set; } public int? Size { get; set; } public IList Sort { get; set; } public Union Source { get; set; } - public IHighlight Highlight { get; set; } - public bool? Explain { get; set; } - public IScriptFields ScriptFields { get; set; } public Fields StoredFields { get; set; } - public bool? Version { get; set; } public bool? TrackScores { get; set; } - public Fields DocValueFields { get; set; } - - internal TopHitsAggregation() { } - - public TopHitsAggregation(string name) : base(name, null) { } + public bool? Version { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.TopHits = this; } @@ -69,27 +69,26 @@ public class TopHitsAggregationDescriptor , ITopHitsAggregation where T : class { + Fields ITopHitsAggregation.DocValueFields { get; set; } + + bool? ITopHitsAggregation.Explain { get; set; } int? ITopHitsAggregation.From { get; set; } + IHighlight ITopHitsAggregation.Highlight { get; set; } + + IScriptFields ITopHitsAggregation.ScriptFields { get; set; } + int? ITopHitsAggregation.Size { get; set; } IList ITopHitsAggregation.Sort { get; set; } Union ITopHitsAggregation.Source { get; set; } - IHighlight ITopHitsAggregation.Highlight { get; set; } - - bool? ITopHitsAggregation.Explain { get; set; } - - IScriptFields ITopHitsAggregation.ScriptFields { get; set; } - Fields ITopHitsAggregation.StoredFields { get; set; } - bool? ITopHitsAggregation.Version { get; set; } - bool? ITopHitsAggregation.TrackScores { get; set; } - Fields ITopHitsAggregation.DocValueFields { get; set; } + bool? ITopHitsAggregation.Version { get; set; } public TopHitsAggregationDescriptor From(int? from) => Assign(a => a.From = from); diff --git a/src/Nest/Aggregations/Metric/ValueCount/ValueCountAggregation.cs b/src/Nest/Aggregations/Metric/ValueCount/ValueCountAggregation.cs index 5c90cd111e0..1efdf709877 100644 --- a/src/Nest/Aggregations/Metric/ValueCount/ValueCountAggregation.cs +++ b/src/Nest/Aggregations/Metric/ValueCount/ValueCountAggregation.cs @@ -2,7 +2,6 @@ namespace Nest { - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IValueCountAggregation : IMetricAggregation { } @@ -16,8 +15,8 @@ public ValueCountAggregation(string name, Field field) : base(name, field) { } internal override void WrapInContainer(AggregationContainer c) => c.ValueCount = this; } - public class ValueCountAggregationDescriptor + public class ValueCountAggregationDescriptor : MetricAggregationDescriptorBase, IValueCountAggregation, T> - , IValueCountAggregation + , IValueCountAggregation where T : class { } -} \ No newline at end of file +} diff --git a/src/Nest/Aggregations/Metric/WeightedAverage/WeightedAverageAggregation.cs b/src/Nest/Aggregations/Metric/WeightedAverage/WeightedAverageAggregation.cs index 678fd785b31..fd2ee0e8d6c 100644 --- a/src/Nest/Aggregations/Metric/WeightedAverage/WeightedAverageAggregation.cs +++ b/src/Nest/Aggregations/Metric/WeightedAverage/WeightedAverageAggregation.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq.Expressions; using Newtonsoft.Json; namespace Nest @@ -9,35 +8,42 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IWeightedAverageAggregation : IAggregation { - /// The configuration for the field or script that provides the values - [JsonProperty("value")] - IWeightedAverageValue Value { get; set; } - /// The configuration for the field or script that provides the weights - [JsonProperty("weight")] - IWeightedAverageValue Weight { get; set; } /// The optional numeric response formatter [JsonProperty("format")] string Format { get; set; } + + /// The configuration for the field or script that provides the values + [JsonProperty("value")] + IWeightedAverageValue Value { get; set; } + /// A hint about the values for pure scripts or unmapped fields [JsonProperty("value_type")] ValueType? ValueType { get; set; } + + /// The configuration for the field or script that provides the weights + [JsonProperty("weight")] + IWeightedAverageValue Weight { get; set; } } public class WeightedAverageAggregation : AggregationBase, IWeightedAverageAggregation { internal WeightedAverageAggregation() { } + public WeightedAverageAggregation(string name) : base(name) { } - internal override void WrapInContainer(AggregationContainer c) => c.WeightedAverage = this; + /// + public string Format { get; set; } - /// + /// public IWeightedAverageValue Value { get; set; } - /// - public IWeightedAverageValue Weight { get; set; } - /// - public string Format { get; set; } - /// + + /// public ValueType? ValueType { get; set; } + + /// + public IWeightedAverageValue Weight { get; set; } + + internal override void WrapInContainer(AggregationContainer c) => c.WeightedAverage = this; } public class WeightedAverageAggregationDescriptor @@ -45,29 +51,29 @@ public class WeightedAverageAggregationDescriptor , IWeightedAverageAggregation where T : class { - IWeightedAverageValue IWeightedAverageAggregation.Value { get; set; } - IWeightedAverageValue IWeightedAverageAggregation.Weight { get; set; } string IWeightedAverageAggregation.Format { get; set; } - ValueType? IWeightedAverageAggregation.ValueType { get; set; } - string IAggregation.Name { get; set; } IDictionary IAggregation.Meta { get; set; } + string IAggregation.Name { get; set; } + IWeightedAverageValue IWeightedAverageAggregation.Value { get; set; } + ValueType? IWeightedAverageAggregation.ValueType { get; set; } + IWeightedAverageValue IWeightedAverageAggregation.Weight { get; set; } - /// + /// public WeightedAverageAggregationDescriptor Meta(Func, FluentDictionary> selector) => Assign(a => a.Meta = selector?.Invoke(new FluentDictionary())); - /// + /// public WeightedAverageAggregationDescriptor Value(Func, IWeightedAverageValue> selector) => Assign(a => a.Value = selector?.Invoke(new WeightedAverageValueDescriptor())); - /// + /// public WeightedAverageAggregationDescriptor Weight(Func, IWeightedAverageValue> selector) => Assign(a => a.Weight = selector?.Invoke(new WeightedAverageValueDescriptor())); - /// + /// public WeightedAverageAggregationDescriptor Format(string format) => Assign(a => a.Format = format); - /// + /// public WeightedAverageAggregationDescriptor ValueType(ValueType? valueType) => Assign(a => a.ValueType = valueType); } } diff --git a/src/Nest/Aggregations/Metric/WeightedAverage/WeightedAverageValue.cs b/src/Nest/Aggregations/Metric/WeightedAverage/WeightedAverageValue.cs index 8c83af09915..65476b99674 100644 --- a/src/Nest/Aggregations/Metric/WeightedAverage/WeightedAverageValue.cs +++ b/src/Nest/Aggregations/Metric/WeightedAverage/WeightedAverageValue.cs @@ -8,7 +8,7 @@ namespace Nest { /// /// The configuration for a field or scrip that provides a value or weight - /// for + /// for /// [JsonObject(MemberSerialization = MemberSerialization.OptIn)] [ContractJsonConverter(typeof(ReadAsTypeJsonConverter))] @@ -20,12 +20,6 @@ public interface IWeightedAverageValue [JsonProperty("field")] Field Field { get; set; } - /// - /// A script to derive the value and the weight from - /// - [JsonProperty("script")] - IScript Script { get; set; } - /// /// defines how documents that are missing a value should be treated. /// The default behavior is different for value and weight: @@ -35,31 +29,42 @@ public interface IWeightedAverageValue /// [JsonProperty("missing")] double? Missing { get; set; } + + /// + /// A script to derive the value and the weight from + /// + [JsonProperty("script")] + IScript Script { get; set; } } /// public class WeightedAverageValue : IWeightedAverageValue { internal WeightedAverageValue() { } - public WeightedAverageValue(Field field) => this.Field = field; - public WeightedAverageValue(IScript script) => this.Script = script; + + public WeightedAverageValue(Field field) => Field = field; + + public WeightedAverageValue(IScript script) => Script = script; /// public Field Field { get; set; } - /// - public IScript Script { get; set; } + /// public double? Missing { get; set; } + + /// + public IScript Script { get; set; } } /// - public class WeightedAverageValueDescriptor : DescriptorBase, IWeightedAverageValue> + public class WeightedAverageValueDescriptor + : DescriptorBase, IWeightedAverageValue> , IWeightedAverageValue where T : class { Field IWeightedAverageValue.Field { get; set; } - IScript IWeightedAverageValue.Script { get; set; } double? IWeightedAverageValue.Missing { get; set; } + IScript IWeightedAverageValue.Script { get; set; } /// public WeightedAverageValueDescriptor Field(Field field) => Assign(a => a.Field = field); @@ -86,20 +91,28 @@ public enum ValueType { /// A string value [EnumMember(Value = "string")] String, + /// A long value that can be used to represent byte, short, integer and long [EnumMember(Value = "long")] Long, + /// A double value that can be used to represent float and double [EnumMember(Value = "double")] Double, + /// A number value [EnumMember(Value = "number")] Number, + /// A date value [EnumMember(Value = "date")] Date, + /// An IP value [EnumMember(Value = "ip")] Ip, + /// A numeric value [EnumMember(Value = "numeric")] Numeric, + /// A geo_point value [EnumMember(Value = "geo_point")] GeoPoint, + /// A boolean value [EnumMember(Value = "boolean")] Boolean, } diff --git a/src/Nest/Aggregations/Pipeline/AverageBucket/AverageBucketAggregation.cs b/src/Nest/Aggregations/Pipeline/AverageBucket/AverageBucketAggregation.cs index 332ea99e201..f80d70e283b 100644 --- a/src/Nest/Aggregations/Pipeline/AverageBucket/AverageBucketAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/AverageBucket/AverageBucketAggregation.cs @@ -9,7 +9,7 @@ public interface IAverageBucketAggregation : IPipelineAggregation { } public class AverageBucketAggregation : PipelineAggregationBase, IAverageBucketAggregation { - internal AverageBucketAggregation () { } + internal AverageBucketAggregation() { } public AverageBucketAggregation(string name, SingleBucketsPath bucketsPath) : base(name, bucketsPath) { } @@ -19,7 +19,5 @@ public AverageBucketAggregation(string name, SingleBucketsPath bucketsPath) public class AverageBucketAggregationDescriptor : PipelineAggregationDescriptorBase - , IAverageBucketAggregation - { - } + , IAverageBucketAggregation { } } diff --git a/src/Nest/Aggregations/Pipeline/BucketScript/BucketScriptAggregation.cs b/src/Nest/Aggregations/Pipeline/BucketScript/BucketScriptAggregation.cs index b38f5c76636..5ee0fe01538 100644 --- a/src/Nest/Aggregations/Pipeline/BucketScript/BucketScriptAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/BucketScript/BucketScriptAggregation.cs @@ -14,19 +14,19 @@ public interface IBucketScriptAggregation : IPipelineAggregation public class BucketScriptAggregation : PipelineAggregationBase, IBucketScriptAggregation { - public IScript Script { get; set; } - - internal BucketScriptAggregation () { } + internal BucketScriptAggregation() { } public BucketScriptAggregation(string name, MultiBucketsPath bucketsPath) : base(name, bucketsPath) { } + public IScript Script { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.BucketScript = this; } public class BucketScriptAggregationDescriptor : PipelineAggregationDescriptorBase - , IBucketScriptAggregation + , IBucketScriptAggregation { IScript IBucketScriptAggregation.Script { get; set; } diff --git a/src/Nest/Aggregations/Pipeline/BucketSelector/BucketSelectorAggregation.cs b/src/Nest/Aggregations/Pipeline/BucketSelector/BucketSelectorAggregation.cs index e6a2f4e652e..ecd50dd9c59 100644 --- a/src/Nest/Aggregations/Pipeline/BucketSelector/BucketSelectorAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/BucketSelector/BucketSelectorAggregation.cs @@ -14,19 +14,19 @@ public interface IBucketSelectorAggregation : IPipelineAggregation public class BucketSelectorAggregation : PipelineAggregationBase, IBucketSelectorAggregation { - public IScript Script { get; set; } - - internal BucketSelectorAggregation () { } + internal BucketSelectorAggregation() { } public BucketSelectorAggregation(string name, MultiBucketsPath bucketsPath) : base(name, bucketsPath) { } + public IScript Script { get; set; } + internal override void WrapInContainer(AggregationContainer c) => c.BucketSelector = this; } public class BucketSelectorAggregationDescriptor : PipelineAggregationDescriptorBase - , IBucketSelectorAggregation + , IBucketSelectorAggregation { IScript IBucketSelectorAggregation.Script { get; set; } diff --git a/src/Nest/Aggregations/Pipeline/BucketSort/BucketSortAggregation.cs b/src/Nest/Aggregations/Pipeline/BucketSort/BucketSortAggregation.cs index 48b5d0a64dc..5158a3099a8 100644 --- a/src/Nest/Aggregations/Pipeline/BucketSort/BucketSortAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/BucketSort/BucketSortAggregation.cs @@ -14,12 +14,6 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IBucketSortAggregation : IAggregation { - /// - /// The list of fields to sort on - /// - [JsonProperty("sort")] - IList Sort { get; set; } - /// /// Buckets in positions prior to the set value will be truncated /// @@ -27,42 +21,44 @@ public interface IBucketSortAggregation : IAggregation int? From { get; set; } /// - /// The number of buckets to return. Defaults to all buckets of the parent aggregation + /// The policy to apply when gaps are found in the data + /// + [JsonProperty("gap_policy")] + GapPolicy? GapPolicy { get; set; } + + /// + /// The number of buckets to return. Defaults to all buckets of the parent aggregation /// [JsonProperty("size")] int? Size { get; set; } /// - /// The policy to apply when gaps are found in the data + /// The list of fields to sort on /// - [JsonProperty("gap_policy")] - GapPolicy? GapPolicy { get; set; } + [JsonProperty("sort")] + IList Sort { get; set; } } /// public class BucketSortAggregation : AggregationBase, IBucketSortAggregation { - internal BucketSortAggregation() - { - } + internal BucketSortAggregation() { } public BucketSortAggregation(string name) - : base(name) - { - } + : base(name) { } /// - public IList Sort { get; set; } + public int? From { get; set; } /// - public int? From { get; set; } + public GapPolicy? GapPolicy { get; set; } /// public int? Size { get; set; } /// - public GapPolicy? GapPolicy { get; set; } + public IList Sort { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.BucketSort = this; } @@ -73,12 +69,11 @@ public class BucketSortAggregationDescriptor , IBucketSortAggregation where T : class { - string IAggregation.Name { get; set; } - IDictionary IAggregation.Meta { get; set; } - int? IBucketSortAggregation.From { get; set; } - int? IBucketSortAggregation.Size { get; set; } GapPolicy? IBucketSortAggregation.GapPolicy { get; set; } + IDictionary IAggregation.Meta { get; set; } + string IAggregation.Name { get; set; } + int? IBucketSortAggregation.Size { get; set; } IList IBucketSortAggregation.Sort { get; set; } /// @@ -93,7 +88,7 @@ public BucketSortAggregationDescriptor Sort(Func, IPromise< public BucketSortAggregationDescriptor From(int? from) => Assign(a => a.From = from); /// - /// The number of buckets to return. Defaults to all buckets of the parent aggregation + /// The number of buckets to return. Defaults to all buckets of the parent aggregation /// public BucketSortAggregationDescriptor Size(int? size) => Assign(a => a.Size = size); diff --git a/src/Nest/Aggregations/Pipeline/BucketsPath.cs b/src/Nest/Aggregations/Pipeline/BucketsPath.cs index 935293f128d..11d52c9bebe 100644 --- a/src/Nest/Aggregations/Pipeline/BucketsPath.cs +++ b/src/Nest/Aggregations/Pipeline/BucketsPath.cs @@ -10,12 +10,9 @@ public interface IBucketsPath { } public class SingleBucketsPath : IBucketsPath { - public string BucketsPath { get; } + public SingleBucketsPath(string bucketsPath) => BucketsPath = bucketsPath; - public SingleBucketsPath(string bucketsPath) - { - this.BucketsPath = bucketsPath; - } + public string BucketsPath { get; } public static implicit operator SingleBucketsPath(string bucketsPath) => new SingleBucketsPath(bucketsPath); } @@ -24,13 +21,14 @@ public interface IMultiBucketsPath : IIsADictionary, IBucketsPat public class MultiBucketsPath : IsADictionaryBase, IMultiBucketsPath { - public MultiBucketsPath() {} + public MultiBucketsPath() { } + public MultiBucketsPath(IDictionary container) : base(container) { } + public MultiBucketsPath(Dictionary container) - : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) - { } + : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) { } - public void Add(string name, string bucketsPath) => this.BackingDictionary.Add(name, bucketsPath); + public void Add(string name, string bucketsPath) => BackingDictionary.Add(name, bucketsPath); public static implicit operator MultiBucketsPath(Dictionary bucketsPath) => new MultiBucketsPath(bucketsPath); } @@ -83,7 +81,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s if (multi != null) { writer.WriteStartObject(); - foreach(var kv in multi) + foreach (var kv in multi) { writer.WritePropertyName(kv.Key); writer.WriteValue(kv.Value); diff --git a/src/Nest/Aggregations/Pipeline/CumulativeSum/CumulativeSumAggregation.cs b/src/Nest/Aggregations/Pipeline/CumulativeSum/CumulativeSumAggregation.cs index e6d50e41914..0e0186f900f 100644 --- a/src/Nest/Aggregations/Pipeline/CumulativeSum/CumulativeSumAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/CumulativeSum/CumulativeSumAggregation.cs @@ -9,7 +9,7 @@ public interface ICumulativeSumAggregation : IPipelineAggregation { } public class CumulativeSumAggregation : PipelineAggregationBase, ICumulativeSumAggregation { - internal CumulativeSumAggregation () { } + internal CumulativeSumAggregation() { } public CumulativeSumAggregation(string name, SingleBucketsPath bucketsPath) : base(name, bucketsPath) { } @@ -19,7 +19,5 @@ public CumulativeSumAggregation(string name, SingleBucketsPath bucketsPath) public class CumulativeSumAggregationDescriptor : PipelineAggregationDescriptorBase - , ICumulativeSumAggregation - { - } + , ICumulativeSumAggregation { } } diff --git a/src/Nest/Aggregations/Pipeline/Derivative/DerivativeAggregation.cs b/src/Nest/Aggregations/Pipeline/Derivative/DerivativeAggregation.cs index ec660300c18..18f38bb0084 100644 --- a/src/Nest/Aggregations/Pipeline/Derivative/DerivativeAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/Derivative/DerivativeAggregation.cs @@ -18,5 +18,5 @@ public DerivativeAggregation(string name, SingleBucketsPath bucketsPath) public class DerivativeAggregationDescriptor : PipelineAggregationDescriptorBase - , IDerivativeAggregation { } + , IDerivativeAggregation { } } diff --git a/src/Nest/Aggregations/Pipeline/ExtendedStatsBucket/ExtendedStatsBucketAggregation.cs b/src/Nest/Aggregations/Pipeline/ExtendedStatsBucket/ExtendedStatsBucketAggregation.cs index 096b1260ab0..145014968a2 100644 --- a/src/Nest/Aggregations/Pipeline/ExtendedStatsBucket/ExtendedStatsBucketAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/ExtendedStatsBucket/ExtendedStatsBucketAggregation.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -17,8 +16,7 @@ public class ExtendedStatsBucketAggregation internal ExtendedStatsBucketAggregation() { } public ExtendedStatsBucketAggregation(string name, SingleBucketsPath bucketsPath) - : base(name, bucketsPath) - { } + : base(name, bucketsPath) { } public double? Sigma { get; set; } @@ -27,12 +25,10 @@ public ExtendedStatsBucketAggregation(string name, SingleBucketsPath bucketsPath public class ExtendedStatsBucketAggregationDescriptor : PipelineAggregationDescriptorBase - , IExtendedStatsBucketAggregation + , IExtendedStatsBucketAggregation { - double? IExtendedStatsBucketAggregation.Sigma { get; set; } public ExtendedStatsBucketAggregationDescriptor Sigma(double? sigma) => Assign(a => a.Sigma = sigma); - } } diff --git a/src/Nest/Aggregations/Pipeline/GapPolicy.cs b/src/Nest/Aggregations/Pipeline/GapPolicy.cs index bd3ba01153a..e2f2c9968b9 100644 --- a/src/Nest/Aggregations/Pipeline/GapPolicy.cs +++ b/src/Nest/Aggregations/Pipeline/GapPolicy.cs @@ -9,6 +9,7 @@ public enum GapPolicy { [EnumMember(Value = "skip")] Skip, + [EnumMember(Value = "insert_zeros")] InsertZeros } diff --git a/src/Nest/Aggregations/Pipeline/MaxBucket/MaxBucketAggregation.cs b/src/Nest/Aggregations/Pipeline/MaxBucket/MaxBucketAggregation.cs index 67aba2981d9..94d4ed47a29 100644 --- a/src/Nest/Aggregations/Pipeline/MaxBucket/MaxBucketAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/MaxBucket/MaxBucketAggregation.cs @@ -9,7 +9,7 @@ public interface IMaxBucketAggregation : IPipelineAggregation { } public class MaxBucketAggregation : PipelineAggregationBase, IMaxBucketAggregation { - internal MaxBucketAggregation () { } + internal MaxBucketAggregation() { } public MaxBucketAggregation(string name, SingleBucketsPath bucketsPath) : base(name, bucketsPath) { } @@ -19,7 +19,5 @@ public MaxBucketAggregation(string name, SingleBucketsPath bucketsPath) public class MaxBucketAggregationDescriptor : PipelineAggregationDescriptorBase - , IMaxBucketAggregation - { - } + , IMaxBucketAggregation { } } diff --git a/src/Nest/Aggregations/Pipeline/MinBucket/MinBucketAggregation.cs b/src/Nest/Aggregations/Pipeline/MinBucket/MinBucketAggregation.cs index 9a27eb026c9..1a7f2983ff8 100644 --- a/src/Nest/Aggregations/Pipeline/MinBucket/MinBucketAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/MinBucket/MinBucketAggregation.cs @@ -9,7 +9,7 @@ public interface IMinBucketAggregation : IPipelineAggregation { } public class MinBucketAggregation : PipelineAggregationBase, IMinBucketAggregation { - internal MinBucketAggregation () { } + internal MinBucketAggregation() { } public MinBucketAggregation(string name, SingleBucketsPath bucketsPath) : base(name, bucketsPath) { } @@ -19,7 +19,5 @@ public MinBucketAggregation(string name, SingleBucketsPath bucketsPath) public class MinBucketAggregationDescriptor : PipelineAggregationDescriptorBase - , IMinBucketAggregation - { - } + , IMinBucketAggregation { } } diff --git a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/EwmaModel.cs b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/EwmaModel.cs index 347a8255ab4..c2caa1d3934 100644 --- a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/EwmaModel.cs +++ b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/EwmaModel.cs @@ -11,16 +11,15 @@ public interface IEwmaModel : IMovingAverageModel public class EwmaModel : IEwmaModel { - string IMovingAverageModel.Name { get; } = "ewma"; - public float? Alpha { get; set; } + string IMovingAverageModel.Name { get; } = "ewma"; } public class EwmaModelDescriptor : DescriptorBase, IEwmaModel { - string IMovingAverageModel.Name { get; } = "ewma"; float? IEwmaModel.Alpha { get; set; } + string IMovingAverageModel.Name { get; } = "ewma"; public EwmaModelDescriptor Alpha(float? alpha) => Assign(a => a.Alpha = alpha); } diff --git a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/HoltLinearModel.cs b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/HoltLinearModel.cs index 07a6cf10f2b..a8a60483f0a 100644 --- a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/HoltLinearModel.cs +++ b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/HoltLinearModel.cs @@ -14,18 +14,17 @@ public interface IHoltLinearModel : IMovingAverageModel public class HoltLinearModel : IHoltLinearModel { - string IMovingAverageModel.Name { get; } = "holt"; - public float? Alpha { get; set; } public float? Beta { get; set; } + string IMovingAverageModel.Name { get; } = "holt"; } public class HoltLinearModelDescriptor : DescriptorBase, IHoltLinearModel { - string IMovingAverageModel.Name { get; } = "holt"; float? IHoltLinearModel.Alpha { get; set; } float? IHoltLinearModel.Beta { get; set; } + string IMovingAverageModel.Name { get; } = "holt"; public HoltLinearModelDescriptor Alpha(float? alpha) => Assign(a => a.Alpha = alpha); diff --git a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/HoltWintersModel.cs b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/HoltWintersModel.cs index 2612f187921..6f76304b030 100644 --- a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/HoltWintersModel.cs +++ b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/HoltWintersModel.cs @@ -9,6 +9,7 @@ public enum HoltWintersType { [EnumMember(Value = "add")] Additive, + [EnumMember(Value = "mult")] Multiplicative } @@ -25,35 +26,34 @@ public interface IHoltWintersModel : IMovingAverageModel [JsonProperty("gamma")] float? Gamma { get; set; } + [JsonProperty("pad")] + bool? Pad { get; set; } + [JsonProperty("period")] int? Period { get; set; } [JsonProperty("type")] HoltWintersType? Type { get; set; } - - [JsonProperty("pad")] - bool? Pad { get; set; } } public class HoltWintersModel : IHoltWintersModel { - string IMovingAverageModel.Name { get; } = "holt_winters"; - public float? Alpha { get; set; } public float? Beta { get; set; } public float? Gamma { get; set; } + public bool? Pad { get; set; } public int? Period { get; set; } public HoltWintersType? Type { get; set; } - public bool? Pad { get; set; } + string IMovingAverageModel.Name { get; } = "holt_winters"; } public class HoltWintersModelDescriptor : DescriptorBase, IHoltWintersModel { - string IMovingAverageModel.Name { get; } = "holt_winters"; float? IHoltWintersModel.Alpha { get; set; } float? IHoltWintersModel.Beta { get; set; } float? IHoltWintersModel.Gamma { get; set; } + string IMovingAverageModel.Name { get; } = "holt_winters"; bool? IHoltWintersModel.Pad { get; set; } int? IHoltWintersModel.Period { get; set; } HoltWintersType? IHoltWintersModel.Type { get; set; } diff --git a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/IMovingAverageModel.cs b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/IMovingAverageModel.cs index f3865903312..6e6c5b6f8fa 100644 --- a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/IMovingAverageModel.cs +++ b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/IMovingAverageModel.cs @@ -2,26 +2,26 @@ namespace Nest { - public interface IMovingAverageModel + public interface IMovingAverageModel { string Name { get; } } public class MovingAverageModelDescriptor : DescriptorBase { - public IEwmaModel Ewma(Func ewmaSelector = null) => + public IEwmaModel Ewma(Func ewmaSelector = null) => ewmaSelector.InvokeOrDefault(new EwmaModelDescriptor()); - public IHoltLinearModel HoltLinear(Func holtSelector = null) => + public IHoltLinearModel HoltLinear(Func holtSelector = null) => holtSelector.InvokeOrDefault(new HoltLinearModelDescriptor()); - public IHoltWintersModel HoltWinters(Func holtWintersSelector) => + public IHoltWintersModel HoltWinters(Func holtWintersSelector) => holtWintersSelector?.Invoke(new HoltWintersModelDescriptor()); - public ILinearModel Linear(Func linearSelector = null) => + public ILinearModel Linear(Func linearSelector = null) => linearSelector.InvokeOrDefault(new LinearModelDescriptor()); - public ISimpleModel Simple(Func simpleSelector = null) => + public ISimpleModel Simple(Func simpleSelector = null) => simpleSelector.InvokeOrDefault(new SimpleModelDescriptor()); } } diff --git a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/LinearModel.cs b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/LinearModel.cs index d83f5ceb634..e58009d9d63 100644 --- a/src/Nest/Aggregations/Pipeline/MovingAverage/Models/LinearModel.cs +++ b/src/Nest/Aggregations/Pipeline/MovingAverage/Models/LinearModel.cs @@ -4,10 +4,10 @@ namespace Nest { [JsonObject(MemberSerialization = MemberSerialization.OptIn)] public interface ILinearModel : IMovingAverageModel { } - + public class LinearModel : ILinearModel { - string IMovingAverageModel.Name { get; } = "linear"; + string IMovingAverageModel.Name { get; } = "linear"; } public class LinearModelDescriptor diff --git a/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregation.cs b/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregation.cs index d3dcaebfd23..2ea83bf3b13 100644 --- a/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregation.cs @@ -7,42 +7,41 @@ namespace Nest [ContractJsonConverter(typeof(MovingAverageAggregationJsonConverter))] public interface IMovingAverageAggregation : IPipelineAggregation { - IMovingAverageModel Model { get; set; } - - [JsonProperty("window")] - int? Window { get; set; } - [JsonProperty("minimize")] bool? Minimize { get; set; } + IMovingAverageModel Model { get; set; } + [JsonProperty("predict")] int? Predict { get; set; } + + [JsonProperty("window")] + int? Window { get; set; } } public class MovingAverageAggregation : PipelineAggregationBase, IMovingAverageAggregation { - public bool? Minimize { get; set; } - public IMovingAverageModel Model { get; set; } - public int? Window { get; set; } - public int? Predict { get; set; } - internal MovingAverageAggregation() { } public MovingAverageAggregation(string name, SingleBucketsPath bucketsPath) - : base(name, bucketsPath) - { } + : base(name, bucketsPath) { } + + public bool? Minimize { get; set; } + public IMovingAverageModel Model { get; set; } + public int? Predict { get; set; } + public int? Window { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.MovingAverage = this; } public class MovingAverageAggregationDescriptor : PipelineAggregationDescriptorBase - , IMovingAverageAggregation + , IMovingAverageAggregation { bool? IMovingAverageAggregation.Minimize { get; set; } IMovingAverageModel IMovingAverageAggregation.Model { get; set; } - int? IMovingAverageAggregation.Window { get; set; } int? IMovingAverageAggregation.Predict { get; set; } + int? IMovingAverageAggregation.Window { get; set; } public MovingAverageAggregationDescriptor Minimize(bool? minimize = true) => Assign(a => a.Minimize = minimize); @@ -52,6 +51,5 @@ public class MovingAverageAggregationDescriptor public MovingAverageAggregationDescriptor Model(Func modelSelector) => Assign(a => a.Model = modelSelector?.Invoke(new MovingAverageModelDescriptor())); - } } diff --git a/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregationJsonConverter.cs b/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregationJsonConverter.cs index a588b1f0737..7d6770a4e02 100644 --- a/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregationJsonConverter.cs +++ b/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregationJsonConverter.cs @@ -28,13 +28,9 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist #if DOTNETCORE JToken value; if (ps.TryGetValue("buckets_path", out value) && value != null) - { aggregation.BucketsPath = new SingleBucketsPath((string)value); - } else - { aggregation.BucketsPath = default(SingleBucketsPath); - } #else aggregation.BucketsPath = GetOrDefault("buckets_path", ps); @@ -46,6 +42,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s { var movingAvg = value as IMovingAverageAggregation; if (movingAvg == null) return; + writer.WriteStartObject(); writer.WritePropertyName("buckets_path"); serializer.Serialize(writer, movingAvg.BucketsPath); @@ -100,6 +97,7 @@ private T GetOrDefault(string key, Dictionary properties) if (value.IsNullOrEmpty()) return null; if (value == "insert_zeros") return GapPolicy.InsertZeros; if (value == "skip") return GapPolicy.Skip; + return null; } @@ -121,6 +119,7 @@ private IMovingAverageModel GetModel(Dictionary properties) return settings.ToObject(); else if (name == "holt_winters") return settings.ToObject(); + return null; } } diff --git a/src/Nest/Aggregations/Pipeline/MovingFunction/MovingFunctionAggregation.cs b/src/Nest/Aggregations/Pipeline/MovingFunction/MovingFunctionAggregation.cs index 13153915c42..d5c1a2109db 100644 --- a/src/Nest/Aggregations/Pipeline/MovingFunction/MovingFunctionAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/MovingFunction/MovingFunctionAggregation.cs @@ -6,33 +6,34 @@ namespace Nest [ContractJsonConverter(typeof(AggregationJsonConverter))] public interface IMovingFunctionAggregation : IPipelineAggregation { - [JsonProperty("window")] - int? Window { get; set; } - [JsonProperty("script")] string Script { get; set; } + + [JsonProperty("window")] + int? Window { get; set; } } public class MovingFunctionAggregation : PipelineAggregationBase, IMovingFunctionAggregation { - internal MovingFunctionAggregation () { } + internal MovingFunctionAggregation() { } public MovingFunctionAggregation(string name, SingleBucketsPath bucketsPath) : base(name, bucketsPath) { } - internal override void WrapInContainer(AggregationContainer c) => c.MovingFunction = this; + public string Script { get; set; } public int? Window { get; set; } - public string Script { get; set; } + + internal override void WrapInContainer(AggregationContainer c) => c.MovingFunction = this; } public class MovingFunctionAggregationDescriptor : PipelineAggregationDescriptorBase - , IMovingFunctionAggregation + , IMovingFunctionAggregation { - int? IMovingFunctionAggregation.Window { get; set; } string IMovingFunctionAggregation.Script { get; set; } + int? IMovingFunctionAggregation.Window { get; set; } public MovingFunctionAggregationDescriptor Window(int? windowSize) => Assign(a => a.Window = windowSize); diff --git a/src/Nest/Aggregations/Pipeline/PercentilesBucket/PercentilesBucketAggregation.cs b/src/Nest/Aggregations/Pipeline/PercentilesBucket/PercentilesBucketAggregation.cs index 2b1430e40fe..5b0086a5d5a 100644 --- a/src/Nest/Aggregations/Pipeline/PercentilesBucket/PercentilesBucketAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/PercentilesBucket/PercentilesBucketAggregation.cs @@ -1,7 +1,6 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; +using Newtonsoft.Json; namespace Nest { @@ -16,20 +15,19 @@ public interface IPercentilesBucketAggregation : IPipelineAggregation public class PercentilesBucketAggregation : PipelineAggregationBase, IPercentilesBucketAggregation { - public IEnumerable Percents { get; set; } - internal PercentilesBucketAggregation() { } public PercentilesBucketAggregation(string name, SingleBucketsPath bucketsPath) - : base(name, bucketsPath) - { } + : base(name, bucketsPath) { } + + public IEnumerable Percents { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.PercentilesBucket = this; } public class PercentilesBucketAggregationDescriptor : PipelineAggregationDescriptorBase - , IPercentilesBucketAggregation + , IPercentilesBucketAggregation { IEnumerable IPercentilesBucketAggregation.Percents { get; set; } @@ -38,6 +36,5 @@ public PercentilesBucketAggregationDescriptor Percents(IEnumerable perce public PercentilesBucketAggregationDescriptor Percents(params double[] percentages) => Assign(a => a.Percents = percentages?.ToList()); - } } diff --git a/src/Nest/Aggregations/Pipeline/PipelineAggregationBase.cs b/src/Nest/Aggregations/Pipeline/PipelineAggregationBase.cs index 42e4483e244..3e8ea39c033 100644 --- a/src/Nest/Aggregations/Pipeline/PipelineAggregationBase.cs +++ b/src/Nest/Aggregations/Pipeline/PipelineAggregationBase.cs @@ -9,18 +9,18 @@ public interface IPipelineAggregation : IAggregation [JsonProperty("buckets_path")] IBucketsPath BucketsPath { get; set; } - [JsonProperty("gap_policy")] - GapPolicy? GapPolicy { get; set; } - [JsonProperty("format")] string Format { get; set; } + + [JsonProperty("gap_policy")] + GapPolicy? GapPolicy { get; set; } } public abstract class PipelineAggregationBase : AggregationBase, IPipelineAggregation { internal PipelineAggregationBase() { } - public PipelineAggregationBase(string name, IBucketsPath bucketsPath) : base(name) => this.BucketsPath = bucketsPath; + public PipelineAggregationBase(string name, IBucketsPath bucketsPath) : base(name) => BucketsPath = bucketsPath; public IBucketsPath BucketsPath { get; set; } public string Format { get; set; } @@ -30,7 +30,7 @@ internal PipelineAggregationBase() { } public abstract class PipelineAggregationDescriptorBase : DescriptorBase, IPipelineAggregation where TPipelineAggregation : PipelineAggregationDescriptorBase - , TPipelineAggregationInterface, IPipelineAggregation + , TPipelineAggregationInterface, IPipelineAggregation where TPipelineAggregationInterface : class, IPipelineAggregation where TBucketsPath : IBucketsPath { @@ -38,10 +38,10 @@ public abstract class PipelineAggregationDescriptorBase IAggregation.Meta { get; set; } + string IAggregation.Name { get; set; } + public TPipelineAggregation Format(string format) => Assign(a => a.Format = format); public TPipelineAggregation GapPolicy(GapPolicy? gapPolicy) => Assign(a => a.GapPolicy = gapPolicy); diff --git a/src/Nest/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregation.cs b/src/Nest/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregation.cs index 9c125616635..bb3b7751173 100644 --- a/src/Nest/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregation.cs @@ -12,20 +12,19 @@ public interface ISerialDifferencingAggregation : IPipelineAggregation public class SerialDifferencingAggregation : PipelineAggregationBase, ISerialDifferencingAggregation { - public int? Lag { get; set; } - internal SerialDifferencingAggregation() { } public SerialDifferencingAggregation(string name, SingleBucketsPath bucketsPath) - : base(name, bucketsPath) - { } + : base(name, bucketsPath) { } + + public int? Lag { get; set; } internal override void WrapInContainer(AggregationContainer c) => c.SerialDifferencing = this; } public class SerialDifferencingAggregationDescriptor : PipelineAggregationDescriptorBase - , ISerialDifferencingAggregation + , ISerialDifferencingAggregation { int? ISerialDifferencingAggregation.Lag { get; set; } diff --git a/src/Nest/Aggregations/Pipeline/StatsBucket/StatsBucketAggregation.cs b/src/Nest/Aggregations/Pipeline/StatsBucket/StatsBucketAggregation.cs index d937c86d694..68cce925277 100644 --- a/src/Nest/Aggregations/Pipeline/StatsBucket/StatsBucketAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/StatsBucket/StatsBucketAggregation.cs @@ -12,15 +12,12 @@ public class StatsBucketAggregation internal StatsBucketAggregation() { } public StatsBucketAggregation(string name, SingleBucketsPath bucketsPath) - : base(name, bucketsPath) - { } + : base(name, bucketsPath) { } internal override void WrapInContainer(AggregationContainer c) => c.StatsBucket = this; } public class StatsBucketAggregationDescriptor : PipelineAggregationDescriptorBase - , IStatsBucketAggregation - { - } + , IStatsBucketAggregation { } } diff --git a/src/Nest/Aggregations/Pipeline/SumBucket/SumBucketAggregation.cs b/src/Nest/Aggregations/Pipeline/SumBucket/SumBucketAggregation.cs index 657701003ee..1c780b52abf 100644 --- a/src/Nest/Aggregations/Pipeline/SumBucket/SumBucketAggregation.cs +++ b/src/Nest/Aggregations/Pipeline/SumBucket/SumBucketAggregation.cs @@ -9,7 +9,7 @@ public interface ISumBucketAggregation : IPipelineAggregation { } public class SumBucketAggregation : PipelineAggregationBase, ISumBucketAggregation { - internal SumBucketAggregation () { } + internal SumBucketAggregation() { } public SumBucketAggregation(string name, SingleBucketsPath bucketsPath) : base(name, bucketsPath) { } @@ -19,7 +19,5 @@ public SumBucketAggregation(string name, SingleBucketsPath bucketsPath) public class SumBucketAggregationDescriptor : PipelineAggregationDescriptorBase - , ISumBucketAggregation - { - } + , ISumBucketAggregation { } } diff --git a/src/Nest/Aggregations/Visitor/AggregationVisitor.cs b/src/Nest/Aggregations/Visitor/AggregationVisitor.cs index 8ade3c0fb6b..ac046d2c1e0 100644 --- a/src/Nest/Aggregations/Visitor/AggregationVisitor.cs +++ b/src/Nest/Aggregations/Visitor/AggregationVisitor.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Nest +namespace Nest { public interface IAggregationVisitor { @@ -29,52 +23,99 @@ public interface IAggregationVisitor /// /// The IAggregation object that will be visited void Visit(IAggregation aggregation); + void Visit(IAverageAggregation aggregation); + void Visit(IValueCountAggregation aggregation); + void Visit(IMaxAggregation aggregation); + void Visit(IMinAggregation aggregation); + void Visit(IStatsAggregation aggregation); + void Visit(ISumAggregation aggregation); + void Visit(IExtendedStatsAggregation aggregation); + void Visit(IDateHistogramAggregation aggregation); + void Visit(IPercentilesAggregation aggregation); + void Visit(IDateRangeAggregation aggregation); + void Visit(IFilterAggregation aggregation); + void Visit(IFiltersAggregation aggregation); + void Visit(IGeoDistanceAggregation aggregation); + void Visit(IGeoHashGridAggregation aggregation); + void Visit(IGeoBoundsAggregation aggregation); + void Visit(IHistogramAggregation aggregation); + void Visit(IGlobalAggregation aggregation); + void Visit(IIpRangeAggregation aggregation); + void Visit(ICardinalityAggregation aggregation); + void Visit(IMissingAggregation aggregation); + void Visit(INestedAggregation aggregation); + void Visit(IReverseNestedAggregation aggregation); + void Visit(IRangeAggregation aggregation); + void Visit(ITermsAggregation aggregation); + void Visit(ISignificantTermsAggregation aggregation); + void Visit(ISignificantTextAggregation aggregation); + void Visit(IPercentileRanksAggregation aggregation); + void Visit(ITopHitsAggregation aggregation); + void Visit(IChildrenAggregation aggregation); + void Visit(IScriptedMetricAggregation aggregation); + void Visit(IAverageBucketAggregation aggregation); + void Visit(IDerivativeAggregation aggregation); + void Visit(IMaxBucketAggregation aggregation); + void Visit(IMinBucketAggregation aggregation); + void Visit(ISumBucketAggregation aggregation); + void Visit(IStatsBucketAggregation aggregation); + void Visit(IExtendedStatsBucketAggregation aggregation); + void Visit(IPercentilesBucketAggregation aggregation); + void Visit(IMovingAverageAggregation aggregation); + void Visit(ICumulativeSumAggregation aggregation); + void Visit(ISerialDifferencingAggregation aggregation); + void Visit(IBucketScriptAggregation aggregation); + void Visit(IBucketSelectorAggregation aggregation); + void Visit(IBucketSortAggregation aggregation); + void Visit(ISamplerAggregation aggregation); + void Visit(IGeoCentroidAggregation aggregation); + void Visit(ICompositeAggregation aggregation); } @@ -84,200 +125,102 @@ public class AggregationVisitor : IAggregationVisitor public AggregationVisitorScope Scope { get; set; } - public virtual void Visit(IValueCountAggregation aggregation) - { - } + public virtual void Visit(IValueCountAggregation aggregation) { } - public virtual void Visit(IMinAggregation aggregation) - { - } + public virtual void Visit(IMinAggregation aggregation) { } - public virtual void Visit(ISumAggregation aggregation) - { - } + public virtual void Visit(ISumAggregation aggregation) { } - public virtual void Visit(IDateHistogramAggregation aggregation) - { - } + public virtual void Visit(IDateHistogramAggregation aggregation) { } - public virtual void Visit(IDateRangeAggregation aggregation) - { - } + public virtual void Visit(IDateRangeAggregation aggregation) { } - public virtual void Visit(IFiltersAggregation aggregation) - { - } + public virtual void Visit(IFiltersAggregation aggregation) { } - public virtual void Visit(IGeoHashGridAggregation aggregation) - { - } + public virtual void Visit(IGeoHashGridAggregation aggregation) { } - public virtual void Visit(IHistogramAggregation aggregation) - { - } + public virtual void Visit(IHistogramAggregation aggregation) { } - public virtual void Visit(IIpRangeAggregation aggregation) - { - } + public virtual void Visit(IIpRangeAggregation aggregation) { } - public virtual void Visit(IMissingAggregation aggregation) - { - } + public virtual void Visit(IMissingAggregation aggregation) { } - public virtual void Visit(IReverseNestedAggregation aggregation) - { - } + public virtual void Visit(IReverseNestedAggregation aggregation) { } - public virtual void Visit(ITermsAggregation aggregation) - { - } + public virtual void Visit(ITermsAggregation aggregation) { } - public void Visit(ISignificantTextAggregation aggregation) - { - } + public void Visit(ISignificantTextAggregation aggregation) { } - public virtual void Visit(IPercentileRanksAggregation aggregation) - { - } + public virtual void Visit(IPercentileRanksAggregation aggregation) { } - public virtual void Visit(IChildrenAggregation aggregation) - { - } + public virtual void Visit(IChildrenAggregation aggregation) { } - public virtual void Visit(IAverageBucketAggregation aggregation) - { - } + public virtual void Visit(IAverageBucketAggregation aggregation) { } - public virtual void Visit(IMaxBucketAggregation aggregation) - { - } + public virtual void Visit(IMaxBucketAggregation aggregation) { } - public virtual void Visit(ISumBucketAggregation aggregation) - { - } + public virtual void Visit(ISumBucketAggregation aggregation) { } - public virtual void Visit(IStatsBucketAggregation aggregation) - { - } + public virtual void Visit(IStatsBucketAggregation aggregation) { } - public virtual void Visit(IExtendedStatsBucketAggregation aggregation) - { - } + public virtual void Visit(IExtendedStatsBucketAggregation aggregation) { } - public virtual void Visit(IPercentilesBucketAggregation aggregation) - { - } + public virtual void Visit(IPercentilesBucketAggregation aggregation) { } - public virtual void Visit(ICumulativeSumAggregation aggregation) - { - } + public virtual void Visit(ICumulativeSumAggregation aggregation) { } - public virtual void Visit(IBucketScriptAggregation aggregation) - { - } + public virtual void Visit(IBucketScriptAggregation aggregation) { } - public virtual void Visit(ISamplerAggregation aggregation) - { - } + public virtual void Visit(ISamplerAggregation aggregation) { } - public virtual void Visit(IBucketSelectorAggregation aggregation) - { - } + public virtual void Visit(IBucketSelectorAggregation aggregation) { } - public virtual void Visit(IBucketSortAggregation aggregation) - { - } + public virtual void Visit(IBucketSortAggregation aggregation) { } - public virtual void Visit(ISerialDifferencingAggregation aggregation) - { - } + public virtual void Visit(ISerialDifferencingAggregation aggregation) { } - public virtual void Visit(IMovingAverageAggregation aggregation) - { - } + public virtual void Visit(IMovingAverageAggregation aggregation) { } - public virtual void Visit(IMinBucketAggregation aggregation) - { - } + public virtual void Visit(IMinBucketAggregation aggregation) { } - public virtual void Visit(IDerivativeAggregation aggregation) - { - } + public virtual void Visit(IDerivativeAggregation aggregation) { } - public virtual void Visit(IScriptedMetricAggregation aggregation) - { - } + public virtual void Visit(IScriptedMetricAggregation aggregation) { } - public virtual void Visit(ITopHitsAggregation aggregation) - { - } + public virtual void Visit(ITopHitsAggregation aggregation) { } - public virtual void Visit(ISignificantTermsAggregation aggregation) - { - } + public virtual void Visit(ISignificantTermsAggregation aggregation) { } - public virtual void Visit(IRangeAggregation aggregation) - { - } + public virtual void Visit(IRangeAggregation aggregation) { } - public virtual void Visit(INestedAggregation aggregation) - { - } + public virtual void Visit(INestedAggregation aggregation) { } - public virtual void Visit(ICardinalityAggregation aggregation) - { - } + public virtual void Visit(ICardinalityAggregation aggregation) { } - public virtual void Visit(IGlobalAggregation aggregation) - { - } + public virtual void Visit(IGlobalAggregation aggregation) { } - public virtual void Visit(IGeoBoundsAggregation aggregation) - { - } + public virtual void Visit(IGeoBoundsAggregation aggregation) { } - public virtual void Visit(IGeoDistanceAggregation aggregation) - { - } + public virtual void Visit(IGeoDistanceAggregation aggregation) { } - public virtual void Visit(IFilterAggregation aggregation) - { - } + public virtual void Visit(IFilterAggregation aggregation) { } - public virtual void Visit(IPercentilesAggregation aggregation) - { - } + public virtual void Visit(IPercentilesAggregation aggregation) { } - public virtual void Visit(IExtendedStatsAggregation aggregation) - { - } + public virtual void Visit(IExtendedStatsAggregation aggregation) { } - public virtual void Visit(IStatsAggregation aggregation) - { - } + public virtual void Visit(IStatsAggregation aggregation) { } - public virtual void Visit(IMaxAggregation aggregation) - { - } + public virtual void Visit(IMaxAggregation aggregation) { } - public virtual void Visit(IAverageAggregation aggregation) - { - } + public virtual void Visit(IAverageAggregation aggregation) { } - public virtual void Visit(IGeoCentroidAggregation aggregation) - { - } + public virtual void Visit(IGeoCentroidAggregation aggregation) { } - public virtual void Visit(ICompositeAggregation aggregation) - { - } + public virtual void Visit(ICompositeAggregation aggregation) { } - public virtual void Visit(IAggregation aggregation) - { - } + public virtual void Visit(IAggregation aggregation) { } - public virtual void Visit(IAggregationContainer aggregationContainer) - { - } + public virtual void Visit(IAggregationContainer aggregationContainer) { } } } diff --git a/src/Nest/Aggregations/Visitor/AggregationVisitorScope.cs b/src/Nest/Aggregations/Visitor/AggregationVisitorScope.cs index c8d09f35df1..83374192bcd 100644 --- a/src/Nest/Aggregations/Visitor/AggregationVisitorScope.cs +++ b/src/Nest/Aggregations/Visitor/AggregationVisitorScope.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Nest +namespace Nest { public enum AggregationVisitorScope { diff --git a/src/Nest/Aggregations/Visitor/AggregationWalker.cs b/src/Nest/Aggregations/Visitor/AggregationWalker.cs index 2ea41941bd0..ee506161b34 100644 --- a/src/Nest/Aggregations/Visitor/AggregationWalker.cs +++ b/src/Nest/Aggregations/Visitor/AggregationWalker.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Nest { @@ -11,13 +7,17 @@ public class AggregationWalker private void Accept(IAggregationVisitor visitor, AggregationDictionary aggregations) { if (!aggregations.HasAny()) return; + foreach (var f in aggregations) - this.Accept(visitor, f.Value, AggregationVisitorScope.Bucket); + Accept(visitor, f.Value, AggregationVisitorScope.Bucket); } - private void Accept(IAggregationVisitor visitor, IAggregationContainer aggregation, AggregationVisitorScope scope = AggregationVisitorScope.Aggregation) + private void Accept(IAggregationVisitor visitor, IAggregationContainer aggregation, + AggregationVisitorScope scope = AggregationVisitorScope.Aggregation + ) { if (aggregation == null) return; + visitor.Scope = scope; aggregation.Accept(visitor); } @@ -42,43 +42,115 @@ public void Walk(IAggregationContainer aggregation, IAggregationVisitor visitor) AcceptAggregation(aggregation.BucketSort, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.BucketSelector, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.Cardinality, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.Children, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.Children, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.CumulativeSum, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.DateHistogram, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.DateRange, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.DateHistogram, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.DateRange, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.Derivative, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.ExtendedStats, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.Filter, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.Filters, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.Filter, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.Filters, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.GeoBounds, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.GeoDistance, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.GeoHash, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.Global, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.Histogram, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.IpRange, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.GeoDistance, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.GeoHash, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.Global, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.Histogram, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.IpRange, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.Max, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.MaxBucket, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.Min, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.MinBucket, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.Missing, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.Missing, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.MovingAverage, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.Nested, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.Nested, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.PercentileRanks, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.Percentiles, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.Range, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.ReverseNested, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.Sampler, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.Range, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.ReverseNested, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.Sampler, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.ScriptedMetric, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.SerialDifferencing, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.SignificantTerms, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); - AcceptAggregation(aggregation.SignificantText, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.SignificantTerms, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); + AcceptAggregation(aggregation.SignificantText, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.Stats, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.Sum, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.SumBucket, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.StatsBucket, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.ExtendedStatsBucket, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.PercentilesBucket, visitor, (v, d) => v.Visit(d)); - AcceptAggregation(aggregation.Terms, visitor, (v, d) => { v.Visit(d); this.Accept(v, d.Aggregations); }); + AcceptAggregation(aggregation.Terms, visitor, (v, d) => + { + v.Visit(d); + Accept(v, d.Aggregations); + }); AcceptAggregation(aggregation.TopHits, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.ValueCount, visitor, (v, d) => v.Visit(d)); AcceptAggregation(aggregation.GeoCentroid, visitor, (v, d) => v.Visit(d)); diff --git a/src/Nest/Analysis/Analysis.cs b/src/Nest/Analysis/Analysis.cs index 2f3702f02a6..1ff0dc1b4ef 100644 --- a/src/Nest/Analysis/Analysis.cs +++ b/src/Nest/Analysis/Analysis.cs @@ -7,33 +7,37 @@ public interface IAnalysis { [JsonProperty("analyzer")] IAnalyzers Analyzers { get; set; } + [JsonProperty("char_filter")] ICharFilters CharFilters { get; set; } + + [JsonProperty("normalizer")] + INormalizers Normalizers { get; set; } + [JsonProperty("filter")] ITokenFilters TokenFilters { get; set; } + [JsonProperty("tokenizer")] ITokenizers Tokenizers { get; set; } - [JsonProperty("normalizer")] - INormalizers Normalizers { get; set; } } public class Analysis : IAnalysis { public IAnalyzers Analyzers { get; set; } public ICharFilters CharFilters { get; set; } - public ITokenFilters TokenFilters { get; set; } - public ITokenizers Tokenizers { get; set; } public INormalizers Normalizers { get; set; } + public ITokenFilters TokenFilters { get; set; } + public ITokenizers Tokenizers { get; set; } } public class AnalysisDescriptor : DescriptorBase, IAnalysis { IAnalyzers IAnalysis.Analyzers { get; set; } ICharFilters IAnalysis.CharFilters { get; set; } + INormalizers IAnalysis.Normalizers { get; set; } ITokenFilters IAnalysis.TokenFilters { get; set; } ITokenizers IAnalysis.Tokenizers { get; set; } - INormalizers IAnalysis.Normalizers { get; set; } public AnalysisDescriptor Analyzers(Func> selector) => Assign(a => a.Analyzers = selector?.Invoke(new AnalyzersDescriptor())?.Value); diff --git a/src/Nest/Analysis/Analyzers/AnalyzerBase.cs b/src/Nest/Analysis/Analyzers/AnalyzerBase.cs index 503c0324dd9..321f91597bc 100644 --- a/src/Nest/Analysis/Analyzers/AnalyzerBase.cs +++ b/src/Nest/Analysis/Analyzers/AnalyzerBase.cs @@ -5,11 +5,11 @@ namespace Nest [ContractJsonConverter(typeof(AnalyzerJsonConverter))] public interface IAnalyzer { - [JsonProperty("version")] - string Version { get; set; } - [JsonProperty("type")] string Type { get; } + + [JsonProperty("version")] + string Version { get; set; } } public abstract class AnalyzerBase : IAnalyzer @@ -18,9 +18,9 @@ internal AnalyzerBase() { } protected AnalyzerBase(string type) => Type = type; - public string Version { get; set; } - public virtual string Type { get; protected set; } + + public string Version { get; set; } } public abstract class AnalyzerDescriptorBase @@ -28,11 +28,10 @@ public abstract class AnalyzerDescriptorBase where TAnalyzer : AnalyzerDescriptorBase, TAnalyzerInterface where TAnalyzerInterface : class, IAnalyzer { - string IAnalyzer.Version { get; set; } - string IAnalyzer.Type => this.Type; protected abstract string Type { get; } + string IAnalyzer.Type => Type; + string IAnalyzer.Version { get; set; } public TAnalyzer Version(string version) => Assign(a => a.Version = version); } - } diff --git a/src/Nest/Analysis/Analyzers/AnalyzerJsonConverter.cs b/src/Nest/Analysis/Analyzers/AnalyzerJsonConverter.cs index d47253dfda4..285f019eba3 100644 --- a/src/Nest/Analysis/Analyzers/AnalyzerJsonConverter.cs +++ b/src/Nest/Analysis/Analyzers/AnalyzerJsonConverter.cs @@ -6,9 +6,10 @@ namespace Nest { internal class AnalyzerJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) => true; - public override bool CanWrite => false; public override bool CanRead => true; + public override bool CanWrite => false; + + public override bool CanConvert(Type objectType) => true; public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { @@ -18,7 +19,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist if (typeProperty == null) return null; var typePropertyValue = typeProperty.Value.ToString(); - switch(typePropertyValue) + switch (typePropertyValue) { case "stop": return o.ToObject(ElasticContractResolver.Empty); case "standard": return o.ToObject(ElasticContractResolver.Empty); @@ -33,13 +34,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist default: if (o.Property("tokenizer") != null) return o.ToObject(ElasticContractResolver.Empty); + return o.ToObject(ElasticContractResolver.Empty); } } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotSupportedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); } } diff --git a/src/Nest/Analysis/Analyzers/Analyzers.cs b/src/Nest/Analysis/Analyzers/Analyzers.cs index 4f78b5e4741..da4987729c4 100644 --- a/src/Nest/Analysis/Analyzers/Analyzers.cs +++ b/src/Nest/Analysis/Analyzers/Analyzers.cs @@ -10,11 +10,12 @@ public interface IAnalyzers : IIsADictionary { } public class Analyzers : IsADictionaryBase, IAnalyzers { - public Analyzers() {} + public Analyzers() { } + public Analyzers(IDictionary container) : base(container) { } + public Analyzers(Dictionary container) - : base(container.ToDictionary(kv => kv.Key, kv => kv.Value)) - { } + : base(container.ToDictionary(kv => kv.Key, kv => kv.Value)) { } public void Add(string name, IAnalyzer analyzer) => BackingDictionary.Add(name, analyzer); } @@ -28,8 +29,10 @@ public AnalyzersDescriptor() : base(new Analyzers()) { } /// /// An analyzer of type custom that allows to combine a Tokenizer with zero or more Token Filters, /// and zero or more Char Filters. - /// The custom analyzer accepts a logical/registered name of the tokenizer to use, and a list of - /// logical/registered names of token filters. + /// + /// The custom analyzer accepts a logical/registered name of the tokenizer to use, and a list of + /// logical/registered names of token filters. + /// /// public AnalyzersDescriptor Custom(string name, Func selector) => Assign(name, selector?.Invoke(new CustomAnalyzerDescriptor())); @@ -61,13 +64,17 @@ public AnalyzersDescriptor Simple(string name, Func /// An analyzer of type snowball that uses the standard tokenizer, with standard filter, lowercase filter, stop filter, and snowball filter. - /// The Snowball Analyzer is a stemming analyzer from Lucene that is originally based on the snowball project from snowball.tartarus.org. + /// + /// The Snowball Analyzer is a stemming analyzer from Lucene that is originally based on the snowball project from + /// snowball.tartarus.org. + /// /// public AnalyzersDescriptor Snowball(string name, Func selector) => Assign(name, selector?.Invoke(new SnowballAnalyzerDescriptor())); /// - /// An analyzer of type standard that is built of using Standard Tokenizer, with Standard Token Filter, Lower Case Token Filter, and Stop Token Filter. + /// An analyzer of type standard that is built of using Standard Tokenizer, with Standard Token Filter, Lower Case Token Filter, and Stop Token + /// Filter. /// public AnalyzersDescriptor Standard(string name, Func selector) => Assign(name, selector?.Invoke(new StandardAnalyzerDescriptor())); @@ -98,7 +105,7 @@ public AnalyzersDescriptor Fingerprint(string name, Func selector = null) => Assign(name, selector.InvokeOrDefault(new KuromojiAnalyzerDescriptor())); - /// + /// public AnalyzersDescriptor Nori(string name, Func selector) => Assign(name, selector?.Invoke(new NoriAnalyzerDescriptor())); } diff --git a/src/Nest/Analysis/Analyzers/CustomAnalyzer.cs b/src/Nest/Analysis/Analyzers/CustomAnalyzer.cs index 15b9bb8e860..f87312643a8 100644 --- a/src/Nest/Analysis/Analyzers/CustomAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/CustomAnalyzer.cs @@ -6,8 +6,10 @@ namespace Nest /// /// An analyzer of type custom that allows to combine a Tokenizer with zero or more Token Filters, /// and zero or more Char Filters. - /// The custom analyzer accepts a logical/registered name of the tokenizer to use, and a list of - /// logical/registered names of token filters. + /// + /// The custom analyzer accepts a logical/registered name of the tokenizer to use, and a list of + /// logical/registered names of token filters. + /// /// public interface ICustomAnalyzer : IAnalyzer { @@ -25,35 +27,35 @@ public interface ICustomAnalyzer : IAnalyzer [JsonConverter(typeof(ReadSingleOrEnumerableJsonConverter))] IEnumerable Filter { get; set; } - /// - /// An optional list of logical / registered name of char filters. - /// - [JsonProperty("tokenizer")] - string Tokenizer { get; set; } - /// /// An optional number of positions to increment between each field value of a /// field using this analyzer. /// [JsonProperty("position_offset_gap")] int? PositionOffsetGap { get; set; } + + /// + /// An optional list of logical / registered name of char filters. + /// + [JsonProperty("tokenizer")] + string Tokenizer { get; set; } } public class CustomAnalyzer : AnalyzerBase, ICustomAnalyzer { - public CustomAnalyzer() : base("custom") {} + public CustomAnalyzer() : base("custom") { } - /// - public string Tokenizer { get; set; } + /// + public IEnumerable CharFilter { get; set; } - /// + /// public IEnumerable Filter { get; set; } - /// - public IEnumerable CharFilter { get; set; } - - /// + /// public int? PositionOffsetGap { get; set; } + + /// + public string Tokenizer { get; set; } } public class CustomAnalyzerDescriptor @@ -63,25 +65,25 @@ public class CustomAnalyzerDescriptor IEnumerable ICustomAnalyzer.CharFilter { get; set; } IEnumerable ICustomAnalyzer.Filter { get; set; } - string ICustomAnalyzer.Tokenizer { get; set; } int? ICustomAnalyzer.PositionOffsetGap { get; set; } + string ICustomAnalyzer.Tokenizer { get; set; } - /// + /// public CustomAnalyzerDescriptor Filters(params string[] filters) => Assign(a => a.Filter = filters); - /// + /// public CustomAnalyzerDescriptor Filters(IEnumerable filters) => Assign(a => a.Filter = filters); - /// + /// public CustomAnalyzerDescriptor CharFilters(params string[] charFilters) => Assign(a => a.CharFilter = charFilters); - /// + /// public CustomAnalyzerDescriptor CharFilters(IEnumerable charFilters) => Assign(a => a.CharFilter = charFilters); - /// + /// public CustomAnalyzerDescriptor Tokenizer(string tokenizer) => Assign(a => a.Tokenizer = tokenizer); - /// + /// public CustomAnalyzerDescriptor PositionOffsetGap(int? positionOffsetGap) => Assign(a => a.PositionOffsetGap = positionOffsetGap); } diff --git a/src/Nest/Analysis/Analyzers/FingerprintAnalyzer.cs b/src/Nest/Analysis/Analyzers/FingerprintAnalyzer.cs index 54aafa207bf..1cd281be5e2 100644 --- a/src/Nest/Analysis/Analyzers/FingerprintAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/FingerprintAnalyzer.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; using Newtonsoft.Json; namespace Nest @@ -13,12 +9,6 @@ namespace Nest /// public interface IFingerprintAnalyzer : IAnalyzer { - /// - /// The character that separates the tokens after concatenation. Defaults to a space. - /// - [JsonProperty("separator")] - string Separator { get; set; } - /// /// The maximum token size to emit. Defaults to 255. /// @@ -32,6 +22,12 @@ public interface IFingerprintAnalyzer : IAnalyzer [JsonProperty("preserve_original")] bool? PreserveOriginal { get; set; } + /// + /// The character that separates the tokens after concatenation. Defaults to a space. + /// + [JsonProperty("separator")] + string Separator { get; set; } + /// /// A list of stop words to use. Defaults to an empty list /// @@ -43,7 +39,7 @@ public interface IFingerprintAnalyzer : IAnalyzer /// A path(either relative to config location, or absolute) to a stopwords /// file configuration.Each stop word should be in its own "line" /// (separated by a line break). The file must be UTF-8 encoded. - /// + /// [JsonProperty("stopwords_path")] string StopWordsPath { get; set; } } @@ -51,28 +47,27 @@ public interface IFingerprintAnalyzer : IAnalyzer /// public class FingerprintAnalyzer : AnalyzerBase, IFingerprintAnalyzer { - public FingerprintAnalyzer() : base("fingerprint") {} - - public string Separator { get; set; } + public FingerprintAnalyzer() : base("fingerprint") { } public int? MaxOutputSize { get; set; } public bool? PreserveOriginal { get; set; } + public string Separator { get; set; } + public StopWords StopWords { get; set; } public string StopWordsPath { get; set; } } - /// - public class FingerprintAnalyzerDescriptor : - AnalyzerDescriptorBase, IFingerprintAnalyzer + /// + public class FingerprintAnalyzerDescriptor : AnalyzerDescriptorBase, IFingerprintAnalyzer { protected override string Type => "fingerprint"; - - string IFingerprintAnalyzer.Separator { get; set; } int? IFingerprintAnalyzer.MaxOutputSize { get; set; } bool? IFingerprintAnalyzer.PreserveOriginal { get; set; } + + string IFingerprintAnalyzer.Separator { get; set; } StopWords IFingerprintAnalyzer.StopWords { get; set; } string IFingerprintAnalyzer.StopWordsPath { get; set; } diff --git a/src/Nest/Analysis/Analyzers/KeywordAnalyzer.cs b/src/Nest/Analysis/Analyzers/KeywordAnalyzer.cs index 2237df6f07f..f0408b88e77 100644 --- a/src/Nest/Analysis/Analyzers/KeywordAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/KeywordAnalyzer.cs @@ -5,13 +5,14 @@ /// Note, when using mapping definitions, it make more sense to simply mark the field as not_analyzed. /// public interface IKeywordAnalyzer : IAnalyzer { } - /// + + /// public class KeywordAnalyzer : AnalyzerBase, IKeywordAnalyzer { - public KeywordAnalyzer() : base("keyword") {} + public KeywordAnalyzer() : base("keyword") { } } - /// + /// public class KeywordAnalyzerDescriptor : AnalyzerDescriptorBase, IKeywordAnalyzer { diff --git a/src/Nest/Analysis/Analyzers/LanguageAnalyzer.cs b/src/Nest/Analysis/Analyzers/LanguageAnalyzer.cs index a0645e3f57d..09e5722be79 100644 --- a/src/Nest/Analysis/Analyzers/LanguageAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/LanguageAnalyzer.cs @@ -9,6 +9,12 @@ namespace Nest /// public interface ILanguageAnalyzer : IAnalyzer { + /// + /// The stem_exclusion parameter allows you to specify an array of lowercase words that should not be stemmed. + /// + [JsonProperty("stem_exclusion")] + IEnumerable StemExclusionList { get; set; } + /// /// A list of stopword to initialize the stop filter with. Defaults to the english stop words. /// @@ -16,12 +22,6 @@ public interface ILanguageAnalyzer : IAnalyzer [JsonConverter(typeof(StopWordsJsonConverter))] StopWords StopWords { get; set; } - /// - /// The stem_exclusion parameter allows you to specify an array of lowercase words that should not be stemmed. - /// - [JsonProperty("stem_exclusion")] - IEnumerable StemExclusionList { get; set; } - /// /// A path (either relative to config location, or absolute) to a stopwords file configuration. /// @@ -29,51 +29,55 @@ public interface ILanguageAnalyzer : IAnalyzer string StopwordsPath { get; set; } } - /// + /// public class LanguageAnalyzer : AnalyzerBase, ILanguageAnalyzer { private string _type = "language"; - public override string Type + + /// + [JsonIgnore] + public Language? Language { - get { return _type; } - protected set { this._type = value; this.Language = value.ToEnum(); } + get => _type.ToEnum(); + set => _type = value.GetStringValue().ToLowerInvariant(); } - /// - public StopWords StopWords { get; set; } - - /// + /// public IEnumerable StemExclusionList { get; set; } - /// - [JsonIgnore] - public Language? Language { - get { return _type.ToEnum(); } - set { _type = value.GetStringValue().ToLowerInvariant(); } - } + /// + public StopWords StopWords { get; set; } - /// + /// public string StopwordsPath { get; set; } + + public override string Type + { + get => _type; + protected set + { + _type = value; + Language = value.ToEnum(); + } + } } - /// - public class LanguageAnalyzerDescriptor : - AnalyzerDescriptorBase, ILanguageAnalyzer + /// + public class LanguageAnalyzerDescriptor : AnalyzerDescriptorBase, ILanguageAnalyzer { private string _type = "language"; protected override string Type => _type; + IEnumerable ILanguageAnalyzer.StemExclusionList { get; set; } StopWords ILanguageAnalyzer.StopWords { get; set; } - IEnumerable ILanguageAnalyzer.StemExclusionList { get; set; } string ILanguageAnalyzer.StopwordsPath { get; set; } - public LanguageAnalyzerDescriptor Language(Language? language) => Assign(a => this._type = language?.GetStringValue().ToLowerInvariant()); + public LanguageAnalyzerDescriptor Language(Language? language) => Assign(a => _type = language?.GetStringValue().ToLowerInvariant()); public LanguageAnalyzerDescriptor StopWords(StopWords stopWords) => Assign(a => a.StopWords = stopWords); public LanguageAnalyzerDescriptor StopWords(params string[] stopWords) => Assign(a => a.StopWords = stopWords); public LanguageAnalyzerDescriptor StopWords(IEnumerable stopWords) => Assign(a => a.StopWords = stopWords.ToListOrNullIfEmpty()); - } } diff --git a/src/Nest/Analysis/Analyzers/NoriAnalyzer.cs b/src/Nest/Analysis/Analyzers/NoriAnalyzer.cs index 010caad0020..6471b724ff8 100644 --- a/src/Nest/Analysis/Analyzers/NoriAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/NoriAnalyzer.cs @@ -4,55 +4,55 @@ namespace Nest { /// - ///The nori analyzer consists of the following tokenizer and token filters: - /// - nori_tokenizer - /// - nori_part_of_speech token filter - /// - nori_readingform token filter - /// - lowercase token filter + /// The nori analyzer consists of the following tokenizer and token filters: + /// - nori_tokenizer + /// - nori_part_of_speech token filter + /// - nori_readingform token filter + /// - lowercase token filter /// public interface INoriAnalyzer : IAnalyzer { - /// + /// [JsonProperty("decompound_mode")] NoriDecompoundMode? DecompoundMode { get; set; } - /// - [JsonProperty("user_dictionary")] - string UserDictionary { get; set; } - - /// + /// [JsonProperty("stoptags")] IEnumerable StopTags { get; set; } + + /// + [JsonProperty("user_dictionary")] + string UserDictionary { get; set; } } - /// + /// public class NoriAnalyzer : AnalyzerBase, INoriAnalyzer { - public NoriAnalyzer() : base("nori") {} - - /// - public NoriDecompoundMode? DecompoundMode { get; set; } + public NoriAnalyzer() : base("nori") { } - /// - public string UserDictionary { get; set; } + /// + public NoriDecompoundMode? DecompoundMode { get; set; } /// public IEnumerable StopTags { get; set; } + + /// + public string UserDictionary { get; set; } } - /// + /// public class NoriAnalyzerDescriptor : AnalyzerDescriptorBase, INoriAnalyzer { protected override string Type => "nori"; - NoriDecompoundMode? INoriAnalyzer.DecompoundMode { get; set; } - string INoriAnalyzer.UserDictionary { get; set; } + NoriDecompoundMode? INoriAnalyzer.DecompoundMode { get; set; } IEnumerable INoriAnalyzer.StopTags { get; set; } + string INoriAnalyzer.UserDictionary { get; set; } - /// + /// public NoriAnalyzerDescriptor DecompoundMode(NoriDecompoundMode? mode) => Assign(a => a.DecompoundMode = mode); - /// + /// public NoriAnalyzerDescriptor UserDictionary(string path) => Assign(a => a.UserDictionary = path); /// @@ -60,6 +60,5 @@ public class NoriAnalyzerDescriptor : AnalyzerDescriptorBase public NoriAnalyzerDescriptor StopTags(params string[] stopTags) => Assign(a => a.StopTags = stopTags); - } } diff --git a/src/Nest/Analysis/Analyzers/PatternAnalyzer.cs b/src/Nest/Analysis/Analyzers/PatternAnalyzer.cs index b296023fbca..22aca44aaea 100644 --- a/src/Nest/Analysis/Analyzers/PatternAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/PatternAnalyzer.cs @@ -8,15 +8,15 @@ namespace Nest /// public interface IPatternAnalyzer : IAnalyzer { + [JsonProperty("flags")] + string Flags { get; set; } + [JsonProperty("lowercase")] bool? Lowercase { get; set; } [JsonProperty("pattern")] string Pattern { get; set; } - [JsonProperty("flags")] - string Flags { get; set; } - /// /// A list of stopword to initialize the stop filter with. Defaults to an empty list /// @@ -25,30 +25,29 @@ public interface IPatternAnalyzer : IAnalyzer StopWords StopWords { get; set; } } - /// + /// public class PatternAnalyzer : AnalyzerBase, IPatternAnalyzer { - public PatternAnalyzer() : base("pattern") {} + public PatternAnalyzer() : base("pattern") { } + + public string Flags { get; set; } public bool? Lowercase { get; set; } public string Pattern { get; set; } - public string Flags { get; set; } - public StopWords StopWords { get; set; } } - /// - public class PatternAnalyzerDescriptor : - AnalyzerDescriptorBase, IPatternAnalyzer + /// + public class PatternAnalyzerDescriptor : AnalyzerDescriptorBase, IPatternAnalyzer { protected override string Type => "pattern"; - - StopWords IPatternAnalyzer.StopWords { get; set; } - string IPatternAnalyzer.Pattern { get; set; } string IPatternAnalyzer.Flags { get; set; } bool? IPatternAnalyzer.Lowercase { get; set; } + string IPatternAnalyzer.Pattern { get; set; } + + StopWords IPatternAnalyzer.StopWords { get; set; } public PatternAnalyzerDescriptor StopWords(params string[] stopWords) => Assign(a => a.StopWords = stopWords); @@ -62,6 +61,5 @@ public PatternAnalyzerDescriptor StopWords(IEnumerable stopWords) => public PatternAnalyzerDescriptor Flags(string flags) => Assign(a => a.Flags = flags); public PatternAnalyzerDescriptor Lowercase(bool? lowercase = true) => Assign(a => a.Lowercase = lowercase); - } } diff --git a/src/Nest/Analysis/Analyzers/SimpleAnalyzer.cs b/src/Nest/Analysis/Analyzers/SimpleAnalyzer.cs index da24bec09e9..cf914acf2ae 100644 --- a/src/Nest/Analysis/Analyzers/SimpleAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/SimpleAnalyzer.cs @@ -5,15 +5,14 @@ /// public interface ISimpleAnalyzer : IAnalyzer { } - /// + /// public class SimpleAnalyzer : AnalyzerBase, ISimpleAnalyzer { - public SimpleAnalyzer() : base("simple") {} + public SimpleAnalyzer() : base("simple") { } } - /// - public class SimpleAnalyzerDescriptor : - AnalyzerDescriptorBase, ISimpleAnalyzer + /// + public class SimpleAnalyzerDescriptor : AnalyzerDescriptorBase, ISimpleAnalyzer { protected override string Type => "simple"; } diff --git a/src/Nest/Analysis/Analyzers/SnowballAnalyzer.cs b/src/Nest/Analysis/Analyzers/SnowballAnalyzer.cs index 8461163b15e..398c210710a 100644 --- a/src/Nest/Analysis/Analyzers/SnowballAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/SnowballAnalyzer.cs @@ -5,7 +5,10 @@ namespace Nest { /// /// An analyzer of type snowball that uses the standard tokenizer, with standard filter, lowercase filter, stop filter, and snowball filter. - /// The Snowball Analyzer is a stemming analyzer from Lucene that is originally based on the snowball project from snowball.tartarus.org. + /// + /// The Snowball Analyzer is a stemming analyzer from Lucene that is originally based on the snowball project from + /// snowball.tartarus.org. + /// /// public interface ISnowballAnalyzer : IAnalyzer { @@ -16,29 +19,31 @@ public interface ISnowballAnalyzer : IAnalyzer [JsonConverter(typeof(StopWordsJsonConverter))] StopWords StopWords { get; set; } } - /// + + /// public class SnowballAnalyzer : AnalyzerBase, ISnowballAnalyzer { - public SnowballAnalyzer() : base("snowball") {} + public SnowballAnalyzer() : base("snowball") { } public SnowballLanguage? Language { get; set; } public StopWords StopWords { get; set; } } - /// - public class SnowballAnalyzerDescriptor : - AnalyzerDescriptorBase, ISnowballAnalyzer + + /// + public class SnowballAnalyzerDescriptor : AnalyzerDescriptorBase, ISnowballAnalyzer { protected override string Type => "snowball"; + SnowballLanguage? ISnowballAnalyzer.Language { get; set; } StopWords ISnowballAnalyzer.StopWords { get; set; } - SnowballLanguage? ISnowballAnalyzer.Language { get; set; } public SnowballAnalyzerDescriptor StopWords(StopWords stopWords) => Assign(a => a.StopWords = stopWords); + public SnowballAnalyzerDescriptor StopWords(IEnumerable stopWords) => Assign(a => a.StopWords = stopWords.ToListOrNullIfEmpty()); + public SnowballAnalyzerDescriptor StopWords(params string[] stopWords) => Assign(a => a.StopWords = stopWords.ToListOrNullIfEmpty()); public SnowballAnalyzerDescriptor Language(SnowballLanguage? language) => Assign(a => a.Language = language); - } } diff --git a/src/Nest/Analysis/Analyzers/StandardAnalyzer.cs b/src/Nest/Analysis/Analyzers/StandardAnalyzer.cs index 6b591d8012f..58403a946a8 100644 --- a/src/Nest/Analysis/Analyzers/StandardAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/StandardAnalyzer.cs @@ -4,44 +4,44 @@ namespace Nest { /// - /// An analyzer of type standard that is built of using Standard Tokenizer, with Standard Token Filter, Lower Case Token Filter, and Stop Token Filter. + /// An analyzer of type standard that is built of using Standard Tokenizer, with Standard Token Filter, Lower Case Token Filter, and Stop Token + /// Filter. /// public interface IStandardAnalyzer : IAnalyzer { + /// + /// The maximum token length. If a token is seen that exceeds this length then it is discarded. Defaults to 255. + /// + [JsonProperty("max_token_length")] + int? MaxTokenLength { get; set; } + /// /// A list of stopword to initialize the stop filter with. Defaults to the english stop words. /// [JsonProperty("stopwords")] [JsonConverter(typeof(StopWordsJsonConverter))] StopWords StopWords { get; set; } - - /// - /// The maximum token length. If a token is seen that exceeds this length then it is discarded. Defaults to 255. - /// - [JsonProperty("max_token_length")] - int? MaxTokenLength { get; set; } } - /// + /// public class StandardAnalyzer : AnalyzerBase, IStandardAnalyzer { - public StandardAnalyzer() : base("standard") {} + public StandardAnalyzer() : base("standard") { } - /// - public StopWords StopWords { get; set; } - - /// + /// public int? MaxTokenLength { get; set; } + + /// + public StopWords StopWords { get; set; } } - /// - public class StandardAnalyzerDescriptor : - AnalyzerDescriptorBase, IStandardAnalyzer + /// + public class StandardAnalyzerDescriptor : AnalyzerDescriptorBase, IStandardAnalyzer { protected override string Type => "standard"; + int? IStandardAnalyzer.MaxTokenLength { get; set; } StopWords IStandardAnalyzer.StopWords { get; set; } - int? IStandardAnalyzer.MaxTokenLength { get; set; } public StandardAnalyzerDescriptor StopWords(params string[] stopWords) => Assign(a => a.StopWords = stopWords); @@ -53,6 +53,5 @@ public StandardAnalyzerDescriptor StopWords(IEnumerable stopWords) => public StandardAnalyzerDescriptor MaxTokenLength(int? maxTokenLength) => Assign(a => a.MaxTokenLength = maxTokenLength); - } } diff --git a/src/Nest/Analysis/Analyzers/StopAnalyzer.cs b/src/Nest/Analysis/Analyzers/StopAnalyzer.cs index 3dde8b4938b..d3be89a7195 100644 --- a/src/Nest/Analysis/Analyzers/StopAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/StopAnalyzer.cs @@ -22,21 +22,20 @@ public interface IStopAnalyzer : IAnalyzer string StopwordsPath { get; set; } } - /// + /// public class StopAnalyzer : AnalyzerBase, IStopAnalyzer { - public StopAnalyzer() : base("stop") {} + public StopAnalyzer() : base("stop") { } - /// + /// public StopWords StopWords { get; set; } - /// + /// public string StopwordsPath { get; set; } } - /// - public class StopAnalyzerDescriptor : - AnalyzerDescriptorBase, IStopAnalyzer + /// + public class StopAnalyzerDescriptor : AnalyzerDescriptorBase, IStopAnalyzer { protected override string Type => "stop"; @@ -51,6 +50,5 @@ public StopAnalyzerDescriptor StopWords(IEnumerable stopWords) => public StopAnalyzerDescriptor StopWords(StopWords stopWords) => Assign(a => a.StopWords = stopWords); public StopAnalyzerDescriptor StopwordsPath(string path) => Assign(a => a.StopwordsPath = path); - } } diff --git a/src/Nest/Analysis/Analyzers/WhitespaceAnalyzer.cs b/src/Nest/Analysis/Analyzers/WhitespaceAnalyzer.cs index 582ad72ca80..8a268b735ea 100644 --- a/src/Nest/Analysis/Analyzers/WhitespaceAnalyzer.cs +++ b/src/Nest/Analysis/Analyzers/WhitespaceAnalyzer.cs @@ -5,15 +5,14 @@ /// public interface IWhitespaceAnalyzer : IAnalyzer { } - /// + /// public class WhitespaceAnalyzer : AnalyzerBase, IWhitespaceAnalyzer { - public WhitespaceAnalyzer() : base("whitespace") {} + public WhitespaceAnalyzer() : base("whitespace") { } } - /// - public class WhitespaceAnalyzerDescriptor : - AnalyzerDescriptorBase, IWhitespaceAnalyzer + /// + public class WhitespaceAnalyzerDescriptor : AnalyzerDescriptorBase, IWhitespaceAnalyzer { protected override string Type => "whitespace"; } diff --git a/src/Nest/Analysis/CharFilters/CharFilterBase.cs b/src/Nest/Analysis/CharFilters/CharFilterBase.cs index c7595d1cb0c..bb33a8bce76 100644 --- a/src/Nest/Analysis/CharFilters/CharFilterBase.cs +++ b/src/Nest/Analysis/CharFilters/CharFilterBase.cs @@ -5,23 +5,20 @@ namespace Nest [ContractJsonConverter(typeof(CharFilterJsonConverter))] public interface ICharFilter { - [JsonProperty("version")] - string Version { get; set; } - [JsonProperty("type")] string Type { get; } + + [JsonProperty("version")] + string Version { get; set; } } public abstract class CharFilterBase : ICharFilter { - protected CharFilterBase(string type) - { - this.Type = type; - } - public string Version { get; set; } + protected CharFilterBase(string type) => Type = type; public string Type { get; protected set; } + public string Version { get; set; } } public abstract class CharFilterDescriptorBase @@ -29,10 +26,10 @@ public abstract class CharFilterDescriptorBase, TCharFilterInterface where TCharFilterInterface : class, ICharFilter { - string ICharFilter.Version { get; set; } - string ICharFilter.Type => this.Type; protected abstract string Type { get; } + string ICharFilter.Type => Type; + string ICharFilter.Version { get; set; } public TCharFilter Version(string version) => Assign(a => a.Version = version); } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/CharFilters/CharFilterJsonConverter.cs b/src/Nest/Analysis/CharFilters/CharFilterJsonConverter.cs index ffa0a912e76..ecc332bd960 100644 --- a/src/Nest/Analysis/CharFilters/CharFilterJsonConverter.cs +++ b/src/Nest/Analysis/CharFilters/CharFilterJsonConverter.cs @@ -6,19 +6,20 @@ namespace Nest { internal class CharFilterJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) => true; - public override bool CanWrite => false; public override bool CanRead => true; + public override bool CanWrite => false; + + public override bool CanConvert(Type objectType) => true; public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - JObject o = JObject.Load(reader); + var o = JObject.Load(reader); - JProperty typeProperty = o.Property("type"); + var typeProperty = o.Property("type"); if (typeProperty == null) return null; var typePropertyValue = typeProperty.Value.ToString(); - switch(typePropertyValue) + switch (typePropertyValue) { case "html_strip": return o.ToObject(ElasticContractResolver.Empty); case "mapping": return o.ToObject(ElasticContractResolver.Empty); @@ -29,9 +30,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return null; } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotSupportedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); } } diff --git a/src/Nest/Analysis/CharFilters/CharFilters.cs b/src/Nest/Analysis/CharFilters/CharFilters.cs index 01124d2e7b9..2e8a67019aa 100644 --- a/src/Nest/Analysis/CharFilters/CharFilters.cs +++ b/src/Nest/Analysis/CharFilters/CharFilters.cs @@ -10,11 +10,12 @@ public interface ICharFilters : IIsADictionary { } public class CharFilters : IsADictionaryBase, ICharFilters { - public CharFilters() {} + public CharFilters() { } + public CharFilters(IDictionary container) : base(container) { } + public CharFilters(Dictionary container) - : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) - {} + : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) { } public void Add(string name, ICharFilter analyzer) => BackingDictionary.Add(name, analyzer); } @@ -47,14 +48,17 @@ public CharFiltersDescriptor Mapping(string name, Func - public CharFiltersDescriptor KuromojiIterationMark(string name, Func selector = null) => + public CharFiltersDescriptor KuromojiIterationMark(string name, + Func selector = null + ) => Assign(name, selector?.InvokeOrDefault(new KuromojiIterationMarkCharFilterDescriptor())); /// /// Normalizes as defined here: http://userguide.icu-project.org/transforms/normalization /// Part of the `analysis-icu` plugin: https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-icu.html /// - public CharFiltersDescriptor IcuNormalization(string name, Func selector) => + public CharFiltersDescriptor IcuNormalization(string name, Func selector + ) => Assign(name, selector?.Invoke(new IcuNormalizationCharFilterDescriptor())); } } diff --git a/src/Nest/Analysis/CharFilters/HtmlStripCharFilter.cs b/src/Nest/Analysis/CharFilters/HtmlStripCharFilter.cs index e0265b12bc3..2f7b667f3ad 100644 --- a/src/Nest/Analysis/CharFilters/HtmlStripCharFilter.cs +++ b/src/Nest/Analysis/CharFilters/HtmlStripCharFilter.cs @@ -4,17 +4,17 @@ /// A char filter of type html_strip stripping out HTML elements from an analyzed text. /// public interface IHtmlStripCharFilter : ICharFilter { } - /// + + /// public class HtmlStripCharFilter : CharFilterBase, IHtmlStripCharFilter { public HtmlStripCharFilter() : base("html_strip") { } } - /// - public class HtmlStripCharFilterDescriptor + /// + public class HtmlStripCharFilterDescriptor : CharFilterDescriptorBase, IHtmlStripCharFilter { protected override string Type => "html_strip"; } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/CharFilters/MappingCharFilter.cs b/src/Nest/Analysis/CharFilters/MappingCharFilter.cs index ed42c97fda3..7cb35ea081e 100644 --- a/src/Nest/Analysis/CharFilters/MappingCharFilter.cs +++ b/src/Nest/Analysis/CharFilters/MappingCharFilter.cs @@ -14,37 +14,37 @@ public interface IMappingCharFilter : ICharFilter [JsonProperty("mappings_path")] string MappingsPath { get; set; } } - /// + + /// public class MappingCharFilter : CharFilterBase, IMappingCharFilter { public MappingCharFilter() : base("mapping") { } - /// + /// public IEnumerable Mappings { get; set; } - /// + /// public string MappingsPath { get; set; } } - /// - public class MappingCharFilterDescriptor + /// + public class MappingCharFilterDescriptor : CharFilterDescriptorBase, IMappingCharFilter { protected override string Type => "mapping"; IEnumerable IMappingCharFilter.Mappings { get; set; } string IMappingCharFilter.MappingsPath { get; set; } - /// + /// public MappingCharFilterDescriptor Mappings(params string[] mappings) => Assign(a => a.Mappings = mappings); - /// + /// public MappingCharFilterDescriptor Mappings(IEnumerable mappings) => Assign(a => a.Mappings = mappings); - /// + /// public MappingCharFilterDescriptor MappingsPath(string path) => Assign(a => a.MappingsPath = path); - } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/CharFilters/PatternReplaceCharFilter.cs b/src/Nest/Analysis/CharFilters/PatternReplaceCharFilter.cs index 308839f181a..2e5f549a47d 100644 --- a/src/Nest/Analysis/CharFilters/PatternReplaceCharFilter.cs +++ b/src/Nest/Analysis/CharFilters/PatternReplaceCharFilter.cs @@ -3,7 +3,7 @@ namespace Nest { /// - /// The pattern_replace char filter allows the use of a regex to manipulate the characters in a string before analysis. + /// The pattern_replace char filter allows the use of a regex to manipulate the characters in a string before analysis. /// public interface IPatternReplaceCharFilter : ICharFilter { @@ -13,33 +13,33 @@ public interface IPatternReplaceCharFilter : ICharFilter [JsonProperty("replacement")] string Replacement { get; set; } } - - /// + + /// public class PatternReplaceCharFilter : CharFilterBase, IPatternReplaceCharFilter { public PatternReplaceCharFilter() : base("pattern_replace") { } - /// + /// public string Pattern { get; set; } - /// + /// public string Replacement { get; set; } } - /// - public class PatternReplaceCharFilterDescriptor + + /// + public class PatternReplaceCharFilterDescriptor : CharFilterDescriptorBase, IPatternReplaceCharFilter { protected override string Type => "pattern_replace"; string IPatternReplaceCharFilter.Pattern { get; set; } string IPatternReplaceCharFilter.Replacement { get; set; } - /// + /// public PatternReplaceCharFilterDescriptor Pattern(string pattern) => Assign(a => a.Pattern = pattern); - /// + /// public PatternReplaceCharFilterDescriptor Replacement(string replacement) => Assign(a => a.Replacement = replacement); - } } diff --git a/src/Nest/Analysis/Languages/Language.cs b/src/Nest/Analysis/Languages/Language.cs index 3ac32c0e0a9..0e897ef4a53 100644 --- a/src/Nest/Analysis/Languages/Language.cs +++ b/src/Nest/Analysis/Languages/Language.cs @@ -9,38 +9,38 @@ namespace Nest [JsonConverter(typeof(StringEnumConverter))] public enum Language { - Arabic, - Armenian, - Basque, - Brazilian, - Bulgarian, - Catalan, - Chinese, - Cjk, - Czech, - Danish, - Dutch, - English, - Finnish, - French, - Galician, - German, - Greek, - Hindi, - Hungarian, - Indonesian, - Irish, - Italian, + Arabic, + Armenian, + Basque, + Brazilian, + Bulgarian, + Catalan, + Chinese, + Cjk, + Czech, + Danish, + Dutch, + English, + Finnish, + French, + Galician, + German, + Greek, + Hindi, + Hungarian, + Indonesian, + Irish, + Italian, Latvian, - Norwegian, - Persian, - Portuguese, - Romanian, - Russian, + Norwegian, + Persian, + Portuguese, + Romanian, + Russian, Sorani, - Spanish, - Swedish, - Turkish, + Spanish, + Swedish, + Turkish, Thai } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Languages/SnowballLanguage.cs b/src/Nest/Analysis/Languages/SnowballLanguage.cs index 9d8bb4d997a..a2e2023983b 100644 --- a/src/Nest/Analysis/Languages/SnowballLanguage.cs +++ b/src/Nest/Analysis/Languages/SnowballLanguage.cs @@ -5,54 +5,75 @@ namespace Nest { /// - /// Snowball compatible languages + /// Snowball compatible languages /// [JsonConverter(typeof(StringEnumConverter))] public enum SnowballLanguage { - [EnumMember(Value="Armenian")] + [EnumMember(Value = "Armenian")] Armenian, - [EnumMember(Value="Basque")] + + [EnumMember(Value = "Basque")] Basque, - [EnumMember(Value="Catalan")] + + [EnumMember(Value = "Catalan")] Catalan, - [EnumMember(Value="Danish")] + + [EnumMember(Value = "Danish")] Danish, - [EnumMember(Value="Dutch")] + + [EnumMember(Value = "Dutch")] Dutch, - [EnumMember(Value="English")] + + [EnumMember(Value = "English")] English, - [EnumMember(Value="Finnish")] + + [EnumMember(Value = "Finnish")] Finnish, - [EnumMember(Value="French")] + + [EnumMember(Value = "French")] French, - [EnumMember(Value="German")] + + [EnumMember(Value = "German")] German, - [EnumMember(Value="German2")] + + [EnumMember(Value = "German2")] German2, - [EnumMember(Value="Hungarian")] + + [EnumMember(Value = "Hungarian")] Hungarian, - [EnumMember(Value="Italian")] + + [EnumMember(Value = "Italian")] Italian, - [EnumMember(Value="Kp")] + + [EnumMember(Value = "Kp")] Kp, - [EnumMember(Value="Lovins")] + + [EnumMember(Value = "Lovins")] Lovins, - [EnumMember(Value="Norwegian")] + + [EnumMember(Value = "Norwegian")] Norwegian, - [EnumMember(Value="Porter")] + + [EnumMember(Value = "Porter")] Porter, - [EnumMember(Value="Portuguese")] + + [EnumMember(Value = "Portuguese")] Portuguese, - [EnumMember(Value="Romanian")] + + [EnumMember(Value = "Romanian")] Romanian, - [EnumMember(Value="Russian")] + + [EnumMember(Value = "Russian")] Russian, - [EnumMember(Value="Spanish")] + + [EnumMember(Value = "Spanish")] Spanish, - [EnumMember(Value="Swedish")] + + [EnumMember(Value = "Swedish")] Swedish, - [EnumMember(Value="Turkish")] + + [EnumMember(Value = "Turkish")] Turkish } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Normalizers/CustomNormalizer.cs b/src/Nest/Analysis/Normalizers/CustomNormalizer.cs index 63bc5630952..dee562fb001 100644 --- a/src/Nest/Analysis/Normalizers/CustomNormalizer.cs +++ b/src/Nest/Analysis/Normalizers/CustomNormalizer.cs @@ -28,19 +28,19 @@ public interface ICustomNormalizer : INormalizer IEnumerable Filter { get; set; } } - /// + /// public class CustomNormalizer : NormalizerBase, ICustomNormalizer { - public CustomNormalizer() : base("custom") {} + public CustomNormalizer() : base("custom") { } - /// - public IEnumerable Filter { get; set; } - - /// + /// public IEnumerable CharFilter { get; set; } + + /// + public IEnumerable Filter { get; set; } } - /// + /// public class CustomNormalizerDescriptor : NormalizerDescriptorBase, ICustomNormalizer { @@ -48,17 +48,17 @@ public class CustomNormalizerDescriptor IEnumerable ICustomNormalizer.CharFilter { get; set; } IEnumerable ICustomNormalizer.Filter { get; set; } - /// + + /// public CustomNormalizerDescriptor Filters(params string[] filters) => Assign(a => a.Filter = filters); - /// + /// public CustomNormalizerDescriptor Filters(IEnumerable filters) => Assign(a => a.Filter = filters); - /// + /// public CustomNormalizerDescriptor CharFilters(params string[] charFilters) => Assign(a => a.CharFilter = charFilters); - /// + /// public CustomNormalizerDescriptor CharFilters(IEnumerable charFilters) => Assign(a => a.CharFilter = charFilters); - } } diff --git a/src/Nest/Analysis/Normalizers/NormalizerBase.cs b/src/Nest/Analysis/Normalizers/NormalizerBase.cs index c34b07df9ca..c745d302494 100644 --- a/src/Nest/Analysis/Normalizers/NormalizerBase.cs +++ b/src/Nest/Analysis/Normalizers/NormalizerBase.cs @@ -5,11 +5,11 @@ namespace Nest [ContractJsonConverter(typeof(NormalizerJsonConverter))] public interface INormalizer { - [JsonProperty("version")] - string Version { get; set; } - [JsonProperty("type")] string Type { get; } + + [JsonProperty("version")] + string Version { get; set; } } public abstract class NormalizerBase : INormalizer @@ -18,9 +18,9 @@ internal NormalizerBase() { } protected NormalizerBase(string type) => Type = type; - public string Version { get; set; } - public virtual string Type { get; protected set; } + + public string Version { get; set; } } public abstract class NormalizerDescriptorBase @@ -28,11 +28,10 @@ public abstract class NormalizerDescriptorBase, TNormalizerInterface where TNormalizerInterface : class, INormalizer { - string INormalizer.Version { get; set; } - string INormalizer.Type => this.Type; protected abstract string Type { get; } + string INormalizer.Type => Type; + string INormalizer.Version { get; set; } public TNormalizer Version(string version) => Assign(a => a.Version = version); } - } diff --git a/src/Nest/Analysis/Normalizers/NormalizerJsonConverter.cs b/src/Nest/Analysis/Normalizers/NormalizerJsonConverter.cs index 6707180f9c2..da84714c085 100644 --- a/src/Nest/Analysis/Normalizers/NormalizerJsonConverter.cs +++ b/src/Nest/Analysis/Normalizers/NormalizerJsonConverter.cs @@ -6,9 +6,10 @@ namespace Nest { internal class NormalizerJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) => true; - public override bool CanWrite => false; public override bool CanRead => true; + public override bool CanWrite => false; + + public override bool CanConvert(Type objectType) => true; public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { @@ -18,16 +19,13 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist if (typeProperty == null) return null; var typePropertyValue = typeProperty.Value.ToString(); - switch(typePropertyValue) + switch (typePropertyValue) { default: return o.ToObject(ElasticContractResolver.Empty); } } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotSupportedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); } } diff --git a/src/Nest/Analysis/Normalizers/Normalizers.cs b/src/Nest/Analysis/Normalizers/Normalizers.cs index 5d4740c0563..41a1fc557a4 100644 --- a/src/Nest/Analysis/Normalizers/Normalizers.cs +++ b/src/Nest/Analysis/Normalizers/Normalizers.cs @@ -10,11 +10,12 @@ public interface INormalizers : IIsADictionary { } public class Normalizers : IsADictionaryBase, INormalizers { - public Normalizers() {} + public Normalizers() { } + public Normalizers(IDictionary container) : base(container) { } + public Normalizers(Dictionary container) - : base(container.ToDictionary(kv => kv.Key, kv => kv.Value)) - { } + : base(container.ToDictionary(kv => kv.Key, kv => kv.Value)) { } public void Add(string name, INormalizer analyzer) => BackingDictionary.Add(name, analyzer); } diff --git a/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationAlternate.cs b/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationAlternate.cs index a9fcf0e4924..5a9911aac36 100644 --- a/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationAlternate.cs +++ b/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationAlternate.cs @@ -11,7 +11,7 @@ namespace Nest [JsonConverter(typeof(StringEnumConverter))] public enum IcuCollationAlternate { - [EnumMember(Value="shifted")] Shifted, - [EnumMember(Value="non-ignorable")] NonIgnorable + [EnumMember(Value = "shifted")] Shifted, + [EnumMember(Value = "non-ignorable")] NonIgnorable } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationCaseFirst.cs b/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationCaseFirst.cs index 218bf231ade..6139a977296 100644 --- a/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationCaseFirst.cs +++ b/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationCaseFirst.cs @@ -11,7 +11,7 @@ namespace Nest [JsonConverter(typeof(StringEnumConverter))] public enum IcuCollationCaseFirst { - [EnumMember(Value="lower")] Lower, - [EnumMember(Value="upper")] Upper + [EnumMember(Value = "lower")] Lower, + [EnumMember(Value = "upper")] Upper } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationDecomposition.cs b/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationDecomposition.cs index c7059697728..0d3ca4aed30 100644 --- a/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationDecomposition.cs +++ b/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationDecomposition.cs @@ -16,7 +16,7 @@ namespace Nest [JsonConverter(typeof(StringEnumConverter))] public enum IcuCollationDecomposition { - [EnumMember(Value="no")] No, - [EnumMember(Value="identical")] Canonical + [EnumMember(Value = "no")] No, + [EnumMember(Value = "identical")] Canonical } } diff --git a/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationStrength.cs b/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationStrength.cs index bd1139c11dc..f3068c91324 100644 --- a/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationStrength.cs +++ b/src/Nest/Analysis/Plugins/Icu/Collation/IcuCollationStrength.cs @@ -17,14 +17,16 @@ public enum IcuCollationStrength /// It is the strongest difference. For example, dictionaries are divided into different sections by /// base character. /// - [EnumMember(Value="primary")] Primary, + [EnumMember(Value = "primary")] Primary, + /// /// Accents in the characters are considered secondary differences (for example, "as" < "às" < "at"). /// Other differences between letters can also be considered secondary differences, depending on /// the language. A secondary difference is ignored when there is a primary difference anywhere /// in the strings. /// - [EnumMember(Value="secondary")] Secondary, + [EnumMember(Value = "secondary")] Secondary, + /// /// Upper and lower case differences in characters are distinguished at tertiary strength /// (for example, "ao" < "Ao" < "aò"). In addition, a variant of a letter differs from the base @@ -32,7 +34,8 @@ public enum IcuCollationStrength /// large and small Kana. A tertiary difference is ignored when there is a primary or secondary /// difference anywhere in the strings. /// - [EnumMember(Value="tertiary")] Tertiary, + [EnumMember(Value = "tertiary")] Tertiary, + /// /// When punctuation is ignored (see Ignoring Punctuations in the User Guide) at PRIMARY to /// TERTIARY strength, an additional strength level can be used to distinguish words with @@ -40,7 +43,8 @@ public enum IcuCollationStrength /// when there is a PRIMARY, SECONDARY or TERTIARY difference. The QUATERNARY strength should /// only be used if ignoring punctuation is required. /// - [EnumMember(Value="quaternary")] Quaternary, + [EnumMember(Value = "quaternary")] Quaternary, + /// /// When all other strengths are equal, the IDENTICAL strength is used as a tiebreaker. /// The Unicode code point values of the NFD form of each string are compared, just in @@ -50,6 +54,6 @@ public enum IcuCollationStrength /// this strength substantially decreases the performance for both comparison and collation key /// generation APIs. This strength also increases the size of the collation key. /// - [EnumMember(Value="identical")] Indentical, + [EnumMember(Value = "identical")] Indentical, } } diff --git a/src/Nest/Analysis/Plugins/Icu/IcuCollationTokenFilter.cs b/src/Nest/Analysis/Plugins/Icu/IcuCollationTokenFilter.cs index d83fcdfc68f..921170ae2b1 100644 --- a/src/Nest/Analysis/Plugins/Icu/IcuCollationTokenFilter.cs +++ b/src/Nest/Analysis/Plugins/Icu/IcuCollationTokenFilter.cs @@ -1,29 +1,36 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { /// - /// Collations are used for sorting documents in a language-specific word order. The icu_collation token filter is available to all indices and defaults to using the DUCET collation, which is a best-effort attempt at language-neutral sorting. + /// Collations are used for sorting documents in a language-specific word order. The icu_collation token filter is available to all indices and + /// defaults to using the DUCET collation, which is a best-effort attempt at language-neutral sorting. /// Part of the `analysis-icu` plugin: https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-icu.html /// public interface IIcuCollationTokenFilter : ITokenFilter { - [JsonProperty("language")] - string Language { get; set; } - - [JsonProperty("country")] - string Country { get; set; } + /// + /// Sets the alternate handling for strength quaternary to be either shifted or non-ignorable. + /// Which boils down to ignoring punctuation and whitespace. + /// + [JsonProperty("alternate")] + IcuCollationAlternate? Alternate { get; set; } - [JsonProperty("variant")] - string Variant { get; set; } + /// + /// Useful to control which case is sorted first when case is not ignored for strength tertiary. + /// The default depends on the collation. + /// + [JsonProperty("caseFirst")] + IcuCollationCaseFirst? CaseFirst { get; set; } /// - /// The strength property determines the minimum level of difference considered significant during comparison. + /// Whether case level sorting is required. When strength is set to primary this will ignore accent differences /// - [JsonProperty("strength")] - IcuCollationStrength? Strength { get; set; } + [JsonProperty("caseLevel")] + bool? CaseLevel { get; set; } + + [JsonProperty("country")] + string Country { get; set; } /// /// Setting this decomposition property to canonical allows the Collator to handle unnormalized text properly, @@ -37,24 +44,13 @@ public interface IIcuCollationTokenFilter : ITokenFilter IcuCollationDecomposition? Decomposition { get; set; } /// - /// Sets the alternate handling for strength quaternary to be either shifted or non-ignorable. - /// Which boils down to ignoring punctuation and whitespace. - /// - [JsonProperty("alternate")] - IcuCollationAlternate? Alternate { get; set; } - - /// - /// Whether case level sorting is required. When strength is set to primary this will ignore accent differences + /// Distinguishing between Katakana and Hiragana characters in quaternary strength. /// - [JsonProperty("caseLevel")] - bool? CaseLevel { get; set; } + [JsonProperty("hiraganaQuaternaryMode")] + bool? HiraganaQuaternaryMode { get; set; } - /// - /// Useful to control which case is sorted first when case is not ignored for strength tertiary. - /// The default depends on the collation. - /// - [JsonProperty("caseFirst")] - IcuCollationCaseFirst? CaseFirst { get; set; } + [JsonProperty("language")] + string Language { get; set; } /// /// Whether digits are sorted according to their numeric representation. @@ -64,87 +60,110 @@ public interface IIcuCollationTokenFilter : ITokenFilter bool? Numeric { get; set; } /// - /// Single character or contraction. Controls what is variable for . + /// The strength property determines the minimum level of difference considered significant during comparison. /// - [JsonProperty("variableTop")] - string VariableTop { get; set; } + [JsonProperty("strength")] + IcuCollationStrength? Strength { get; set; } /// - /// Distinguishing between Katakana and Hiragana characters in quaternary strength. + /// Single character or contraction. Controls what is variable for . /// - [JsonProperty("hiraganaQuaternaryMode")] - bool? HiraganaQuaternaryMode { get; set; } + [JsonProperty("variableTop")] + string VariableTop { get; set; } + + [JsonProperty("variant")] + string Variant { get; set; } } - /// + /// public class IcuCollationTokenFilter : TokenFilterBase, IIcuCollationTokenFilter { public IcuCollationTokenFilter() : base("icu_collation") { } - /// - public string Language { get; set; } - /// - public string Country { get; set; } - /// - public string Variant { get; set; } - /// - public IcuCollationStrength? Strength { get; set; } - /// - public IcuCollationDecomposition? Decomposition { get; set; } - /// + /// public IcuCollationAlternate? Alternate { get; set; } - /// - public bool? CaseLevel { get; set; } - /// + + /// public IcuCollationCaseFirst? CaseFirst { get; set; } - /// + + /// + public bool? CaseLevel { get; set; } + + /// + public string Country { get; set; } + + /// + public IcuCollationDecomposition? Decomposition { get; set; } + + /// + public bool? HiraganaQuaternaryMode { get; set; } + + /// + public string Language { get; set; } + + /// public bool? Numeric { get; set; } - /// + + /// + public IcuCollationStrength? Strength { get; set; } + + /// public string VariableTop { get; set; } - /// - public bool? HiraganaQuaternaryMode { get; set; } + + /// + public string Variant { get; set; } } - /// + /// public class IcuCollationTokenFilterDescriptor : TokenFilterDescriptorBase, IIcuCollationTokenFilter { protected override string Type => "icu_collation"; - - string IIcuCollationTokenFilter.Language { get; set; } - string IIcuCollationTokenFilter.Country { get; set; } - string IIcuCollationTokenFilter.Variant { get; set; } - IcuCollationStrength? IIcuCollationTokenFilter.Strength { get; set; } - IcuCollationDecomposition? IIcuCollationTokenFilter.Decomposition { get; set; } IcuCollationAlternate? IIcuCollationTokenFilter.Alternate { get; set; } - bool? IIcuCollationTokenFilter.CaseLevel { get; set; } IcuCollationCaseFirst? IIcuCollationTokenFilter.CaseFirst { get; set; } + bool? IIcuCollationTokenFilter.CaseLevel { get; set; } + string IIcuCollationTokenFilter.Country { get; set; } + IcuCollationDecomposition? IIcuCollationTokenFilter.Decomposition { get; set; } + bool? IIcuCollationTokenFilter.HiraganaQuaternaryMode { get; set; } + + string IIcuCollationTokenFilter.Language { get; set; } bool? IIcuCollationTokenFilter.Numeric { get; set; } + IcuCollationStrength? IIcuCollationTokenFilter.Strength { get; set; } string IIcuCollationTokenFilter.VariableTop { get; set; } - bool? IIcuCollationTokenFilter.HiraganaQuaternaryMode { get; set; } + string IIcuCollationTokenFilter.Variant { get; set; } - /// + /// public IcuCollationTokenFilterDescriptor Language(string language) => Assign(a => a.Language = language); - /// + + /// public IcuCollationTokenFilterDescriptor Country(string country) => Assign(a => a.Country = country); - /// + + /// public IcuCollationTokenFilterDescriptor Variant(string variant) => Assign(a => a.Variant = variant); - /// + + /// public IcuCollationTokenFilterDescriptor Strength(IcuCollationStrength? strength) => Assign(a => a.Strength = strength); - /// - public IcuCollationTokenFilterDescriptor Decomposition(IcuCollationDecomposition? decomposition) => Assign(a => a.Decomposition = decomposition); - /// + + /// + public IcuCollationTokenFilterDescriptor Decomposition(IcuCollationDecomposition? decomposition) => + Assign(a => a.Decomposition = decomposition); + + /// public IcuCollationTokenFilterDescriptor Alternate(IcuCollationAlternate? alternate) => Assign(a => a.Alternate = alternate); - /// + + /// public IcuCollationTokenFilterDescriptor CaseFirst(IcuCollationCaseFirst? caseFirst) => Assign(a => a.CaseFirst = caseFirst); - /// + + /// public IcuCollationTokenFilterDescriptor CaseLevel(bool? caseLevel = true) => Assign(a => a.CaseLevel = caseLevel); - /// + + /// public IcuCollationTokenFilterDescriptor Numeric(bool? numeric = true) => Assign(a => a.Numeric = numeric); - /// + + /// public IcuCollationTokenFilterDescriptor HiraganaQuaternaryMode(bool? mode = true) => Assign(a => a.HiraganaQuaternaryMode = mode); - /// - public IcuCollationTokenFilterDescriptor VariableTop(string variableTop) => Assign(a => a.VariableTop = variableTop); + /// + public IcuCollationTokenFilterDescriptor VariableTop(string variableTop) => Assign(a => a.VariableTop = variableTop); } } diff --git a/src/Nest/Analysis/Plugins/Icu/IcuFoldingTokenFilter.cs b/src/Nest/Analysis/Plugins/Icu/IcuFoldingTokenFilter.cs index 139e16d3204..ce699f31c26 100644 --- a/src/Nest/Analysis/Plugins/Icu/IcuFoldingTokenFilter.cs +++ b/src/Nest/Analysis/Plugins/Icu/IcuFoldingTokenFilter.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -17,16 +15,16 @@ public interface IIcuFoldingTokenFilter : ITokenFilter string UnicodeSetFilter { get; set; } } - /// + /// public class IcuFoldingTokenFilter : TokenFilterBase, IIcuFoldingTokenFilter { public IcuFoldingTokenFilter() : base("icu_folding") { } - /// + /// public string UnicodeSetFilter { get; set; } } - /// + /// public class IcuFoldingTokenFilterDescriptor : TokenFilterDescriptorBase, IIcuFoldingTokenFilter { @@ -34,7 +32,7 @@ public class IcuFoldingTokenFilterDescriptor string IIcuFoldingTokenFilter.UnicodeSetFilter { get; set; } - /// + /// public IcuFoldingTokenFilterDescriptor UnicodeSetFilter(string filter) => Assign(a => a.UnicodeSetFilter = filter); } diff --git a/src/Nest/Analysis/Plugins/Icu/IcuNormalizationCharFilter.cs b/src/Nest/Analysis/Plugins/Icu/IcuNormalizationCharFilter.cs index 24d4dc3e5e9..057cc091744 100644 --- a/src/Nest/Analysis/Plugins/Icu/IcuNormalizationCharFilter.cs +++ b/src/Nest/Analysis/Plugins/Icu/IcuNormalizationCharFilter.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -9,45 +8,45 @@ namespace Nest /// public interface IIcuNormalizationCharFilter : ICharFilter { - /// - /// The type of normalization - /// - [JsonProperty("name")] - IcuNormalizationType? Name { get; set; } - /// /// Set the mode parameter to decompose to convert nfc to nfd or nfkc to nfkd respectively /// [JsonProperty("mode")] IcuNormalizationMode? Mode { get; set; } + + /// + /// The type of normalization + /// + [JsonProperty("name")] + IcuNormalizationType? Name { get; set; } } - /// + + /// public class IcuNormalizationCharFilter : CharFilterBase, IIcuNormalizationCharFilter { public IcuNormalizationCharFilter() : base("icu_normalizer") { } - /// - public IcuNormalizationType? Name { get; set; } - - /// + /// public IcuNormalizationMode? Mode { get; set; } + + /// + public IcuNormalizationType? Name { get; set; } } - /// + /// public class IcuNormalizationCharFilterDescriptor : CharFilterDescriptorBase, IIcuNormalizationCharFilter { protected override string Type => "icu_normalizer"; - IcuNormalizationType? IIcuNormalizationCharFilter.Name { get; set; } IcuNormalizationMode? IIcuNormalizationCharFilter.Mode { get; set; } + IcuNormalizationType? IIcuNormalizationCharFilter.Name { get; set; } - /// + /// public IcuNormalizationCharFilterDescriptor Name(IcuNormalizationType? name = null) => Assign(a => a.Name = name); - /// + /// public IcuNormalizationCharFilterDescriptor Mode(IcuNormalizationMode? mode = null) => Assign(a => a.Mode = mode); - } } diff --git a/src/Nest/Analysis/Plugins/Icu/IcuNormalizationTokenFilter.cs b/src/Nest/Analysis/Plugins/Icu/IcuNormalizationTokenFilter.cs index 0d21393e121..06c0a02b198 100644 --- a/src/Nest/Analysis/Plugins/Icu/IcuNormalizationTokenFilter.cs +++ b/src/Nest/Analysis/Plugins/Icu/IcuNormalizationTokenFilter.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -17,16 +15,16 @@ public interface IIcuNormalizationTokenFilter : ITokenFilter IcuNormalizationType? Name { get; set; } } - /// + /// public class IcuNormalizationTokenFilter : TokenFilterBase, IIcuNormalizationTokenFilter { public IcuNormalizationTokenFilter() : base("icu_normalizer") { } - /// + /// public IcuNormalizationType? Name { get; set; } } - /// + /// public class IcuNormalizationTokenFilterDescriptor : TokenFilterDescriptorBase, IIcuNormalizationTokenFilter { @@ -34,7 +32,7 @@ public class IcuNormalizationTokenFilterDescriptor IcuNormalizationType? IIcuNormalizationTokenFilter.Name { get; set; } - /// + /// public IcuNormalizationTokenFilterDescriptor Name(IcuNormalizationType? name) => Assign(a => a.Name = name); } } diff --git a/src/Nest/Analysis/Plugins/Icu/IcuTokenizer.cs b/src/Nest/Analysis/Plugins/Icu/IcuTokenizer.cs index 288f69af4a7..1bd9e6c1025 100644 --- a/src/Nest/Analysis/Plugins/Icu/IcuTokenizer.cs +++ b/src/Nest/Analysis/Plugins/Icu/IcuTokenizer.cs @@ -19,16 +19,16 @@ public interface IIcuTokenizer : ITokenizer string RuleFiles { get; set; } } - /// + /// public class IcuTokenizer : TokenizerBase, IIcuTokenizer - { - public IcuTokenizer() { Type = "icu_tokenizer"; } + { + public IcuTokenizer() => Type = "icu_tokenizer"; - /// + /// public string RuleFiles { get; set; } - } + } - /// + /// public class IcuTokenizerDescriptor : TokenizerDescriptorBase, IIcuTokenizer { @@ -36,7 +36,7 @@ public class IcuTokenizerDescriptor string IIcuTokenizer.RuleFiles { get; set; } - /// + /// public IcuTokenizerDescriptor RuleFiles(string ruleFiles) => Assign(a => a.RuleFiles = ruleFiles); } } diff --git a/src/Nest/Analysis/Plugins/Icu/IcuTransformTokenFilter.cs b/src/Nest/Analysis/Plugins/Icu/IcuTransformTokenFilter.cs index ae5eb02f1bb..0542d372f06 100644 --- a/src/Nest/Analysis/Plugins/Icu/IcuTransformTokenFilter.cs +++ b/src/Nest/Analysis/Plugins/Icu/IcuTransformTokenFilter.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -21,18 +19,18 @@ public interface IIcuTransformTokenFilter : ITokenFilter string Id { get; set; } } - /// + /// public class IcuTransformTokenFilter : TokenFilterBase, IIcuTransformTokenFilter { public IcuTransformTokenFilter() : base("icu_transform") { } - /// + /// public IcuTransformDirection? Direction { get; set; } public string Id { get; set; } } - /// + /// public class IcuTransformTokenFilterDescriptor : TokenFilterDescriptorBase, IIcuTransformTokenFilter { @@ -41,10 +39,10 @@ public class IcuTransformTokenFilterDescriptor IcuTransformDirection? IIcuTransformTokenFilter.Direction { get; set; } string IIcuTransformTokenFilter.Id { get; set; } - /// + /// public IcuTransformTokenFilterDescriptor Direction(IcuTransformDirection? direction) => Assign(a => a.Direction = direction); - /// + /// public IcuTransformTokenFilterDescriptor Id(string id) => Assign(a => a.Id = id); } } diff --git a/src/Nest/Analysis/Plugins/Icu/Normalization/IcuNormalizationMode.cs b/src/Nest/Analysis/Plugins/Icu/Normalization/IcuNormalizationMode.cs index 1efca53c301..7164c22c1f5 100644 --- a/src/Nest/Analysis/Plugins/Icu/Normalization/IcuNormalizationMode.cs +++ b/src/Nest/Analysis/Plugins/Icu/Normalization/IcuNormalizationMode.cs @@ -13,13 +13,14 @@ public enum IcuNormalizationMode /// /// Switch normalization type to decompose /// - [EnumMember(Value="decompose")] + [EnumMember(Value = "decompose")] Decompose, + /// /// Switch normalization type to compose, which is the default so you'd never need to set this /// Included here for completeness sake because the Java API has it. /// - [EnumMember(Value="compose")] + [EnumMember(Value = "compose")] Compose } } diff --git a/src/Nest/Analysis/Plugins/Icu/Normalization/IcuNormalizationType.cs b/src/Nest/Analysis/Plugins/Icu/Normalization/IcuNormalizationType.cs index 982061934c4..0824674906d 100644 --- a/src/Nest/Analysis/Plugins/Icu/Normalization/IcuNormalizationType.cs +++ b/src/Nest/Analysis/Plugins/Icu/Normalization/IcuNormalizationType.cs @@ -13,17 +13,19 @@ public enum IcuNormalizationType /// /// Characters are decomposed and then recomposed by canonical equivalence. /// - [EnumMember(Value="nfc")] + [EnumMember(Value = "nfc")] Canonical, + /// /// Characters are decomposed by compatibility, then recomposed by canonical equivalence. /// - [EnumMember(Value="nfkc")] + [EnumMember(Value = "nfkc")] Compatibility, + /// /// Characters are decomposed by compatibility, then recomposed by canonical equivalence with case folding /// - [EnumMember(Value="nfkc_cf")] + [EnumMember(Value = "nfkc_cf")] CompatibilityCaseFold } } diff --git a/src/Nest/Analysis/Plugins/Icu/Transform/IcuNormalizationType.cs b/src/Nest/Analysis/Plugins/Icu/Transform/IcuNormalizationType.cs index f251c8c8ede..08670cc0de8 100644 --- a/src/Nest/Analysis/Plugins/Icu/Transform/IcuNormalizationType.cs +++ b/src/Nest/Analysis/Plugins/Icu/Transform/IcuNormalizationType.cs @@ -11,10 +11,11 @@ namespace Nest public enum IcuTransformDirection { /// LTR - [EnumMember(Value="forward")] + [EnumMember(Value = "forward")] Forward, + /// RTL - [EnumMember(Value="reverse")] + [EnumMember(Value = "reverse")] Reverse, } } diff --git a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiAnalyzer.cs b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiAnalyzer.cs index d99140f0ce6..200a2382162 100644 --- a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiAnalyzer.cs +++ b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiAnalyzer.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -16,19 +15,18 @@ public interface IKuromojiAnalyzer : IAnalyzer string UserDictionary { get; set; } } - /// + /// public class KuromojiAnalyzer : AnalyzerBase, IKuromojiAnalyzer { - public KuromojiAnalyzer() : base("kuromoji") {} + public KuromojiAnalyzer() : base("kuromoji") { } public KuromojiTokenizationMode? Mode { get; set; } public string UserDictionary { get; set; } } - /// - public class KuromojiAnalyzerDescriptor : - AnalyzerDescriptorBase, IKuromojiAnalyzer + /// + public class KuromojiAnalyzerDescriptor : AnalyzerDescriptorBase, IKuromojiAnalyzer { protected override string Type => "kuromoji"; @@ -38,6 +36,5 @@ public class KuromojiAnalyzerDescriptor : public KuromojiAnalyzerDescriptor Mode(KuromojiTokenizationMode? mode) => Assign(a => a.Mode = mode); public KuromojiAnalyzerDescriptor UserDictionary(string userDictionary) => Assign(a => a.UserDictionary = userDictionary); - } } diff --git a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiIterationMarkCharFilter.cs b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiIterationMarkCharFilter.cs index 9f30fc52c79..b2caf4fa203 100644 --- a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiIterationMarkCharFilter.cs +++ b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiIterationMarkCharFilter.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -9,39 +8,39 @@ namespace Nest /// public interface IKuromojiIterationMarkCharFilter : ICharFilter { - [JsonProperty("normalize_kanji")] - bool? NormalizeKanji { get; set; } - [JsonProperty("normalize_kana")] bool? NormalizeKana { get; set; } + + [JsonProperty("normalize_kanji")] + bool? NormalizeKanji { get; set; } } - /// + + /// public class KuromojiIterationMarkCharFilter : CharFilterBase, IKuromojiIterationMarkCharFilter { public KuromojiIterationMarkCharFilter() : base("kuromoji_iteration_mark") { } - /// - public bool? NormalizeKanji { get; set; } - - /// + /// public bool? NormalizeKana { get; set; } + + /// + public bool? NormalizeKanji { get; set; } } - /// + /// public class KuromojiIterationMarkCharFilterDescriptor : CharFilterDescriptorBase, IKuromojiIterationMarkCharFilter { protected override string Type => "kuromoji_iteration_mark"; - bool? IKuromojiIterationMarkCharFilter.NormalizeKanji { get; set; } bool? IKuromojiIterationMarkCharFilter.NormalizeKana { get; set; } + bool? IKuromojiIterationMarkCharFilter.NormalizeKanji { get; set; } - /// + /// public KuromojiIterationMarkCharFilterDescriptor NormalizeKanji(bool? normalize = true) => Assign(a => a.NormalizeKanji = normalize); - /// + /// public KuromojiIterationMarkCharFilterDescriptor NormalizeKana(bool? normalize = true) => Assign(a => a.NormalizeKana = normalize); - } } diff --git a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiPartOfSpeechTokenFilter.cs b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiPartOfSpeechTokenFilter.cs index b244f976973..2b7a6c9dabb 100644 --- a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiPartOfSpeechTokenFilter.cs +++ b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiPartOfSpeechTokenFilter.cs @@ -17,16 +17,16 @@ public interface IKuromojiPartOfSpeechTokenFilter : ITokenFilter IEnumerable StopTags { get; set; } } - /// + /// public class KuromojiPartOfSpeechTokenFilter : TokenFilterBase, IKuromojiPartOfSpeechTokenFilter { public KuromojiPartOfSpeechTokenFilter() : base("kuromoji_part_of_speech") { } - /// + /// public IEnumerable StopTags { get; set; } } - /// + /// public class KuromojiPartOfSpeechTokenFilterDescriptor : TokenFilterDescriptorBase, IKuromojiPartOfSpeechTokenFilter { @@ -34,12 +34,10 @@ public class KuromojiPartOfSpeechTokenFilterDescriptor IEnumerable IKuromojiPartOfSpeechTokenFilter.StopTags { get; set; } - /// + /// public KuromojiPartOfSpeechTokenFilterDescriptor StopTags(IEnumerable stopTags) => Assign(a => a.StopTags = stopTags); - /// + /// public KuromojiPartOfSpeechTokenFilterDescriptor StopTags(params string[] stopTags) => Assign(a => a.StopTags = stopTags); - } - } diff --git a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiReadingFormTokenFilter.cs b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiReadingFormTokenFilter.cs index 4a3d21f53f6..1a5254dedd0 100644 --- a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiReadingFormTokenFilter.cs +++ b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiReadingFormTokenFilter.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -16,16 +15,16 @@ public interface IKuromojiReadingFormTokenFilter : ITokenFilter bool? UseRomaji { get; set; } } - /// + /// public class KuromojiReadingFormTokenFilter : TokenFilterBase, IKuromojiReadingFormTokenFilter { public KuromojiReadingFormTokenFilter() : base("kuromoji_readingform") { } - /// + /// public bool? UseRomaji { get; set; } } - /// + /// public class KuromojiReadingFormTokenFilterDescriptor : TokenFilterDescriptorBase, IKuromojiReadingFormTokenFilter { @@ -33,10 +32,7 @@ public class KuromojiReadingFormTokenFilterDescriptor bool? IKuromojiReadingFormTokenFilter.UseRomaji { get; set; } - /// + /// public KuromojiReadingFormTokenFilterDescriptor UseRomaji(bool? useRomaji = true) => Assign(a => a.UseRomaji = useRomaji); - - } - } diff --git a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiStemmerTokenFilter.cs b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiStemmerTokenFilter.cs index 503923d2724..d0bd41330c3 100644 --- a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiStemmerTokenFilter.cs +++ b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiStemmerTokenFilter.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -18,16 +16,16 @@ public interface IKuromojiStemmerTokenFilter : ITokenFilter int? MinimumLength { get; set; } } - /// + /// public class KuromojiStemmerTokenFilter : TokenFilterBase, IKuromojiStemmerTokenFilter { public KuromojiStemmerTokenFilter() : base("kuromoji_stemmer") { } - /// + /// public int? MinimumLength { get; set; } } - /// + /// public class KuromojiStemmerTokenFilterDescriptor : TokenFilterDescriptorBase, IKuromojiStemmerTokenFilter { @@ -35,7 +33,7 @@ public class KuromojiStemmerTokenFilterDescriptor int? IKuromojiStemmerTokenFilter.MinimumLength { get; set; } - /// + /// public KuromojiStemmerTokenFilterDescriptor MinimumLength(int? minimumLength) => Assign(a => a.MinimumLength = minimumLength); } } diff --git a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiTokenizationMode.cs b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiTokenizationMode.cs index b66b54429f2..c54073a1d85 100644 --- a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiTokenizationMode.cs +++ b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiTokenizationMode.cs @@ -16,17 +16,18 @@ public enum KuromojiTokenizationMode /// [EnumMember(Value = "normal")] Normal, + /// /// Segmentation geared towards search. This includes a decompounding process for long nouns, /// also including the full compound token as a synonym. /// [EnumMember(Value = "search")] Search, + /// /// Extended mode outputs unigrams for unknown words. /// [EnumMember(Value = "extended")] Extended - } } diff --git a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiTokenizer.cs b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiTokenizer.cs index 7c1eafe9487..a6530100500 100644 --- a/src/Nest/Analysis/Plugins/Kuromoji/KuromojiTokenizer.cs +++ b/src/Nest/Analysis/Plugins/Kuromoji/KuromojiTokenizer.cs @@ -8,12 +8,6 @@ namespace Nest /// public interface IKuromojiTokenizer : ITokenizer { - /// - /// The tokenization mode determines how the tokenizer handles compound and unknown words. - /// - [JsonProperty("mode")] - KuromojiTokenizationMode? Mode { get; set; } - /// /// Whether punctuation should be discarded from the output. Defaults to true. /// @@ -21,74 +15,80 @@ public interface IKuromojiTokenizer : ITokenizer bool? DiscardPunctuation { get; set; } /// - /// The Kuromoji tokenizer uses the MeCab-IPADIC dictionary by default. A user_dictionary may be - /// appended to the default dictionary. + /// The tokenization mode determines how the tokenizer handles compound and unknown words. /// - [JsonProperty("user_dictionary")] - string UserDictionary { get; set; } + [JsonProperty("mode")] + KuromojiTokenizationMode? Mode { get; set; } /// - ///The nbest_examples can be used to find a nbest_cost value based on examples. For example, - /// a value of /箱根山-箱根/成田空港-成田/ indicates that in the texts, 箱根山 (Mt. Hakone) and 成田空港 (Narita Airport) - /// we’d like a cost that gives is us 箱根 (Hakone) and 成田 (Narita). + /// The nbest_cost parameter specifies an additional Viterbi cost. The KuromojiTokenizer will include all tokens in + /// Viterbi paths that are within the nbest_cost value of the best path. + /// + [JsonProperty("nbest_cost")] + int? NBestCost { get; set; } + + /// + /// The nbest_examples can be used to find a nbest_cost value based on examples. For example, + /// a value of /箱根山-箱根/成田空港-成田/ indicates that in the texts, 箱根山 (Mt. Hakone) and 成田空港 (Narita Airport) + /// we’d like a cost that gives is us 箱根 (Hakone) and 成田 (Narita). /// [JsonProperty("nbest_examples")] string NBestExamples { get; set; } /// - /// The nbest_cost parameter specifies an additional Viterbi cost. The KuromojiTokenizer will include all tokens in - /// Viterbi paths that are within the nbest_cost value of the best path. + /// The Kuromoji tokenizer uses the MeCab-IPADIC dictionary by default. A user_dictionary may be + /// appended to the default dictionary. /// - [JsonProperty("nbest_cost")] - int? NBestCost { get; set; } + [JsonProperty("user_dictionary")] + string UserDictionary { get; set; } } - /// + /// public class KuromojiTokenizer : TokenizerBase, IKuromojiTokenizer - { - public KuromojiTokenizer() { Type = "kuromoji_tokenizer"; } - - /// - public KuromojiTokenizationMode? Mode { get; set; } + { + public KuromojiTokenizer() => Type = "kuromoji_tokenizer"; - /// + /// public bool? DiscardPunctuation { get; set; } - /// - public string UserDictionary { get; set; } + /// + public KuromojiTokenizationMode? Mode { get; set; } - /// + /// + public int? NBestCost { get; set; } + + /// public string NBestExamples { get; set; } - /// - public int? NBestCost { get; set; } - } + /// + public string UserDictionary { get; set; } + } - /// + /// public class KuromojiTokenizerDescriptor : TokenizerDescriptorBase, IKuromojiTokenizer { protected override string Type => "kuromoji_tokenizer"; + bool? IKuromojiTokenizer.DiscardPunctuation { get; set; } KuromojiTokenizationMode? IKuromojiTokenizer.Mode { get; set; } - bool? IKuromojiTokenizer.DiscardPunctuation { get; set; } - string IKuromojiTokenizer.UserDictionary { get; set; } - string IKuromojiTokenizer.NBestExamples { get; set; } int? IKuromojiTokenizer.NBestCost { get; set; } + string IKuromojiTokenizer.NBestExamples { get; set; } + string IKuromojiTokenizer.UserDictionary { get; set; } - /// + /// public KuromojiTokenizerDescriptor Mode(KuromojiTokenizationMode? mode) => Assign(a => a.Mode = mode); - /// + /// public KuromojiTokenizerDescriptor DiscardPunctuation(bool? discard = true) => Assign(a => a.DiscardPunctuation = discard); - /// + /// public KuromojiTokenizerDescriptor UserDictionary(string userDictionary) => Assign(a => a.UserDictionary = userDictionary); - /// + /// public KuromojiTokenizerDescriptor NBestExamples(string examples) => Assign(a => a.NBestExamples = examples); - /// + /// public KuromojiTokenizerDescriptor NBestCost(int? cost) => Assign(a => a.NBestCost = cost); } } diff --git a/src/Nest/Analysis/Plugins/Phonetic/PhoneticEncoder.cs b/src/Nest/Analysis/Plugins/Phonetic/PhoneticEncoder.cs index f63aac80e5b..7bf44c11fe7 100644 --- a/src/Nest/Analysis/Plugins/Phonetic/PhoneticEncoder.cs +++ b/src/Nest/Analysis/Plugins/Phonetic/PhoneticEncoder.cs @@ -9,26 +9,37 @@ public enum PhoneticEncoder { [EnumMember(Value = "metaphone")] Metaphone, + [EnumMember(Value = "double_metaphone")] DoubleMetaphone, + [EnumMember(Value = "soundex")] Soundex, + [EnumMember(Value = "refined_soundex")] RefinedSoundex, + [EnumMember(Value = "caverphone1")] Caverphone1, + [EnumMember(Value = "caverphone2")] Caverphone2, + [EnumMember(Value = "cologne")] Cologne, + [EnumMember(Value = "nysiis")] Nysiis, + [EnumMember(Value = "koelnerphonetik")] KoelnerPhonetik, + [EnumMember(Value = "haasephonetik")] HaasePhonetik, + [EnumMember(Value = "beider_morse")] Beidermorse, + [EnumMember(Value = "daitch_mokotoff")] DaitchMokotoff } diff --git a/src/Nest/Analysis/Plugins/Phonetic/PhoneticLanguage.cs b/src/Nest/Analysis/Plugins/Phonetic/PhoneticLanguage.cs index 7f6732228b9..893ded4c559 100644 --- a/src/Nest/Analysis/Plugins/Phonetic/PhoneticLanguage.cs +++ b/src/Nest/Analysis/Plugins/Phonetic/PhoneticLanguage.cs @@ -43,4 +43,4 @@ public enum PhoneticLanguage [EnumMember(Value = "spanish")] Spanish, } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Plugins/Phonetic/PhoneticNameType.cs b/src/Nest/Analysis/Plugins/Phonetic/PhoneticNameType.cs index 54dfd7dd9ef..6aec77c132a 100644 --- a/src/Nest/Analysis/Plugins/Phonetic/PhoneticNameType.cs +++ b/src/Nest/Analysis/Plugins/Phonetic/PhoneticNameType.cs @@ -16,4 +16,4 @@ public enum PhoneticNameType [EnumMember(Value = "sephardic")] Sephardic } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Plugins/Phonetic/PhoneticRuleType.cs b/src/Nest/Analysis/Plugins/Phonetic/PhoneticRuleType.cs index d5ba7190274..ef0674b6074 100644 --- a/src/Nest/Analysis/Plugins/Phonetic/PhoneticRuleType.cs +++ b/src/Nest/Analysis/Plugins/Phonetic/PhoneticRuleType.cs @@ -13,4 +13,4 @@ public enum PhoneticRuleType [EnumMember(Value = "exact")] Exact } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Plugins/Phonetic/PhoneticTokenFilter.cs b/src/Nest/Analysis/Plugins/Phonetic/PhoneticTokenFilter.cs index 63eed861f94..946c80b899f 100644 --- a/src/Nest/Analysis/Plugins/Phonetic/PhoneticTokenFilter.cs +++ b/src/Nest/Analysis/Plugins/Phonetic/PhoneticTokenFilter.cs @@ -19,47 +19,47 @@ public interface IPhoneticTokenFilter : ITokenFilter PhoneticEncoder? Encoder { get; set; } /// - ///The replace parameter (defaults to true) controls if the token processed should be replaced - /// with the encoded one (set it to true), or added (set it to false). + /// An array of languages to check. If not specified, then the language will be guessed /// - [JsonProperty("replace")] - bool? Replace { get; set; } + /// + /// Valid for only + /// + [JsonProperty("languageset")] + IEnumerable LanguageSet { get; set; } /// /// The maximum length of the emitted metaphone token. Defaults to 4 /// /// - /// Valid for only + /// Valid for only /// [JsonProperty("max_code_len")] int? MaxCodeLength { get; set; } - /// - /// Whether matching should be exact or approximate. Defaults to approximate - /// - /// - /// Valid for only - /// - [JsonProperty("rule_type")] - PhoneticRuleType? RuleType { get; set; } - /// /// Whether names are ashkenazi, sephardic, or generic. Defaults to generic /// /// - /// Valid for only + /// Valid for only /// [JsonProperty("name_type")] PhoneticNameType? NameType { get; set; } /// - /// An array of languages to check. If not specified, then the language will be guessed + /// The replace parameter (defaults to true) controls if the token processed should be replaced + /// with the encoded one (set it to true), or added (set it to false). + /// + [JsonProperty("replace")] + bool? Replace { get; set; } + + /// + /// Whether matching should be exact or approximate. Defaults to approximate /// /// - /// Valid for only + /// Valid for only /// - [JsonProperty("languageset")] - IEnumerable LanguageSet { get; set; } + [JsonProperty("rule_type")] + PhoneticRuleType? RuleType { get; set; } } /// @@ -67,23 +67,23 @@ public class PhoneticTokenFilter : TokenFilterBase, IPhoneticTokenFilter { public PhoneticTokenFilter() : base("phonetic") { } - /// + /// public PhoneticEncoder? Encoder { get; set; } - /// - public bool? Replace { get; set; } + /// + public IEnumerable LanguageSet { get; set; } - /// + /// public int? MaxCodeLength { get; set; } - /// - public PhoneticRuleType? RuleType { get; set; } - - /// + /// public PhoneticNameType? NameType { get; set; } - /// - public IEnumerable LanguageSet { get; set; } + /// + public bool? Replace { get; set; } + + /// + public PhoneticRuleType? RuleType { get; set; } } /// @@ -91,13 +91,13 @@ public class PhoneticTokenFilterDescriptor : TokenFilterDescriptorBase, IPhoneticTokenFilter { protected override string Type => "phonetic"; - - bool? IPhoneticTokenFilter.Replace { get; set; } PhoneticEncoder? IPhoneticTokenFilter.Encoder { get; set; } + IEnumerable IPhoneticTokenFilter.LanguageSet { get; set; } int? IPhoneticTokenFilter.MaxCodeLength { get; set; } - PhoneticRuleType? IPhoneticTokenFilter.RuleType { get; set; } PhoneticNameType? IPhoneticTokenFilter.NameType { get; set; } - IEnumerable IPhoneticTokenFilter.LanguageSet { get; set; } + + bool? IPhoneticTokenFilter.Replace { get; set; } + PhoneticRuleType? IPhoneticTokenFilter.RuleType { get; set; } /// public PhoneticTokenFilterDescriptor Replace(bool? replace = true) => Assign(a => a.Replace = replace); diff --git a/src/Nest/Analysis/StopWords.cs b/src/Nest/Analysis/StopWords.cs index fdb94d6d653..b9c0f3e105c 100644 --- a/src/Nest/Analysis/StopWords.cs +++ b/src/Nest/Analysis/StopWords.cs @@ -8,33 +8,33 @@ namespace Nest public class StopWords : Union> { public StopWords(string item) : base(item) { } + public StopWords(IEnumerable item) : base(item) { } public static implicit operator StopWords(string first) => new StopWords(first); + public static implicit operator StopWords(List second) => new StopWords(second); + public static implicit operator StopWords(string[] second) => new StopWords(second); } - internal class StopWordsJsonConverter :JsonConverter + internal class StopWordsJsonConverter : JsonConverter { + public static UnionJsonConverter> Unionconverter = new UnionJsonConverter>(); public override bool CanRead => true; public override bool CanWrite => true; - public static UnionJsonConverter> Unionconverter = new UnionJsonConverter>(); - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var union = Unionconverter.ReadJson(reader, objectType, existingValue, serializer) as Union>; if (union.Item1 != null) return new StopWords(union.Item1); + return new StopWords(union.Item2); } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => Unionconverter.WriteJson(writer, value, serializer); - } public override bool CanConvert(Type objectType) => true; } - } diff --git a/src/Nest/Analysis/TokenFilters/AsciiFoldingTokenFilter.cs b/src/Nest/Analysis/TokenFilters/AsciiFoldingTokenFilter.cs index ed97554e41c..22f7f4786cb 100644 --- a/src/Nest/Analysis/TokenFilters/AsciiFoldingTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/AsciiFoldingTokenFilter.cs @@ -2,7 +2,6 @@ namespace Nest { - /// /// A token filter of type asciifolding that converts alphabetic, numeric, and symbolic Unicode characters which are /// not in the first 127 ASCII characters (the “Basic Latin” Unicode block) into their ASCII equivalents, if one exists. @@ -13,7 +12,7 @@ public interface IAsciiFoldingTokenFilter : ITokenFilter bool? PreserveOriginal { get; set; } } - /// + /// public class AsciiFoldingTokenFilter : TokenFilterBase, IAsciiFoldingTokenFilter { public AsciiFoldingTokenFilter() : base("asciifolding") { } @@ -21,7 +20,7 @@ public AsciiFoldingTokenFilter() : base("asciifolding") { } public bool? PreserveOriginal { get; set; } } - /// + /// public class AsciiFoldingTokenFilterDescriptor : TokenFilterDescriptorBase, IAsciiFoldingTokenFilter { @@ -29,8 +28,7 @@ public class AsciiFoldingTokenFilterDescriptor bool? IAsciiFoldingTokenFilter.PreserveOriginal { get; set; } - /// + /// public AsciiFoldingTokenFilterDescriptor PreserveOriginal(bool? preserve = true) => Assign(a => a.PreserveOriginal = preserve); } - } diff --git a/src/Nest/Analysis/TokenFilters/CommonGramsTokenFilter.cs b/src/Nest/Analysis/TokenFilters/CommonGramsTokenFilter.cs index 78f427ff2c4..7b9ec0b7ad4 100644 --- a/src/Nest/Analysis/TokenFilters/CommonGramsTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/CommonGramsTokenFilter.cs @@ -4,8 +4,8 @@ namespace Nest { /// - /// Token filter that generates bigrams for frequently occuring terms. Single terms are still indexed. - ///Note, common_words or common_words_path field is required. + /// Token filter that generates bigrams for frequently occuring terms. Single terms are still indexed. + /// Note, common_words or common_words_path field is required. /// public interface ICommonGramsTokenFilter : ITokenFilter { @@ -35,27 +35,26 @@ public interface ICommonGramsTokenFilter : ITokenFilter bool? QueryMode { get; set; } } - /// + /// public class CommonGramsTokenFilter : TokenFilterBase, ICommonGramsTokenFilter { public CommonGramsTokenFilter() : base("common_grams") { } - /// + /// public IEnumerable CommonWords { get; set; } - /// + /// public string CommonWordsPath { get; set; } - /// + /// public bool? IgnoreCase { get; set; } - /// + /// public bool? QueryMode { get; set; } - } - /// - public class CommonGramsTokenFilterDescriptor + /// + public class CommonGramsTokenFilterDescriptor : TokenFilterDescriptorBase, ICommonGramsTokenFilter { protected override string Type => "common_grams"; @@ -65,21 +64,19 @@ public class CommonGramsTokenFilterDescriptor bool? ICommonGramsTokenFilter.IgnoreCase { get; set; } bool? ICommonGramsTokenFilter.QueryMode { get; set; } - /// + /// public CommonGramsTokenFilterDescriptor QueryMode(bool? queryMode = true) => Assign(a => a.QueryMode = queryMode); - /// + /// public CommonGramsTokenFilterDescriptor IgnoreCase(bool? ignoreCase = true) => Assign(a => a.IgnoreCase = ignoreCase); - /// + /// public CommonGramsTokenFilterDescriptor CommonWordsPath(string path) => Assign(a => a.CommonWordsPath = path); - /// + /// public CommonGramsTokenFilterDescriptor CommonWords(IEnumerable commonWords) => Assign(a => a.CommonWords = commonWords); - /// + /// public CommonGramsTokenFilterDescriptor CommonWords(params string[] commonWords) => Assign(a => a.CommonWords = commonWords); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/CompoundWord/CompoundWordTokenFilterBase.cs b/src/Nest/Analysis/TokenFilters/CompoundWord/CompoundWordTokenFilterBase.cs index 9f602b0f367..30ef879cdbf 100644 --- a/src/Nest/Analysis/TokenFilters/CompoundWord/CompoundWordTokenFilterBase.cs +++ b/src/Nest/Analysis/TokenFilters/CompoundWord/CompoundWordTokenFilterBase.cs @@ -8,18 +8,6 @@ namespace Nest /// public interface ICompoundWordTokenFilter : ITokenFilter { - /// - /// A list of words to use. - /// - [JsonProperty("word_list")] - IEnumerable WordList { get; set; } - - /// - /// A path (either relative to config location, or absolute) to a list of words. - /// - [JsonProperty("word_list_path")] - string WordListPath { get; set; } - /// /// A path (either relative to config location, or absolute) to a FOP XML hyphenation pattern file. /// @@ -27,10 +15,10 @@ public interface ICompoundWordTokenFilter : ITokenFilter string HyphenationPatternsPath { get; set; } /// - /// Minimum word size. + /// Maximum subword size. /// - [JsonProperty("min_word_size")] - int? MinWordSize { get; set; } + [JsonProperty("max_subword_size")] + int? MaxSubwordSize { get; set; } /// /// Minimum subword size. @@ -39,80 +27,91 @@ public interface ICompoundWordTokenFilter : ITokenFilter int? MinSubwordSize { get; set; } /// - /// Maximum subword size. + /// Minimum word size. /// - [JsonProperty("max_subword_size")] - int? MaxSubwordSize { get; set; } + [JsonProperty("min_word_size")] + int? MinWordSize { get; set; } /// /// Only matching the longest. /// [JsonProperty("only_longest_match")] bool? OnlyLongestMatch { get; set; } + + /// + /// A list of words to use. + /// + [JsonProperty("word_list")] + IEnumerable WordList { get; set; } + + /// + /// A path (either relative to config location, or absolute) to a list of words. + /// + [JsonProperty("word_list_path")] + string WordListPath { get; set; } } public abstract class CompoundWordTokenFilterBase : TokenFilterBase, ICompoundWordTokenFilter { protected CompoundWordTokenFilterBase(string type) : base(type) { } - /// - public IEnumerable WordList { get; set; } - - /// - public string WordListPath { get; set; } + public string HyphenationPatternsPath { get; set; } - /// - public int? MinWordSize { get; set; } + /// + public int? MaxSubwordSize { get; set; } - /// + /// public int? MinSubwordSize { get; set; } - /// - public int? MaxSubwordSize { get; set; } + /// + public int? MinWordSize { get; set; } - /// + /// public bool? OnlyLongestMatch { get; set; } - public string HyphenationPatternsPath { get; set; } + /// + public IEnumerable WordList { get; set; } + + /// + public string WordListPath { get; set; } } - /// + /// public abstract class CompoundWordTokenFilterDescriptorBase : TokenFilterDescriptorBase, ICompoundWordTokenFilter where TCompound : CompoundWordTokenFilterDescriptorBase, TCompoundInterface where TCompoundInterface : class, ICompoundWordTokenFilter { - IEnumerable ICompoundWordTokenFilter.WordList { get; set; } - string ICompoundWordTokenFilter.WordListPath { get; set; } - int? ICompoundWordTokenFilter.MinWordSize { get; set; } - int? ICompoundWordTokenFilter.MinSubwordSize { get; set; } + string ICompoundWordTokenFilter.HyphenationPatternsPath { get; set; } int? ICompoundWordTokenFilter.MaxSubwordSize { get; set; } + int? ICompoundWordTokenFilter.MinSubwordSize { get; set; } + int? ICompoundWordTokenFilter.MinWordSize { get; set; } bool? ICompoundWordTokenFilter.OnlyLongestMatch { get; set; } - string ICompoundWordTokenFilter.HyphenationPatternsPath { get; set; } + IEnumerable ICompoundWordTokenFilter.WordList { get; set; } + string ICompoundWordTokenFilter.WordListPath { get; set; } - /// + /// public TCompound WordList(IEnumerable wordList) => Assign(a => a.WordList = wordList); - /// + /// public TCompound WordList(params string[] wordList) => Assign(a => a.WordList = wordList); - /// + /// public TCompound WordListPath(string path) => Assign(a => a.WordListPath = path); - /// + /// public TCompound HyphenationPatternsPath(string path) => Assign(a => a.HyphenationPatternsPath = path); - /// + /// public TCompound MinWordSize(int? minWordSize) => Assign(a => a.MinWordSize = minWordSize); - /// + /// public TCompound MinSubwordSize(int? minSubwordSize) => Assign(a => a.MinSubwordSize = minSubwordSize); - /// + /// public TCompound MaxSubwordSize(int? maxSubwordSize) => Assign(a => a.MaxSubwordSize = maxSubwordSize); - /// + /// public TCompound OnlyLongestMatch(bool? onlyLongest = true) => Assign(a => a.OnlyLongestMatch = onlyLongest); - } } diff --git a/src/Nest/Analysis/TokenFilters/CompoundWord/DictionaryDecompounderTokenFilter.cs b/src/Nest/Analysis/TokenFilters/CompoundWord/DictionaryDecompounderTokenFilter.cs index 0d435cdc7ad..cb6f83b2449 100644 --- a/src/Nest/Analysis/TokenFilters/CompoundWord/DictionaryDecompounderTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/CompoundWord/DictionaryDecompounderTokenFilter.cs @@ -1,16 +1,18 @@ namespace Nest { public interface IDictionaryDecompounderTokenFilter : ICompoundWordTokenFilter { } - /// + + /// public class DictionaryDecompounderTokenFilter : CompoundWordTokenFilterBase, IDictionaryDecompounderTokenFilter { public DictionaryDecompounderTokenFilter() : base("dictionary_decompounder") { } } - /// + + /// public class DictionaryDecompounderTokenFilterDescriptor : CompoundWordTokenFilterDescriptorBase - , IDictionaryDecompounderTokenFilter + , IDictionaryDecompounderTokenFilter { protected override string Type => "dictionary_decompounder"; } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/CompoundWord/HyphenationDecompounderTokenFilter.cs b/src/Nest/Analysis/TokenFilters/CompoundWord/HyphenationDecompounderTokenFilter.cs index c67796afac4..9d31838c66d 100644 --- a/src/Nest/Analysis/TokenFilters/CompoundWord/HyphenationDecompounderTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/CompoundWord/HyphenationDecompounderTokenFilter.cs @@ -4,17 +4,18 @@ namespace Nest /// Token filters that allow to decompose compound words. /// public interface IHyphenationDecompounderTokenFilter : ICompoundWordTokenFilter { } - /// + + /// public class HyphenationDecompounderTokenFilter : CompoundWordTokenFilterBase, IHyphenationDecompounderTokenFilter { public HyphenationDecompounderTokenFilter() : base("hyphenation_decompounder") { } } - /// - public class HyphenationDecompounderTokenFilterDescriptor + + /// + public class HyphenationDecompounderTokenFilterDescriptor : CompoundWordTokenFilterDescriptorBase - , IHyphenationDecompounderTokenFilter + , IHyphenationDecompounderTokenFilter { protected override string Type => "hyphenation_decompounder"; } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/DelimitedPayload/DelimitedPayloadEncoding.cs b/src/Nest/Analysis/TokenFilters/DelimitedPayload/DelimitedPayloadEncoding.cs index a45bf0a96e3..a6fde9852b2 100644 --- a/src/Nest/Analysis/TokenFilters/DelimitedPayload/DelimitedPayloadEncoding.cs +++ b/src/Nest/Analysis/TokenFilters/DelimitedPayload/DelimitedPayloadEncoding.cs @@ -9,9 +9,11 @@ public enum DelimitedPayloadEncoding { [EnumMember(Value = "int")] Integer, + [EnumMember(Value = "float")] Float, + [EnumMember(Value = "identity")] Identity, } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/DelimitedPayload/DelimitedPayloadTokenFilter.cs b/src/Nest/Analysis/TokenFilters/DelimitedPayload/DelimitedPayloadTokenFilter.cs index 3420962794e..1b3c3bc5d3c 100644 --- a/src/Nest/Analysis/TokenFilters/DelimitedPayload/DelimitedPayloadTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/DelimitedPayload/DelimitedPayloadTokenFilter.cs @@ -18,23 +18,21 @@ public interface IDelimitedPayloadTokenFilter : ITokenFilter /// [JsonProperty("encoding")] DelimitedPayloadEncoding? Encoding { get; set; } - } - /// + /// public class DelimitedPayloadTokenFilter : TokenFilterBase, IDelimitedPayloadTokenFilter { public DelimitedPayloadTokenFilter() : base("delimited_payload_filter") { } - /// + /// public char? Delimiter { get; set; } - /// + /// public DelimitedPayloadEncoding? Encoding { get; set; } - } - /// + /// public class DelimitedPayloadTokenFilterDescriptor : TokenFilterDescriptorBase, IDelimitedPayloadTokenFilter { @@ -43,12 +41,10 @@ public class DelimitedPayloadTokenFilterDescriptor char? IDelimitedPayloadTokenFilter.Delimiter { get; set; } DelimitedPayloadEncoding? IDelimitedPayloadTokenFilter.Encoding { get; set; } - /// + /// public DelimitedPayloadTokenFilterDescriptor Delimiter(char? delimiter) => Assign(a => a.Delimiter = delimiter); - /// + /// public DelimitedPayloadTokenFilterDescriptor Encoding(DelimitedPayloadEncoding? encoding) => Assign(a => a.Encoding = encoding); - } - } diff --git a/src/Nest/Analysis/TokenFilters/EdgeNGram/EdgeNGramSide.cs b/src/Nest/Analysis/TokenFilters/EdgeNGram/EdgeNGramSide.cs index 3b4e1ce8c4b..9d86f8f9035 100644 --- a/src/Nest/Analysis/TokenFilters/EdgeNGram/EdgeNGramSide.cs +++ b/src/Nest/Analysis/TokenFilters/EdgeNGram/EdgeNGramSide.cs @@ -9,7 +9,8 @@ public enum EdgeNGramSide { [EnumMember(Value = "front")] Front, + [EnumMember(Value = "back")] Back, } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/EdgeNGram/EdgeNGramTokenFilter.cs b/src/Nest/Analysis/TokenFilters/EdgeNGram/EdgeNGramTokenFilter.cs index 04c5cfa87d3..1700b356d9c 100644 --- a/src/Nest/Analysis/TokenFilters/EdgeNGram/EdgeNGramTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/EdgeNGram/EdgeNGramTokenFilter.cs @@ -8,57 +8,56 @@ namespace Nest public interface IEdgeNGramTokenFilter : ITokenFilter { /// - ///Defaults to 1. + /// Defaults to 2. /// - [JsonProperty("min_gram")] - int? MinGram { get; set; } + [JsonProperty("max_gram")] + int? MaxGram { get; set; } /// - ///Defaults to 2. + /// Defaults to 1. /// - [JsonProperty("max_gram")] - int? MaxGram { get; set; } + [JsonProperty("min_gram")] + int? MinGram { get; set; } /// /// Either front or back. Defaults to front. /// [JsonProperty("side")] EdgeNGramSide? Side { get; set; } - } - /// + + /// public class EdgeNGramTokenFilter : TokenFilterBase, IEdgeNGramTokenFilter { public EdgeNGramTokenFilter() : base("edge_ngram") { } - /// - public int? MinGram { get; set; } - - /// + /// public int? MaxGram { get; set; } - /// + /// + public int? MinGram { get; set; } + + /// public EdgeNGramSide? Side { get; set; } } - /// - public class EdgeNGramTokenFilterDescriptor + + /// + public class EdgeNGramTokenFilterDescriptor : TokenFilterDescriptorBase, IEdgeNGramTokenFilter { protected override string Type => "edge_ngram"; + int? IEdgeNGramTokenFilter.MaxGram { get; set; } int? IEdgeNGramTokenFilter.MinGram { get; set; } - int? IEdgeNGramTokenFilter.MaxGram { get; set; } EdgeNGramSide? IEdgeNGramTokenFilter.Side { get; set; } - /// + /// public EdgeNGramTokenFilterDescriptor MinGram(int? minGram) => Assign(a => a.MinGram = minGram); - /// + /// public EdgeNGramTokenFilterDescriptor MaxGram(int? maxGram) => Assign(a => a.MaxGram = maxGram); - /// + /// public EdgeNGramTokenFilterDescriptor Side(EdgeNGramSide? side) => Assign(a => a.Side = side); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/ElisionTokenFilter.cs b/src/Nest/Analysis/TokenFilters/ElisionTokenFilter.cs index 731abb6353a..b6bf95f9221 100644 --- a/src/Nest/Analysis/TokenFilters/ElisionTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/ElisionTokenFilter.cs @@ -15,28 +15,27 @@ public interface IElisionTokenFilter : ITokenFilter IEnumerable Articles { get; set; } } - /// + /// public class ElisionTokenFilter : TokenFilterBase, IElisionTokenFilter { public ElisionTokenFilter() : base("elision") { } - /// + /// public IEnumerable Articles { get; set; } } - /// - public class ElisionTokenFilterDescriptor + + /// + public class ElisionTokenFilterDescriptor : TokenFilterDescriptorBase, IElisionTokenFilter { protected override string Type => "elision"; IEnumerable IElisionTokenFilter.Articles { get; set; } - /// + /// public ElisionTokenFilterDescriptor Articles(IEnumerable articles) => Assign(a => a.Articles = articles); - /// + /// public ElisionTokenFilterDescriptor Articles(params string[] articles) => Assign(a => a.Articles = articles); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/FingerprintTokenFilter.cs b/src/Nest/Analysis/TokenFilters/FingerprintTokenFilter.cs index 6139252ae78..12872c30c64 100644 --- a/src/Nest/Analysis/TokenFilters/FingerprintTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/FingerprintTokenFilter.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -15,44 +10,45 @@ namespace Nest /// public interface IFingerprintTokenFilter : ITokenFilter { + /// + /// The maximum token size to emit. Defaults to 255. + /// + [JsonProperty("max_output_size")] + int? MaxOutputSize { get; set; } + /// /// The character that separates the tokens after concatenation. /// Defaults to a space. /// [JsonProperty("separator")] string Separator { get; set; } - - /// - /// The maximum token size to emit. Defaults to 255. - /// - [JsonProperty("max_output_size")] - int? MaxOutputSize { get; set; } } - /// + /// public class FingerprintTokenFilter : TokenFilterBase, IFingerprintTokenFilter { public FingerprintTokenFilter() : base("fingerprint") { } /// - /// The character that separates the tokens after concatenation. - /// Defaults to a space. + /// The maximum token size to emit. Defaults to 255. /// - public string Separator { get; set; } + public int? MaxOutputSize { get; set; } /// - /// The maximum token size to emit. Defaults to 255. + /// The character that separates the tokens after concatenation. + /// Defaults to a space. /// - public int? MaxOutputSize { get; set; } + public string Separator { get; set; } } - /// + + /// public class FingerprintTokenFilterDescriptor : TokenFilterDescriptorBase, IFingerprintTokenFilter { protected override string Type => "fingerprint"; + int? IFingerprintTokenFilter.MaxOutputSize { get; set; } string IFingerprintTokenFilter.Separator { get; set; } - int? IFingerprintTokenFilter.MaxOutputSize { get; set; } public FingerprintTokenFilterDescriptor Separator(string separator) => Assign(a => a.Separator = separator); diff --git a/src/Nest/Analysis/TokenFilters/HunspellTokenFilter.cs b/src/Nest/Analysis/TokenFilters/HunspellTokenFilter.cs index 5c4355befac..feeaf819a22 100644 --- a/src/Nest/Analysis/TokenFilters/HunspellTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/HunspellTokenFilter.cs @@ -1,19 +1,18 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { /// - /// Basic support for hunspell stemming. - /// Hunspell dictionaries will be picked up from a dedicated hunspell directory on the filesystem. + /// Basic support for hunspell stemming. + /// Hunspell dictionaries will be picked up from a dedicated hunspell directory on the filesystem. /// public interface IHunspellTokenFilter : ITokenFilter { /// - /// A locale for this filter. If this is unset, the lang or language are used instead - so one of these has to be set. + /// If only unique terms should be returned, this needs to be set to true. /// - [JsonProperty("locale")] - string Locale { get; set; } + [JsonProperty("dedup")] + bool? Dedup { get; set; } /// /// The name of a dictionary.The path to your hunspell dictionaries should be configured via @@ -23,62 +22,57 @@ public interface IHunspellTokenFilter : ITokenFilter string Dictionary { get; set; } /// - /// If only unique terms should be returned, this needs to be set to true. + /// A locale for this filter. If this is unset, the lang or language are used instead - so one of these has to be set. /// - [JsonProperty("dedup")] - bool? Dedup { get; set; } + [JsonProperty("locale")] + string Locale { get; set; } /// /// If only the longest term should be returned, set this to true. /// [JsonProperty("longest_only")] bool? LongestOnly { get; set; } - } - /// + /// public class HunspellTokenFilter : TokenFilterBase, IHunspellTokenFilter { public HunspellTokenFilter() : base("hunspell") { } - /// - public string Locale { get; set; } + /// + public bool? Dedup { get; set; } - /// + /// public string Dictionary { get; set; } - /// - public bool? Dedup { get; set; } + /// + public string Locale { get; set; } - /// + /// public bool? LongestOnly { get; set; } - - } - /// + /// public class HunspellTokenFilterDescriptor : TokenFilterDescriptorBase, IHunspellTokenFilter { protected override string Type => "hunspell"; - - bool? IHunspellTokenFilter.LongestOnly { get; set; } bool? IHunspellTokenFilter.Dedup { get; set; } - string IHunspellTokenFilter.Locale { get; set; } string IHunspellTokenFilter.Dictionary { get; set; } + string IHunspellTokenFilter.Locale { get; set; } + + bool? IHunspellTokenFilter.LongestOnly { get; set; } - /// + /// public HunspellTokenFilterDescriptor LongestOnly(bool? longestOnly = true) => Assign(a => a.LongestOnly = longestOnly); - /// + /// public HunspellTokenFilterDescriptor Dedup(bool? dedup = true) => Assign(a => a.Dedup = dedup); - /// + /// public HunspellTokenFilterDescriptor Locale(string locale) => Assign(a => a.Locale = locale); - /// + /// public HunspellTokenFilterDescriptor Dictionary(string dictionary) => Assign(a => a.Dictionary = dictionary); - } - } diff --git a/src/Nest/Analysis/TokenFilters/KStemTokenFilter.cs b/src/Nest/Analysis/TokenFilters/KStemTokenFilter.cs index def2a0913be..aec25078e27 100644 --- a/src/Nest/Analysis/TokenFilters/KStemTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/KStemTokenFilter.cs @@ -1,20 +1,21 @@ namespace Nest { /// - ///The kstem token filter is a high performance filter for english. - /// All terms must already be lowercased (use lowercase filter) for this filter to work correctly. + /// The kstem token filter is a high performance filter for english. + /// All terms must already be lowercased (use lowercase filter) for this filter to work correctly. /// public interface IKStemTokenFilter : ITokenFilter { } - /// + + /// public class KStemTokenFilter : TokenFilterBase, IKStemTokenFilter { public KStemTokenFilter() : base("kstem") { } } - /// - public class KStemTokenFilterDescriptor + + /// + public class KStemTokenFilterDescriptor : TokenFilterDescriptorBase, IKStemTokenFilter { protected override string Type => "kstem"; } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/KeepTypesTokenFilter.cs b/src/Nest/Analysis/TokenFilters/KeepTypesTokenFilter.cs index 70b88d679f6..7d34ee5b268 100644 --- a/src/Nest/Analysis/TokenFilters/KeepTypesTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/KeepTypesTokenFilter.cs @@ -8,8 +8,9 @@ namespace Nest [JsonConverter(typeof(StringEnumConverter))] public enum KeepTypesMode { - [EnumMember(Value="include")] + [EnumMember(Value = "include")] Include, + [EnumMember(Value = "exclude")] Exclude } @@ -19,45 +20,43 @@ public enum KeepTypesMode /// public interface IKeepTypesTokenFilter : ITokenFilter { + /// Whether to include or exclude the types provided on + [JsonProperty("mode")] + KeepTypesMode? Mode { get; set; } + /// A list of types to keep. [JsonProperty("types")] IEnumerable Types { get; set; } - - /// Whether to include or exclude the types provided on - [JsonProperty("mode")] - KeepTypesMode? Mode { get; set; } } - /// + + /// public class KeepTypesTokenFilter : TokenFilterBase { public KeepTypesTokenFilter() : base("keep_types") { } - /// - public IEnumerable Types { get; set; } - - /// + /// public KeepTypesMode? Mode { get; set; } + /// + public IEnumerable Types { get; set; } } - /// + + /// public class KeepTypesTokenFilterDescriptor : TokenFilterDescriptorBase, IKeepTypesTokenFilter { protected override string Type => "keep_types"; + KeepTypesMode? IKeepTypesTokenFilter.Mode { get; set; } IEnumerable IKeepTypesTokenFilter.Types { get; set; } - KeepTypesMode? IKeepTypesTokenFilter.Mode { get; set; } - /// + /// public KeepTypesTokenFilterDescriptor Types(IEnumerable types) => Assign(a => a.Types = types); - /// + /// public KeepTypesTokenFilterDescriptor Types(params string[] types) => Assign(a => a.Types = types); - /// + /// public KeepTypesTokenFilterDescriptor Mode(KeepTypesMode? mode) => Assign(a => a.Mode = mode); - - } - } diff --git a/src/Nest/Analysis/TokenFilters/KeepWordsTokenFilter.cs b/src/Nest/Analysis/TokenFilters/KeepWordsTokenFilter.cs index b2549fad0c8..3e9e11572d0 100644 --- a/src/Nest/Analysis/TokenFilters/KeepWordsTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/KeepWordsTokenFilter.cs @@ -14,56 +14,54 @@ public interface IKeepWordsTokenFilter : ITokenFilter [JsonProperty("keep_words")] IEnumerable KeepWords { get; set; } - /// - /// A path to a words file. - /// - [JsonProperty("keep_words_path")] - string KeepWordsPath { get; set; } - /// /// A boolean indicating whether to lower case the words. /// [JsonProperty("keep_words_case")] bool? KeepWordsCase { get; set; } + /// + /// A path to a words file. + /// + [JsonProperty("keep_words_path")] + string KeepWordsPath { get; set; } } - /// + + /// public class KeepWordsTokenFilter : TokenFilterBase, IKeepWordsTokenFilter { public KeepWordsTokenFilter() : base("keep") { } - /// + /// public IEnumerable KeepWords { get; set; } - /// - public string KeepWordsPath { get; set; } - - /// + /// public bool? KeepWordsCase { get; set; } + /// + public string KeepWordsPath { get; set; } } - /// - public class KeepWordsTokenFilterDescriptor + + /// + public class KeepWordsTokenFilterDescriptor : TokenFilterDescriptorBase, IKeepWordsTokenFilter { protected override string Type => "keep"; + IEnumerable IKeepWordsTokenFilter.KeepWords { get; set; } bool? IKeepWordsTokenFilter.KeepWordsCase { get; set; } string IKeepWordsTokenFilter.KeepWordsPath { get; set; } - IEnumerable IKeepWordsTokenFilter.KeepWords { get; set; } - /// + /// public KeepWordsTokenFilterDescriptor KeepWordsCase(bool? keepCase = true) => Assign(a => a.KeepWordsCase = keepCase); - /// + /// public KeepWordsTokenFilterDescriptor KeepWordsPath(string path) => Assign(a => a.KeepWordsPath = path); - /// + /// public KeepWordsTokenFilterDescriptor KeepWords(IEnumerable keepWords) => Assign(a => a.KeepWords = keepWords); - /// + /// public KeepWordsTokenFilterDescriptor KeepWords(params string[] keepWords) => Assign(a => a.KeepWords = keepWords); - } - } diff --git a/src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs b/src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs index eea9e3d078e..c58b6a11049 100644 --- a/src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs @@ -6,8 +6,14 @@ namespace Nest /// /// Protects words from being modified by stemmers. Must be placed before any stemming filters. /// - public interface IKeywordMarkerTokenFilter: ITokenFilter + public interface IKeywordMarkerTokenFilter : ITokenFilter { + /// + /// Set to true to lower case all words first. Defaults to false. + /// + [JsonProperty("ignore_case")] + bool? IgnoreCase { get; set; } + /// /// A list of words to use. /// @@ -19,48 +25,43 @@ public interface IKeywordMarkerTokenFilter: ITokenFilter /// [JsonProperty("keywords_path")] string KeywordsPath { get; set; } - - /// - /// Set to true to lower case all words first. Defaults to false. - /// - [JsonProperty("ignore_case")] - bool? IgnoreCase { get; set; } } - /// + /// public class KeywordMarkerTokenFilter : TokenFilterBase, IKeywordMarkerTokenFilter { public KeywordMarkerTokenFilter() : base("keyword_marker") { } - /// + /// + public bool? IgnoreCase { get; set; } + + /// public IEnumerable Keywords { get; set; } - /// + /// public string KeywordsPath { get; set; } - - /// - public bool? IgnoreCase { get; set; } } - /// - public class KeywordMarkerTokenFilterDescriptor + + /// + public class KeywordMarkerTokenFilterDescriptor : TokenFilterDescriptorBase, IKeywordMarkerTokenFilter { protected override string Type => "keyword_marker"; + bool? IKeywordMarkerTokenFilter.IgnoreCase { get; set; } IEnumerable IKeywordMarkerTokenFilter.Keywords { get; set; } string IKeywordMarkerTokenFilter.KeywordsPath { get; set; } - bool? IKeywordMarkerTokenFilter.IgnoreCase { get; set; } - /// + /// public KeywordMarkerTokenFilterDescriptor IgnoreCase(bool? ignoreCase = true) => Assign(a => a.IgnoreCase = ignoreCase); - /// + /// public KeywordMarkerTokenFilterDescriptor KeywordsPath(string path) => Assign(a => a.KeywordsPath = path); - /// + /// public KeywordMarkerTokenFilterDescriptor Keywords(IEnumerable keywords) => Assign(a => a.Keywords = keywords); - /// + /// public KeywordMarkerTokenFilterDescriptor Keywords(params string[] keywords) => Assign(a => a.Keywords = keywords); } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/LengthTokenFilter.cs b/src/Nest/Analysis/TokenFilters/LengthTokenFilter.cs index 949f77cc78d..2a5b4ce4364 100644 --- a/src/Nest/Analysis/TokenFilters/LengthTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/LengthTokenFilter.cs @@ -7,44 +7,44 @@ namespace Nest /// public interface ILengthTokenFilter : ITokenFilter { - /// - /// The minimum number. Defaults to 0. - /// - [JsonProperty("min")] - int? Min { get; set; } - /// /// The maximum number. Defaults to Integer.MAX_VALUE. /// [JsonProperty("max")] int? Max { get; set; } + + /// + /// The minimum number. Defaults to 0. + /// + [JsonProperty("min")] + int? Min { get; set; } } - /// + + /// public class LengthTokenFilter : TokenFilterBase, ILengthTokenFilter { public LengthTokenFilter() : base("length") { } - /// - public int? Min { get; set; } - - /// + /// public int? Max { get; set; } + + /// + public int? Min { get; set; } } - /// - public class LengthTokenFilterDescriptor + + /// + public class LengthTokenFilterDescriptor : TokenFilterDescriptorBase, ILengthTokenFilter { protected override string Type => "length"; + int? ILengthTokenFilter.Max { get; set; } int? ILengthTokenFilter.Min { get; set; } - int? ILengthTokenFilter.Max { get; set; } - /// + /// public LengthTokenFilterDescriptor Min(int? minimum) => Assign(a => a.Min = minimum); - /// + /// public LengthTokenFilterDescriptor Max(int? maximum) => Assign(a => a.Max = maximum); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/LimitTokenCountTokenFilter.cs b/src/Nest/Analysis/TokenFilters/LimitTokenCountTokenFilter.cs index 218fd31dc1d..9deb845c5d5 100644 --- a/src/Nest/Analysis/TokenFilters/LimitTokenCountTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/LimitTokenCountTokenFilter.cs @@ -7,44 +7,45 @@ namespace Nest /// public interface ILimitTokenCountTokenFilter : ITokenFilter { - /// - /// The maximum number of tokens that should be indexed per document and field. - /// - [JsonProperty("max_token_count")] - int? MaxTokenCount { get; set; } - /// /// If set to true the filter exhaust the stream even if max_token_count tokens have been consumed already. /// [JsonProperty("consume_all_tokens")] bool? ConsumeAllTokens { get; set; } + + /// + /// The maximum number of tokens that should be indexed per document and field. + /// + [JsonProperty("max_token_count")] + int? MaxTokenCount { get; set; } } - /// + + /// public class LimitTokenCountTokenFilter : TokenFilterBase, ILimitTokenCountTokenFilter { public LimitTokenCountTokenFilter() : base("limit") { } - /// - public int? MaxTokenCount { get; set; } - - /// + /// public bool? ConsumeAllTokens { get; set; } + + /// + public int? MaxTokenCount { get; set; } } - /// - public class LimitTokenCountTokenFilterDescriptor + + /// + public class LimitTokenCountTokenFilterDescriptor : TokenFilterDescriptorBase, ILimitTokenCountTokenFilter { protected override string Type => "limit"; + bool? ILimitTokenCountTokenFilter.ConsumeAllTokens { get; set; } int? ILimitTokenCountTokenFilter.MaxTokenCount { get; set; } - bool? ILimitTokenCountTokenFilter.ConsumeAllTokens { get; set; } - /// - public LimitTokenCountTokenFilterDescriptor ConsumeAllToken(bool? consumeAllTokens = true) => Assign(a => a.ConsumeAllTokens = consumeAllTokens); + /// + public LimitTokenCountTokenFilterDescriptor ConsumeAllToken(bool? consumeAllTokens = true) => + Assign(a => a.ConsumeAllTokens = consumeAllTokens); - /// + /// public LimitTokenCountTokenFilterDescriptor MaxTokenCount(int? maxTokenCount) => Assign(a => a.MaxTokenCount = maxTokenCount); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/LowercaseTokenFilter.cs b/src/Nest/Analysis/TokenFilters/LowercaseTokenFilter.cs index a28a5d9f988..3d6fa4f85e6 100644 --- a/src/Nest/Analysis/TokenFilters/LowercaseTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/LowercaseTokenFilter.cs @@ -3,8 +3,8 @@ namespace Nest { /// - /// A token filter of type lowercase that normalizes token text to lower case. - /// Lowercase token filter supports Greek and Turkish lowercase token filters through the language parameter. + /// A token filter of type lowercase that normalizes token text to lower case. + /// Lowercase token filter supports Greek and Turkish lowercase token filters through the language parameter. /// public interface ILowercaseTokenFilter : ITokenFilter { @@ -14,24 +14,25 @@ public interface ILowercaseTokenFilter : ITokenFilter [JsonProperty("language")] string Language { get; set; } } - /// + + /// public class LowercaseTokenFilter : TokenFilterBase, ILowercaseTokenFilter { public LowercaseTokenFilter() : base("lowercase") { } - /// + /// public string Language { get; set; } } - /// - public class LowercaseTokenFilterDescriptor + + /// + public class LowercaseTokenFilterDescriptor : TokenFilterDescriptorBase, ILowercaseTokenFilter { protected override string Type => "lowercase"; string ILowercaseTokenFilter.Language { get; set; } - /// + /// public LowercaseTokenFilterDescriptor Language(string language) => Assign(a => a.Language = language); } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/MultiplexerTokenFilter.cs b/src/Nest/Analysis/TokenFilters/MultiplexerTokenFilter.cs index 9454b6ad78a..d1d1ef56eee 100644 --- a/src/Nest/Analysis/TokenFilters/MultiplexerTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/MultiplexerTokenFilter.cs @@ -1,5 +1,4 @@ -using System.Collections; -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Nest @@ -16,19 +15,21 @@ public interface IMultiplexerTokenFilter : ITokenFilter [JsonProperty("preserve_original")] bool? PreserveOriginal { get; set; } } + public class MultiplexerTokenFilter : TokenFilterBase, IMultiplexerTokenFilter { internal const string TokenType = "multiplexer"; + public MultiplexerTokenFilter() : base(TokenType) { } - /// + /// public IEnumerable Filters { get; set; } - /// + /// public bool? PreserveOriginal { get; set; } - } - /// + + /// public class MultiplexerTokenFilterDescriptor : TokenFilterDescriptorBase, IMultiplexerTokenFilter { @@ -37,14 +38,13 @@ public class MultiplexerTokenFilterDescriptor IEnumerable IMultiplexerTokenFilter.Filters { get; set; } bool? IMultiplexerTokenFilter.PreserveOriginal { get; set; } - /// + /// public MultiplexerTokenFilterDescriptor Filters(IEnumerable filters) => Assign(a => a.Filters = filters); - /// + /// public MultiplexerTokenFilterDescriptor Filters(params string[] filters) => Assign(a => a.Filters = filters); - /// + /// public MultiplexerTokenFilterDescriptor PreserveOriginal(bool? preserve = true) => Assign(a => a.PreserveOriginal = preserve); } - } diff --git a/src/Nest/Analysis/TokenFilters/NgramTokenFilter.cs b/src/Nest/Analysis/TokenFilters/NgramTokenFilter.cs index 65204840b0a..8d168fa0056 100644 --- a/src/Nest/Analysis/TokenFilters/NgramTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/NgramTokenFilter.cs @@ -8,44 +8,43 @@ namespace Nest public interface INGramTokenFilter : ITokenFilter { /// - /// Defaults to 1. + /// Defaults to 2 /// - [JsonProperty("min_gram")] - int? MinGram { get; set; } + [JsonProperty("max_gram")] + int? MaxGram { get; set; } /// - /// Defaults to 2 + /// Defaults to 1. /// - [JsonProperty("max_gram")] - int? MaxGram { get; set; } + [JsonProperty("min_gram")] + int? MinGram { get; set; } } - /// + /// public class NGramTokenFilter : TokenFilterBase, INGramTokenFilter { public NGramTokenFilter() : base("ngram") { } - /// - public int? MinGram { get; set; } - - /// + /// public int? MaxGram { get; set; } + + /// + public int? MinGram { get; set; } } - /// - public class NGramTokenFilterDescriptor + + /// + public class NGramTokenFilterDescriptor : TokenFilterDescriptorBase, INGramTokenFilter { protected override string Type => "ngram"; + int? INGramTokenFilter.MaxGram { get; set; } int? INGramTokenFilter.MinGram { get; set; } - int? INGramTokenFilter.MaxGram { get; set; } - /// + /// public NGramTokenFilterDescriptor MinGram(int? minGram) => Assign(a => a.MinGram = minGram); - /// + /// public NGramTokenFilterDescriptor MaxGram(int? maxGram) => Assign(a => a.MaxGram = maxGram); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/NoriPartOfSpeechTokenFilter.cs b/src/Nest/Analysis/TokenFilters/NoriPartOfSpeechTokenFilter.cs index 93870344550..0c41ffecfa6 100644 --- a/src/Nest/Analysis/TokenFilters/NoriPartOfSpeechTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/NoriPartOfSpeechTokenFilter.cs @@ -11,7 +11,7 @@ public interface INoriPartOfSpeechTokenFilter : ITokenFilter IEnumerable StopTags { get; set; } } - /// + /// public class NoriPartOfSpeechTokenFilter : TokenFilterBase, INoriPartOfSpeechTokenFilter { public NoriPartOfSpeechTokenFilter() : base("nori_part_of_speech") { } @@ -19,7 +19,8 @@ public NoriPartOfSpeechTokenFilter() : base("nori_part_of_speech") { } /// public IEnumerable StopTags { get; set; } } - /// + + /// public class NoriPartOfSpeechTokenFilterDescriptor : TokenFilterDescriptorBase, INoriPartOfSpeechTokenFilter { @@ -32,7 +33,5 @@ public class NoriPartOfSpeechTokenFilterDescriptor /// public NoriPartOfSpeechTokenFilterDescriptor StopTags(params string[] stopTags) => Assign(a => a.StopTags = stopTags); - } - } diff --git a/src/Nest/Analysis/TokenFilters/PatternCaptureTokenFilter.cs b/src/Nest/Analysis/TokenFilters/PatternCaptureTokenFilter.cs index 5d6c895f481..ae87470e440 100644 --- a/src/Nest/Analysis/TokenFilters/PatternCaptureTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/PatternCaptureTokenFilter.cs @@ -20,35 +20,35 @@ public interface IPatternCaptureTokenFilter : ITokenFilter [JsonProperty("preserve_original")] bool? PreserveOriginal { get; set; } } - /// + + /// public class PatternCaptureTokenFilter : TokenFilterBase, IPatternCaptureTokenFilter { public PatternCaptureTokenFilter() : base("pattern_capture") { } - /// + /// public IEnumerable Patterns { get; set; } - /// + /// public bool? PreserveOriginal { get; set; } } - /// - public class PatternCaptureTokenFilterDescriptor + + /// + public class PatternCaptureTokenFilterDescriptor : TokenFilterDescriptorBase, IPatternCaptureTokenFilter { protected override string Type => "pattern_capture"; + IEnumerable IPatternCaptureTokenFilter.Patterns { get; set; } bool? IPatternCaptureTokenFilter.PreserveOriginal { get; set; } - IEnumerable IPatternCaptureTokenFilter.Patterns { get; set; } - /// + /// public PatternCaptureTokenFilterDescriptor PreserveOriginal(bool? preserve = true) => Assign(a => a.PreserveOriginal = preserve); - /// + /// public PatternCaptureTokenFilterDescriptor Patterns(IEnumerable patterns) => Assign(a => a.Patterns = patterns); - /// + /// public PatternCaptureTokenFilterDescriptor Patterns(params string[] patterns) => Assign(a => a.Patterns = patterns); - } - } diff --git a/src/Nest/Analysis/TokenFilters/PatternReplaceTokenFilter.cs b/src/Nest/Analysis/TokenFilters/PatternReplaceTokenFilter.cs index 2029142c7ce..84d4d6bc5ac 100644 --- a/src/Nest/Analysis/TokenFilters/PatternReplaceTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/PatternReplaceTokenFilter.cs @@ -3,7 +3,7 @@ namespace Nest { /// - /// The pattern_replace token filter allows to easily handle string replacements based on a regular expression. + /// The pattern_replace token filter allows to easily handle string replacements based on a regular expression. /// public interface IPatternReplaceTokenFilter : ITokenFilter { @@ -19,19 +19,21 @@ public interface IPatternReplaceTokenFilter : ITokenFilter [JsonProperty("replacement")] string Replacement { get; set; } } - /// + + /// public class PatternReplaceTokenFilter : TokenFilterBase, IPatternReplaceTokenFilter { public PatternReplaceTokenFilter() : base("pattern_replace") { } - /// + /// public string Pattern { get; set; } - /// + /// public string Replacement { get; set; } } - /// - public class PatternReplaceTokenFilterDescriptor + + /// + public class PatternReplaceTokenFilterDescriptor : TokenFilterDescriptorBase, IPatternReplaceTokenFilter { protected override string Type => "pattern_replace"; @@ -40,12 +42,10 @@ public class PatternReplaceTokenFilterDescriptor string IPatternReplaceTokenFilter.Replacement { get; set; } - /// + /// public PatternReplaceTokenFilterDescriptor Pattern(string pattern) => Assign(a => a.Pattern = pattern); - /// + /// public PatternReplaceTokenFilterDescriptor Replacement(string replacement) => Assign(a => a.Replacement = replacement); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/PorterStemTokenFilter.cs b/src/Nest/Analysis/TokenFilters/PorterStemTokenFilter.cs index 74accd94eb2..50a6a2568e8 100644 --- a/src/Nest/Analysis/TokenFilters/PorterStemTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/PorterStemTokenFilter.cs @@ -4,16 +4,17 @@ /// A token filter of type porterStem that transforms the token stream as per the Porter stemming algorithm. /// public interface IPorterStemTokenFilter : ITokenFilter { } - /// + + /// public class PorterStemTokenFilter : TokenFilterBase, IPorterStemTokenFilter { public PorterStemTokenFilter() : base("porter_stem") { } } - /// - public class PorterStemTokenFilterDescriptor + + /// + public class PorterStemTokenFilterDescriptor : TokenFilterDescriptorBase, IPorterStemTokenFilter { protected override string Type => "porter_stem"; } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/RemoveDuplicatesTokenFilter.cs b/src/Nest/Analysis/TokenFilters/RemoveDuplicatesTokenFilter.cs index 8916cd1490b..3e59dd5da15 100644 --- a/src/Nest/Analysis/TokenFilters/RemoveDuplicatesTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/RemoveDuplicatesTokenFilter.cs @@ -1,22 +1,19 @@ -using System.Collections; -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Nest +namespace Nest { /// /// A token filter that drops identical tokens at the same position /// public interface IRemoveDuplicatesTokenFilter : ITokenFilter { } - /// + /// public class RemoveDuplicatesTokenFilter : TokenFilterBase, IRemoveDuplicatesTokenFilter { internal const string TokenType = "remove_duplicates"; + public RemoveDuplicatesTokenFilter() : base(TokenType) { } } - /// + /// public class RemoveDuplicatesTokenFilterDescriptor : TokenFilterDescriptorBase, IRemoveDuplicatesTokenFilter { diff --git a/src/Nest/Analysis/TokenFilters/ReverseTokenFilter.cs b/src/Nest/Analysis/TokenFilters/ReverseTokenFilter.cs index 469bb867155..32a2a4f2b0b 100644 --- a/src/Nest/Analysis/TokenFilters/ReverseTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/ReverseTokenFilter.cs @@ -4,16 +4,17 @@ /// A token filter of type reverse that simply reverses the tokens. /// public interface IReverseTokenFilter : ITokenFilter { } - /// + + /// public class ReverseTokenFilter : TokenFilterBase, IReverseTokenFilter { public ReverseTokenFilter() : base("reverse") { } } - /// - public class ReverseTokenFilterDescriptor + + /// + public class ReverseTokenFilterDescriptor : TokenFilterDescriptorBase, IReverseTokenFilter { protected override string Type => "reverse"; } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/Shingle/ShingleTokenFilter.cs b/src/Nest/Analysis/TokenFilters/Shingle/ShingleTokenFilter.cs index 47b72bc8a98..f61d4e0a5b2 100644 --- a/src/Nest/Analysis/TokenFilters/Shingle/ShingleTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/Shingle/ShingleTokenFilter.cs @@ -3,16 +3,17 @@ namespace Nest { /// - /// A token filter of type shingle that constructs shingles (token n-grams) from a token stream. + /// A token filter of type shingle that constructs shingles (token n-grams) from a token stream. /// In other words, it creates combinations of tokens as a single token. /// public interface IShingleTokenFilter : ITokenFilter { /// - /// The minimum shingle size. Defaults to 2. + /// The string to use as a replacement for each position at which there is no actual token in the stream. For instance this string is used if + /// the position increment is greater than one when a stop filter is used together with the shingle filter. Defaults to "_" /// - [JsonProperty("min_shingle_size")] - int? MinShingleSize { get; set; } + [JsonProperty("filler_token")] + string FillerToken { get; set; } /// /// The maximum shingle size. Defaults to 2. @@ -20,6 +21,12 @@ public interface IShingleTokenFilter : ITokenFilter [JsonProperty("max_shingle_size")] int? MaxShingleSize { get; set; } + /// + /// The minimum shingle size. Defaults to 2. + /// + [JsonProperty("min_shingle_size")] + int? MinShingleSize { get; set; } + /// /// If true the output will contain the input tokens (unigrams) as well as the shingles. Defaults to true. /// @@ -27,7 +34,7 @@ public interface IShingleTokenFilter : ITokenFilter bool? OutputUnigrams { get; set; } /// - /// If output_unigrams is false the output will contain the input tokens (unigrams) if no shingles are available. + /// If output_unigrams is false the output will contain the input tokens (unigrams) if no shingles are available. /// Note if output_unigrams is set to true this setting has no effect. Defaults to false. /// [JsonProperty("output_unigrams_if_no_shingles")] @@ -38,68 +45,62 @@ public interface IShingleTokenFilter : ITokenFilter /// [JsonProperty("token_separator")] string TokenSeparator { get; set; } - - /// - /// The string to use as a replacement for each position at which there is no actual token in the stream. For instance this string is used if the position increment is greater than one when a stop filter is used together with the shingle filter. Defaults to "_" - /// - [JsonProperty("filler_token")] - string FillerToken { get; set; } } - /// + /// public class ShingleTokenFilter : TokenFilterBase, IShingleTokenFilter { public ShingleTokenFilter() : base("shingle") { } - /// - public int? MinShingleSize { get; set; } + /// + public string FillerToken { get; set; } - /// + /// public int? MaxShingleSize { get; set; } - /// + /// + public int? MinShingleSize { get; set; } + + /// public bool? OutputUnigrams { get; set; } - /// + /// public bool? OutputUnigramsIfNoShingles { get; set; } - /// + /// public string TokenSeparator { get; set; } - - /// - public string FillerToken { get; set; } } - /// - public class ShingleTokenFilterDescriptor + + /// + public class ShingleTokenFilterDescriptor : TokenFilterDescriptorBase, IShingleTokenFilter { protected override string Type => "shingle"; + string IShingleTokenFilter.FillerToken { get; set; } + int? IShingleTokenFilter.MaxShingleSize { get; set; } + int? IShingleTokenFilter.MinShingleSize { get; set; } bool? IShingleTokenFilter.OutputUnigrams { get; set; } bool? IShingleTokenFilter.OutputUnigramsIfNoShingles { get; set; } - int? IShingleTokenFilter.MinShingleSize { get; set; } - int? IShingleTokenFilter.MaxShingleSize { get; set; } string IShingleTokenFilter.TokenSeparator { get; set; } - string IShingleTokenFilter.FillerToken { get; set; } - /// + /// public ShingleTokenFilterDescriptor OutputUnigrams(bool? output = true) => Assign(a => a.OutputUnigrams = output); - /// - public ShingleTokenFilterDescriptor OutputUnigramsIfNoShingles(bool? outputIfNo = true) => Assign(a => a.OutputUnigramsIfNoShingles = outputIfNo); + /// + public ShingleTokenFilterDescriptor OutputUnigramsIfNoShingles(bool? outputIfNo = true) => + Assign(a => a.OutputUnigramsIfNoShingles = outputIfNo); - /// + /// public ShingleTokenFilterDescriptor MinShingleSize(int? minShingleSize) => Assign(a => a.MinShingleSize = minShingleSize); - /// + /// public ShingleTokenFilterDescriptor MaxShingleSize(int? maxShingleSize) => Assign(a => a.MaxShingleSize = maxShingleSize); - /// + /// public ShingleTokenFilterDescriptor TokenSeparator(string separator) => Assign(a => a.TokenSeparator = separator); - /// + /// public ShingleTokenFilterDescriptor FillerToken(string filler) => Assign(a => a.FillerToken = filler); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/SnowballTokenFilter.cs b/src/Nest/Analysis/TokenFilters/SnowballTokenFilter.cs index 79c4f77e0e9..30dab4e1439 100644 --- a/src/Nest/Analysis/TokenFilters/SnowballTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/SnowballTokenFilter.cs @@ -11,26 +11,25 @@ public interface ISnowballTokenFilter : ITokenFilter SnowballLanguage? Language { get; set; } } - /// + /// public class SnowballTokenFilter : TokenFilterBase, ISnowballTokenFilter { public SnowballTokenFilter() : base("snowball") { } - /// + /// [JsonProperty("language")] public SnowballLanguage? Language { get; set; } - } - /// - public class SnowballTokenFilterDescriptor + + /// + public class SnowballTokenFilterDescriptor : TokenFilterDescriptorBase, ISnowballTokenFilter { protected override string Type => "snowball"; SnowballLanguage? ISnowballTokenFilter.Language { get; set; } - /// + /// public SnowballTokenFilterDescriptor Language(SnowballLanguage? language) => Assign(a => a.Language = language); } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/StandardTokenFilter.cs b/src/Nest/Analysis/TokenFilters/StandardTokenFilter.cs index e92f0007707..1b9aef0c122 100644 --- a/src/Nest/Analysis/TokenFilters/StandardTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/StandardTokenFilter.cs @@ -4,17 +4,17 @@ /// A token filter of type standard that normalizes tokens extracted with the Standard Tokenizer. /// public interface IStandardTokenFilter : ITokenFilter { } - /// + + /// public class StandardTokenFilter : TokenFilterBase, IStandardTokenFilter { public StandardTokenFilter() : base("standard") { } } - /// - public class StandardTokenFilterDescriptor + /// + public class StandardTokenFilterDescriptor : TokenFilterDescriptorBase, IStandardTokenFilter { protected override string Type => "standard"; } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/StemmerOverrideTokenFilter.cs b/src/Nest/Analysis/TokenFilters/StemmerOverrideTokenFilter.cs index 4bf2b231c54..7f1c5871a44 100644 --- a/src/Nest/Analysis/TokenFilters/StemmerOverrideTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/StemmerOverrideTokenFilter.cs @@ -4,7 +4,8 @@ namespace Nest { /// - /// Overrides stemming algorithms, by applying a custom mapping, then protecting these terms from being modified by stemmers. Must be placed before any stemming filters. + /// Overrides stemming algorithms, by applying a custom mapping, then protecting these terms from being modified by stemmers. Must be placed + /// before any stemming filters. /// public interface IStemmerOverrideTokenFilter : ITokenFilter { @@ -20,20 +21,21 @@ public interface IStemmerOverrideTokenFilter : ITokenFilter [JsonProperty("rules_path")] string RulesPath { get; set; } } - /// + + /// public class StemmerOverrideTokenFilter : TokenFilterBase, IStemmerOverrideTokenFilter { public StemmerOverrideTokenFilter() : base("stemmer_override") { } - /// + /// public IEnumerable Rules { get; set; } - /// + /// public string RulesPath { get; set; } - } - /// - public class StemmerOverrideTokenFilterDescriptor + + /// + public class StemmerOverrideTokenFilterDescriptor : TokenFilterDescriptorBase, IStemmerOverrideTokenFilter { protected override string Type => "stemmer_override"; @@ -41,15 +43,13 @@ public class StemmerOverrideTokenFilterDescriptor IEnumerable IStemmerOverrideTokenFilter.Rules { get; set; } string IStemmerOverrideTokenFilter.RulesPath { get; set; } - /// + /// public StemmerOverrideTokenFilterDescriptor Rules(IEnumerable rules) => Assign(a => a.Rules = rules); - /// + /// public StemmerOverrideTokenFilterDescriptor Rules(params string[] rules) => Assign(a => a.Rules = rules); - /// + /// public StemmerOverrideTokenFilterDescriptor RulesPath(string path) => Assign(a => a.RulesPath = path); - } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/StemmerTokenFilter.cs b/src/Nest/Analysis/TokenFilters/StemmerTokenFilter.cs index 9133292f316..8e4552fb0af 100644 --- a/src/Nest/Analysis/TokenFilters/StemmerTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/StemmerTokenFilter.cs @@ -10,23 +10,23 @@ public interface IStemmerTokenFilter : ITokenFilter [JsonProperty("language")] string Language { get; set; } } + public class StemmerTokenFilter : TokenFilterBase, IStemmerTokenFilter { public StemmerTokenFilter() : base("stemmer") { } public string Language { get; set; } - } - /// - public class StemmerTokenFilterDescriptor + + /// + public class StemmerTokenFilterDescriptor : TokenFilterDescriptorBase, IStemmerTokenFilter { protected override string Type => "stemmer"; string IStemmerTokenFilter.Language { get; set; } - /// + /// public StemmerTokenFilterDescriptor Language(string language) => Assign(a => a.Language = language); } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/Stop/StopTokenFilter.cs b/src/Nest/Analysis/TokenFilters/Stop/StopTokenFilter.cs index 21a24c19142..a7187f03057 100644 --- a/src/Nest/Analysis/TokenFilters/Stop/StopTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/Stop/StopTokenFilter.cs @@ -8,6 +8,20 @@ namespace Nest /// public interface IStopTokenFilter : ITokenFilter { + /// + /// Set to true to lower case all words first. Defaults to false. + /// + [JsonProperty("ignore_case")] + bool? IgnoreCase { get; set; } + + /// + /// Set to false in order to not ignore the last term of a search if it is a stop word. + /// This is very useful for the completion suggester as a query like green a can + /// be extended to green apple even though you remove stop words in general. Defaults to true. + /// + [JsonProperty("remove_trailing")] + bool? RemoveTrailing { get; set; } + /// /// A list of stop words to use. Defaults to `_english_` stop words. /// @@ -15,12 +29,6 @@ public interface IStopTokenFilter : ITokenFilter [JsonConverter(typeof(StopWordsJsonConverter))] StopWords StopWords { get; set; } - /// - /// Set to true to lower case all words first. Defaults to false. - /// - [JsonProperty("ignore_case")] - bool? IgnoreCase { get; set; } - /// /// A path (either relative to config location, or absolute) to a stopwords /// file configuration. Each stop word should be in its own "line" @@ -28,34 +36,27 @@ public interface IStopTokenFilter : ITokenFilter /// [JsonProperty("stopwords_path")] string StopWordsPath { get; set; } - - /// - /// Set to false in order to not ignore the last term of a search if it is a stop word. - /// This is very useful for the completion suggester as a query like green a can - /// be extended to green apple even though you remove stop words in general. Defaults to true. - /// - [JsonProperty("remove_trailing")] - bool? RemoveTrailing { get; set; } } - /// + /// public class StopTokenFilter : TokenFilterBase, IStopTokenFilter { public StopTokenFilter() : base("stop") { } - /// - public StopWords StopWords { get; set; } - - /// + /// public bool? IgnoreCase { get; set; } - /// - public string StopWordsPath { get; set; } - - /// + /// public bool? RemoveTrailing { get; set; } + + /// + public StopWords StopWords { get; set; } + + /// + public string StopWordsPath { get; set; } } - /// + + /// public class StopTokenFilterDescriptor : TokenFilterDescriptorBase, IStopTokenFilter { @@ -66,24 +67,22 @@ public class StopTokenFilterDescriptor StopWords IStopTokenFilter.StopWords { get; set; } string IStopTokenFilter.StopWordsPath { get; set; } - /// + /// public StopTokenFilterDescriptor IgnoreCase(bool? ignoreCase = true) => Assign(a => a.IgnoreCase = ignoreCase); - /// + /// public StopTokenFilterDescriptor RemoveTrailing(bool? removeTrailing = true) => Assign(a => a.RemoveTrailing = removeTrailing); - /// + /// public StopTokenFilterDescriptor StopWords(StopWords stopWords) => Assign(a => a.StopWords = stopWords); - /// + /// public StopTokenFilterDescriptor StopWords(IEnumerable stopWords) => Assign(a => a.StopWords = stopWords.ToListOrNullIfEmpty()); - /// + /// public StopTokenFilterDescriptor StopWords(params string[] stopWords) => Assign(a => a.StopWords = stopWords); - /// + /// public StopTokenFilterDescriptor StopWordsPath(string path) => Assign(a => a.StopWordsPath = path); - } - } diff --git a/src/Nest/Analysis/TokenFilters/Synonym/SynonymFormat.cs b/src/Nest/Analysis/TokenFilters/Synonym/SynonymFormat.cs index 11e226b5da8..5d1de75e498 100644 --- a/src/Nest/Analysis/TokenFilters/Synonym/SynonymFormat.cs +++ b/src/Nest/Analysis/TokenFilters/Synonym/SynonymFormat.cs @@ -9,7 +9,8 @@ public enum SynonymFormat { [EnumMember(Value = "solr")] Solr, + [EnumMember(Value = "wordnet")] WordNet } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/Synonym/SynonymGraphTokenFilter.cs b/src/Nest/Analysis/TokenFilters/Synonym/SynonymGraphTokenFilter.cs index db2ab8bc889..d8bf3e45d0f 100644 --- a/src/Nest/Analysis/TokenFilters/Synonym/SynonymGraphTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/Synonym/SynonymGraphTokenFilter.cs @@ -10,101 +10,100 @@ namespace Nest /// public interface ISynonymGraphTokenFilter : ITokenFilter { - /// - /// a path a synonyms file relative to the node's `config` location. - /// - [JsonProperty("synonyms_path")] - string SynonymsPath { get; set; } + [JsonProperty("expand")] + bool? Expand { get; set; } [JsonProperty("format")] SynonymFormat? Format { get; set; } - [JsonProperty("synonyms")] - IEnumerable Synonyms { get; set; } - [JsonProperty("ignore_case")] [Obsolete("Will be removed in Elasticsearch 7.x, if you need to ignore case add a lowercase filter before this synonym filter")] bool? IgnoreCase { get; set; } - [JsonProperty("expand")] - bool? Expand { get; set; } + /// + [JsonProperty("lenient")] + bool? Lenient { get; set; } + + [JsonProperty("synonyms")] + IEnumerable Synonyms { get; set; } + + /// + /// a path a synonyms file relative to the node's `config` location. + /// + [JsonProperty("synonyms_path")] + string SynonymsPath { get; set; } [JsonProperty("tokenizer")] string Tokenizer { get; set; } - - /// - [JsonProperty("lenient")] - bool? Lenient { get; set; } } - /// + /// public class SynonymGraphTokenFilter : TokenFilterBase, ISynonymGraphTokenFilter { public SynonymGraphTokenFilter() : base("synonym_graph") { } - /// - public string SynonymsPath { get; set; } + /// + public bool? Expand { get; set; } - /// + /// public SynonymFormat? Format { get; set; } - /// - public IEnumerable Synonyms { get; set; } - - /// + /// [Obsolete("Will be removed in Elasticsearch 7.x, if you need to ignore case add a lowercase filter before this synonym filter")] public bool? IgnoreCase { get; set; } - /// - public bool? Expand { get; set; } - - /// + /// public bool? Lenient { get; set; } - /// + /// + public IEnumerable Synonyms { get; set; } + + /// + public string SynonymsPath { get; set; } + + /// public string Tokenizer { get; set; } } - /// + + /// public class SynonymGraphTokenFilterDescriptor : TokenFilterDescriptorBase, ISynonymGraphTokenFilter { protected override string Type => "synonym_graph"; + bool? ISynonymGraphTokenFilter.Expand { get; set; } + SynonymFormat? ISynonymGraphTokenFilter.Format { get; set; } bool? ISynonymGraphTokenFilter.IgnoreCase { get; set; } - bool? ISynonymGraphTokenFilter.Expand { get; set; } bool? ISynonymGraphTokenFilter.Lenient { get; set; } - string ISynonymGraphTokenFilter.Tokenizer { get; set; } - string ISynonymGraphTokenFilter.SynonymsPath { get; set; } - SynonymFormat? ISynonymGraphTokenFilter.Format{ get; set; } IEnumerable ISynonymGraphTokenFilter.Synonyms { get; set; } + string ISynonymGraphTokenFilter.SynonymsPath { get; set; } + string ISynonymGraphTokenFilter.Tokenizer { get; set; } - /// + /// [Obsolete("Will be removed in Elasticsearch 7.x, if you need to ignore case add a lowercase filter before this synonym filter")] public SynonymGraphTokenFilterDescriptor IgnoreCase(bool? ignoreCase = true) => Assign(a => a.IgnoreCase = ignoreCase); - /// + /// public SynonymGraphTokenFilterDescriptor Expand(bool? expand = true) => Assign(a => a.Expand = expand); - /// + /// public SynonymGraphTokenFilterDescriptor Lenient(bool? lenient = true) => Assign(a => a.Lenient = lenient); - /// + /// public SynonymGraphTokenFilterDescriptor Tokenizer(string tokenizer) => Assign(a => a.Tokenizer = tokenizer); - /// + /// public SynonymGraphTokenFilterDescriptor SynonymsPath(string path) => Assign(a => a.SynonymsPath = path); - /// + /// public SynonymGraphTokenFilterDescriptor Format(SynonymFormat? format) => Assign(a => a.Format = format); - /// + /// public SynonymGraphTokenFilterDescriptor Synonyms(IEnumerable synonymGraphs) => Assign(a => a.Synonyms = synonymGraphs); - /// + /// public SynonymGraphTokenFilterDescriptor Synonyms(params string[] synonymGraphs) => Assign(a => a.Synonyms = synonymGraphs); - } - } diff --git a/src/Nest/Analysis/TokenFilters/Synonym/SynonymTokenFilter.cs b/src/Nest/Analysis/TokenFilters/Synonym/SynonymTokenFilter.cs index fbdb7f153f7..06182640cc2 100644 --- a/src/Nest/Analysis/TokenFilters/Synonym/SynonymTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/Synonym/SynonymTokenFilter.cs @@ -9,102 +9,101 @@ namespace Nest /// public interface ISynonymTokenFilter : ITokenFilter { - /// - /// a path a synonyms file relative to the node's `config` location. - /// - [JsonProperty("synonyms_path")] - string SynonymsPath { get; set; } + [JsonProperty("expand")] + bool? Expand { get; set; } [JsonProperty("format")] SynonymFormat? Format { get; set; } - [JsonProperty("synonyms")] - IEnumerable Synonyms { get; set; } - [JsonProperty("ignore_case")] [Obsolete("Will be removed in Elasticsearch 7.x, if you need to ignore case add a lowercase filter before this synonym filter")] bool? IgnoreCase { get; set; } - [JsonProperty("expand")] - bool? Expand { get; set; } - - [JsonProperty("tokenizer")] - string Tokenizer { get; set; } - /// /// If `true` ignores exceptions while parsing the synonym configuration. It is important // to note that only those synonym rules which cannot get parsed are ignored. /// [JsonProperty("lenient")] bool? Lenient { get; set; } + + [JsonProperty("synonyms")] + IEnumerable Synonyms { get; set; } + + /// + /// a path a synonyms file relative to the node's `config` location. + /// + [JsonProperty("synonyms_path")] + string SynonymsPath { get; set; } + + [JsonProperty("tokenizer")] + string Tokenizer { get; set; } } - /// + /// public class SynonymTokenFilter : TokenFilterBase, ISynonymTokenFilter { public SynonymTokenFilter() : base("synonym") { } - /// - public string SynonymsPath { get; set; } + /// + public bool? Expand { get; set; } - /// + /// public SynonymFormat? Format { get; set; } - /// - public IEnumerable Synonyms { get; set; } - - /// + /// [Obsolete("Will be removed in Elasticsearch 7.x, if you need to ignore case add a lowercase filter before this synonym filter")] public bool? IgnoreCase { get; set; } - /// - public bool? Expand { get; set; } - - /// + /// public bool? Lenient { get; set; } - /// + /// + public IEnumerable Synonyms { get; set; } + + /// + public string SynonymsPath { get; set; } + + /// public string Tokenizer { get; set; } } - /// + + /// public class SynonymTokenFilterDescriptor : TokenFilterDescriptorBase, ISynonymTokenFilter { protected override string Type => "synonym"; + bool? ISynonymTokenFilter.Expand { get; set; } + SynonymFormat? ISynonymTokenFilter.Format { get; set; } bool? ISynonymTokenFilter.IgnoreCase { get; set; } - bool? ISynonymTokenFilter.Expand { get; set; } bool? ISynonymTokenFilter.Lenient { get; set; } - string ISynonymTokenFilter.Tokenizer { get; set; } - string ISynonymTokenFilter.SynonymsPath { get; set; } - SynonymFormat? ISynonymTokenFilter.Format { get; set; } IEnumerable ISynonymTokenFilter.Synonyms { get; set; } + string ISynonymTokenFilter.SynonymsPath { get; set; } + string ISynonymTokenFilter.Tokenizer { get; set; } - /// + /// [Obsolete("Will be removed in Elasticsearch 7.x, if you need to ignore case add a lowercase filter before this synonym filter")] public SynonymTokenFilterDescriptor IgnoreCase(bool? ignoreCase = true) => Assign(a => a.IgnoreCase = ignoreCase); - /// + /// public SynonymTokenFilterDescriptor Expand(bool? expand = true) => Assign(a => a.Expand = expand); - /// + /// public SynonymTokenFilterDescriptor Lenient(bool? lenient = true) => Assign(a => a.Lenient = lenient); - /// + /// public SynonymTokenFilterDescriptor Tokenizer(string tokenizer) => Assign(a => a.Tokenizer = tokenizer); - /// + /// public SynonymTokenFilterDescriptor SynonymsPath(string path) => Assign(a => a.SynonymsPath = path); - /// + /// public SynonymTokenFilterDescriptor Format(SynonymFormat? format) => Assign(a => a.Format = format); - /// + /// public SynonymTokenFilterDescriptor Synonyms(IEnumerable synonyms) => Assign(a => a.Synonyms = synonyms); - /// + /// public SynonymTokenFilterDescriptor Synonyms(params string[] synonyms) => Assign(a => a.Synonyms = synonyms); - } - } diff --git a/src/Nest/Analysis/TokenFilters/TokenFilterBase.cs b/src/Nest/Analysis/TokenFilters/TokenFilterBase.cs index a13fe3a58a1..155a50233bb 100644 --- a/src/Nest/Analysis/TokenFilters/TokenFilterBase.cs +++ b/src/Nest/Analysis/TokenFilters/TokenFilterBase.cs @@ -5,38 +5,33 @@ namespace Nest [ContractJsonConverter(typeof(TokenFilterJsonConverter))] public interface ITokenFilter { - [JsonProperty("version")] - string Version { get; set; } - [JsonProperty("type")] string Type { get; } + [JsonProperty("version")] + string Version { get; set; } } public abstract class TokenFilterBase : ITokenFilter { - protected TokenFilterBase(string type) - { - this.Type = type; - } - - [JsonProperty("version")] - public string Version { get; set; } + protected TokenFilterBase(string type) => Type = type; [JsonProperty("type")] public string Type { get; protected set; } + + [JsonProperty("version")] + public string Version { get; set; } } - public abstract class TokenFilterDescriptorBase + public abstract class TokenFilterDescriptorBase : DescriptorBase, ITokenFilter where TTokenFilter : TokenFilterDescriptorBase, TTokenFilterInterface where TTokenFilterInterface : class, ITokenFilter { - string ITokenFilter.Version { get; set; } - string ITokenFilter.Type => this.Type; protected abstract string Type { get; } + string ITokenFilter.Type => Type; + string ITokenFilter.Version { get; set; } public TTokenFilter Version(string version) => Assign(a => a.Version = version); } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/TokenFilterJsonConverter.cs b/src/Nest/Analysis/TokenFilters/TokenFilterJsonConverter.cs index fc36dae5144..ab43f823164 100644 --- a/src/Nest/Analysis/TokenFilters/TokenFilterJsonConverter.cs +++ b/src/Nest/Analysis/TokenFilters/TokenFilterJsonConverter.cs @@ -6,19 +6,20 @@ namespace Nest { internal class TokenFilterJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) => true; - public override bool CanWrite => false; public override bool CanRead => true; + public override bool CanWrite => false; + + public override bool CanConvert(Type objectType) => true; public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - JObject o = JObject.Load(reader); + var o = JObject.Load(reader); - JProperty typeProperty = o.Property("type"); + var typeProperty = o.Property("type"); if (typeProperty == null) return null; var typePropertyValue = typeProperty.Value.ToString(); - switch(typePropertyValue.ToLowerInvariant()) + switch (typePropertyValue.ToLowerInvariant()) { case "asciifolding": return o.ToObject(ElasticContractResolver.Empty); case "common_grams": return o.ToObject(ElasticContractResolver.Empty); @@ -67,9 +68,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return null; } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotSupportedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); } } diff --git a/src/Nest/Analysis/TokenFilters/TokenFilters.cs b/src/Nest/Analysis/TokenFilters/TokenFilters.cs index a0bc22e0c02..55a04c40424 100644 --- a/src/Nest/Analysis/TokenFilters/TokenFilters.cs +++ b/src/Nest/Analysis/TokenFilters/TokenFilters.cs @@ -6,33 +6,23 @@ namespace Nest { [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] - public interface ITokenFilters : IIsADictionary - { - } + public interface ITokenFilters : IIsADictionary { } public class TokenFilters : IsADictionaryBase, ITokenFilters { - public TokenFilters() - { - } + public TokenFilters() { } - public TokenFilters(IDictionary container) : base(container) - { - } + public TokenFilters(IDictionary container) : base(container) { } public TokenFilters(Dictionary container) - : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) - { - } + : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) { } public void Add(string name, ITokenFilter analyzer) => BackingDictionary.Add(name, analyzer); } public class TokenFiltersDescriptor : IsADictionaryDescriptorBase { - public TokenFiltersDescriptor() : base(new TokenFilters()) - { - } + public TokenFiltersDescriptor() : base(new TokenFilters()) { } public TokenFiltersDescriptor UserDefined(string name, ITokenFilter analyzer) => Assign(name, analyzer); @@ -40,14 +30,16 @@ public TokenFiltersDescriptor() : base(new TokenFilters()) /// Token filters that allow to decompose compound words using a dictionary /// public TokenFiltersDescriptor DictionaryDecompounder(string name, - Func selector) => + Func selector + ) => Assign(name, selector?.Invoke(new DictionaryDecompounderTokenFilterDescriptor())); /// /// Token filters that allow to decompose compound words using FOP XML /// public TokenFiltersDescriptor HyphenationDecompounder(string name, - Func selector) => + Func selector + ) => Assign(name, selector?.Invoke(new HyphenationDecompounderTokenFilterDescriptor())); /// @@ -99,7 +91,9 @@ public TokenFiltersDescriptor WordDelimiter(string name, Func not in the first 127 ASCII characters (the “Basic Latin” Unicode block) into their ASCII equivalents, if one exists. /// - public TokenFiltersDescriptor WordDelimiterGraph(string name, Func selector) => + public TokenFiltersDescriptor WordDelimiterGraph(string name, + Func selector + ) => Assign(name, selector?.Invoke(new WordDelimiterGraphTokenFilterDescriptor())); /// @@ -110,8 +104,8 @@ public TokenFiltersDescriptor AsciiFolding(string name, Func - /// Token filter that generates bigrams for frequently occuring terms. Single terms are still indexed. - ///Note, common_words or common_words_path field is required. + /// Token filter that generates bigrams for frequently occuring terms. Single terms are still indexed. + /// Note, common_words or common_words_path field is required. /// public TokenFiltersDescriptor CommonGrams(string name, Func selector) => Assign(name, selector?.Invoke(new CommonGramsTokenFilterDescriptor())); @@ -119,7 +113,8 @@ public TokenFiltersDescriptor CommonGrams(string name, Func /// Splits tokens into tokens and payload whenever a delimiter character is found. /// - public TokenFiltersDescriptor DelimitedPayload(string name, Func selector) => + public TokenFiltersDescriptor DelimitedPayload(string name, Func selector + ) => Assign(name, selector?.Invoke(new DelimitedPayloadTokenFilterDescriptor())); /// @@ -129,8 +124,8 @@ public TokenFiltersDescriptor Elision(string name, Func - /// Basic support for hunspell stemming. - /// Hunspell dictionaries will be picked up from a dedicated hunspell directory on the filesystem. + /// Basic support for hunspell stemming. + /// Hunspell dictionaries will be picked up from a dedicated hunspell directory on the filesystem. /// public TokenFiltersDescriptor Hunspell(string name, Func selector) => Assign(name, selector?.Invoke(new HunspellTokenFilterDescriptor())); @@ -154,8 +149,8 @@ public TokenFiltersDescriptor KeywordMarker(string name, Func - ///The kstem token filter is a high performance filter for english. - /// All terms must already be lowercased (use lowercase filter) for this filter to work correctly. + /// The kstem token filter is a high performance filter for english. + /// All terms must already be lowercased (use lowercase filter) for this filter to work correctly. /// public TokenFiltersDescriptor KStem(string name, Func selector = null) => Assign(name, selector.InvokeOrDefault(new KStemTokenFilterDescriptor())); @@ -169,12 +164,13 @@ public TokenFiltersDescriptor Length(string name, Func /// Limits the number of tokens that are indexed per document and field. /// - public TokenFiltersDescriptor LimitTokenCount(string name, Func selector) => + public TokenFiltersDescriptor LimitTokenCount(string name, Func selector + ) => Assign(name, selector?.Invoke(new LimitTokenCountTokenFilterDescriptor())); /// - /// A token filter of type lowercase that normalizes token text to lower case. - /// Lowercase token filter supports Greek and Turkish lowercase token filters through the language parameter. + /// A token filter of type lowercase that normalizes token text to lower case. + /// Lowercase token filter supports Greek and Turkish lowercase token filters through the language parameter. /// public TokenFiltersDescriptor Lowercase(string name, Func selector = null) => Assign(name, selector.InvokeOrDefault(new LowercaseTokenFilterDescriptor())); @@ -228,9 +224,11 @@ public TokenFiltersDescriptor Stemmer(string name, Func - /// Overrides stemming algorithms, by applying a custom mapping, then protecting these terms from being modified by stemmers. Must be placed before any stemming filters. + /// Overrides stemming algorithms, by applying a custom mapping, then protecting these terms from being modified by stemmers. Must be placed + /// before any stemming filters. /// - public TokenFiltersDescriptor StemmerOverride(string name, Func selector) => + public TokenFiltersDescriptor StemmerOverride(string name, Func selector + ) => Assign(name, selector?.Invoke(new StemmerOverrideTokenFilterDescriptor())); /// @@ -271,26 +269,33 @@ public TokenFiltersDescriptor Fingerprint(string name, Func - public TokenFiltersDescriptor KuromojiStemmer(string name, Func selector = null) => + public TokenFiltersDescriptor KuromojiStemmer(string name, + Func selector = null + ) => Assign(name, selector.InvokeOrDefault(new KuromojiStemmerTokenFilterDescriptor())); /// /// The kuromoji_readingform token filter replaces the token with its reading form in either katakana or romaji. /// Part of the `analysis-kuromoji` plugin: https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-kuromoji.html /// - public TokenFiltersDescriptor KuromojiReadingForm(string name, Func selector) => + public TokenFiltersDescriptor KuromojiReadingForm(string name, + Func selector + ) => Assign(name, selector.Invoke(new KuromojiReadingFormTokenFilterDescriptor())); /// /// The kuromoji_part_of_speech token filter removes tokens that match a set of part-of-speech tags. /// Part of the `analysis-kuromoji` plugin: https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-kuromoji.html /// - public TokenFiltersDescriptor KuromojiPartOfSpeech(string name, Func selector) => + public TokenFiltersDescriptor KuromojiPartOfSpeech(string name, + Func selector + ) => Assign(name, selector.Invoke(new KuromojiPartOfSpeechTokenFilterDescriptor())); /// - /// Collations are used for sorting documents in a language-specific word order. The icu_collation token filter is available to all indices and defaults to using the DUCET collation, which is a best-effort attempt at language-neutral sorting. + /// Collations are used for sorting documents in a language-specific word order. The icu_collation token filter is available to all indices and + /// defaults to using the DUCET collation, which is a best-effort attempt at language-neutral sorting. /// Part of the `analysis-icu` plugin: https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-icu.html /// public TokenFiltersDescriptor IcuCollation(string name, Func selector) => @@ -307,7 +312,8 @@ public TokenFiltersDescriptor IcuFolding(string name, Func - public TokenFiltersDescriptor IcuNormalization(string name, Func selector) => + public TokenFiltersDescriptor IcuNormalization(string name, Func selector + ) => Assign(name, selector.Invoke(new IcuNormalizationTokenFilterDescriptor())); /// @@ -318,8 +324,9 @@ public TokenFiltersDescriptor IcuNormalization(string name, Func selector) => Assign(name, selector.Invoke(new IcuTransformTokenFilterDescriptor())); - /// - public TokenFiltersDescriptor NoriPartOfSpeech(string name, Func selector) => + /// + public TokenFiltersDescriptor NoriPartOfSpeech(string name, Func selector + ) => Assign(name, selector.Invoke(new NoriPartOfSpeechTokenFilterDescriptor())); /// @@ -330,7 +337,9 @@ public TokenFiltersDescriptor Multiplexer(string name, Func A token filter of type remove_duplicates that drops identical tokens at the same position. - public TokenFiltersDescriptor RemoveDuplicates(string name, Func selector = null) => + public TokenFiltersDescriptor RemoveDuplicates(string name, + Func selector = null + ) => Assign(name, selector.InvokeOrDefault(new RemoveDuplicatesTokenFilterDescriptor())); } } diff --git a/src/Nest/Analysis/TokenFilters/TrimTokenFilter.cs b/src/Nest/Analysis/TokenFilters/TrimTokenFilter.cs index e204728eae2..313b5636f45 100644 --- a/src/Nest/Analysis/TokenFilters/TrimTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/TrimTokenFilter.cs @@ -5,15 +5,16 @@ /// public interface ITrimTokenFilter : ITokenFilter { } - /// + /// public class TrimTokenFilter : TokenFilterBase, ITrimTokenFilter { public TrimTokenFilter() : base("trim") { } } - /// - public class TrimTokenFilterDescriptor + + /// + public class TrimTokenFilterDescriptor : TokenFilterDescriptorBase, ITrimTokenFilter { protected override string Type => "trim"; } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/TruncateTokenFilter.cs b/src/Nest/Analysis/TokenFilters/TruncateTokenFilter.cs index 117bf514dea..d5a310c4f0f 100644 --- a/src/Nest/Analysis/TokenFilters/TruncateTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/TruncateTokenFilter.cs @@ -3,7 +3,7 @@ namespace Nest { /// - /// The truncate token filter can be used to truncate tokens into a specific length. This can come in handy with keyword (single token) + /// The truncate token filter can be used to truncate tokens into a specific length. This can come in handy with keyword (single token) /// based mapped fields that are used for sorting in order to reduce memory usage. /// public interface ITruncateTokenFilter : ITokenFilter @@ -13,26 +13,26 @@ public interface ITruncateTokenFilter : ITokenFilter /// [JsonProperty("length")] int? Length { get; set; } - } + } - /// + /// public class TruncateTokenFilter : TokenFilterBase, ITruncateTokenFilter { public TruncateTokenFilter() : base("truncate") { } - /// + /// public int? Length { get; set; } } - /// - public class TruncateTokenFilterDescriptor + + /// + public class TruncateTokenFilterDescriptor : TokenFilterDescriptorBase, ITruncateTokenFilter { protected override string Type => "truncate"; int? ITruncateTokenFilter.Length { get; set; } - /// + /// public TruncateTokenFilterDescriptor Length(int? length) => Assign(a => a.Length = length); } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/UniqueTokenFilter.cs b/src/Nest/Analysis/TokenFilters/UniqueTokenFilter.cs index 4495357da5b..dcdc44cec41 100644 --- a/src/Nest/Analysis/TokenFilters/UniqueTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/UniqueTokenFilter.cs @@ -14,25 +14,24 @@ public interface IUniqueTokenFilter : ITokenFilter bool? OnlyOnSamePosition { get; set; } } - /// + /// public class UniqueTokenFilter : TokenFilterBase, IUniqueTokenFilter { public UniqueTokenFilter() : base("unique") { } - /// + /// public bool? OnlyOnSamePosition { get; set; } } - /// - public class UniqueTokenFilterDescriptor + /// + public class UniqueTokenFilterDescriptor : TokenFilterDescriptorBase, IUniqueTokenFilter { protected override string Type => "unique"; bool? IUniqueTokenFilter.OnlyOnSamePosition { get; set; } - /// + /// public UniqueTokenFilterDescriptor OnlyOnSamePosition(bool? samePositionOnly = true) => Assign(a => a.OnlyOnSamePosition = samePositionOnly); } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/UppercaseTokenFilter.cs b/src/Nest/Analysis/TokenFilters/UppercaseTokenFilter.cs index dc3ace155b3..832e8282078 100644 --- a/src/Nest/Analysis/TokenFilters/UppercaseTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/UppercaseTokenFilter.cs @@ -5,17 +5,16 @@ /// public interface IUppercaseTokenFilter : ITokenFilter { } - /// + /// public class UppercaseTokenFilter : TokenFilterBase, IUppercaseTokenFilter { public UppercaseTokenFilter() : base("uppercase") { } } - /// - public class UppercaseTokenFilterDescriptor + /// + public class UppercaseTokenFilterDescriptor : TokenFilterDescriptorBase, IUppercaseTokenFilter { protected override string Type => "uppercase"; } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/TokenFilters/WordDelimiter/WordDelimiterTokenFilter.cs b/src/Nest/Analysis/TokenFilters/WordDelimiter/WordDelimiterTokenFilter.cs index 56e104d3fcf..1bd832fd798 100644 --- a/src/Nest/Analysis/TokenFilters/WordDelimiter/WordDelimiterTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/WordDelimiter/WordDelimiterTokenFilter.cs @@ -9,16 +9,16 @@ namespace Nest public interface IWordDelimiterTokenFilter : ITokenFilter { /// - /// If true causes parts of words to be generated: "PowerShot" ⇒ "Power" "Shot". Defaults to true. + /// If true causes all subword parts to be catenated: "wi-fi-4000" ⇒ "wifi4000". Defaults to false. /// - [JsonProperty("generate_word_parts")] - bool? GenerateWordParts { get; set; } + [JsonProperty("catenate_all")] + bool? CatenateAll { get; set; } /// - /// If true causes number subwords to be generated: "500-42" ⇒ "500" "42". Defaults to true. + /// If true causes maximum runs of number parts to be catenated: "500-42" ⇒ "50042". Defaults to false. /// - [JsonProperty("generate_number_parts")] - bool? GenerateNumberParts { get; set; } + [JsonProperty("catenate_numbers")] + bool? CatenateNumbers { get; set; } /// /// If true causes maximum runs of word parts to be catenated: "wi-fi" ⇒ "wifi". Defaults to false. @@ -27,22 +27,16 @@ public interface IWordDelimiterTokenFilter : ITokenFilter bool? CatenateWords { get; set; } /// - /// If true causes maximum runs of number parts to be catenated: "500-42" ⇒ "50042". Defaults to false. - /// - [JsonProperty("catenate_numbers")] - bool? CatenateNumbers { get; set; } - - /// - /// If true causes all subword parts to be catenated: "wi-fi-4000" ⇒ "wifi4000". Defaults to false. + /// If true causes number subwords to be generated: "500-42" ⇒ "500" "42". Defaults to true. /// - [JsonProperty("catenate_all")] - bool? CatenateAll { get; set; } + [JsonProperty("generate_number_parts")] + bool? GenerateNumberParts { get; set; } /// - /// If true causes "PowerShot" to be two tokens; ("Power-Shot" remains two parts regards). Defaults to true. + /// If true causes parts of words to be generated: "PowerShot" ⇒ "Power" "Shot". Defaults to true. /// - [JsonProperty("split_on_case_change")] - bool? SplitOnCaseChange { get; set; } + [JsonProperty("generate_word_parts")] + bool? GenerateWordParts { get; set; } /// /// If true includes original words in subwords: "500-42" ⇒ "500-42" "500" "42". Defaults to false. @@ -51,29 +45,35 @@ public interface IWordDelimiterTokenFilter : ITokenFilter bool? PreserveOriginal { get; set; } /// - /// If true causes "j2se" to be three tokens; "j" "2" "se". Defaults to true. + /// A list of protected words from being delimiter. /// - [JsonProperty("split_on_numerics")] - bool? SplitOnNumerics { get; set; } + [JsonProperty("protected_words")] + IEnumerable ProtectedWords { get; set; } /// - /// If true causes trailing "'s" to be removed for each subword: "O’Neil’s" ⇒ "O", "Neil". Defaults to true. + /// protected_words_path which resolved to a file configured with protected words (one on each line). + /// Automatically resolves to config/ based location if exists. /// - [JsonProperty("stem_english_possessive")] - bool? StemEnglishPossessive { get; set; } + [JsonProperty("protected_words_path ")] + string ProtectedWordsPath { get; set; } /// - /// A list of protected words from being delimiter. + /// If true causes "PowerShot" to be two tokens; ("Power-Shot" remains two parts regards). Defaults to true. /// - [JsonProperty("protected_words")] - IEnumerable ProtectedWords { get; set; } + [JsonProperty("split_on_case_change")] + bool? SplitOnCaseChange { get; set; } /// - ///protected_words_path which resolved to a file configured with protected words (one on each line). - /// Automatically resolves to config/ based location if exists. + /// If true causes "j2se" to be three tokens; "j" "2" "se". Defaults to true. /// - [JsonProperty("protected_words_path ")] - string ProtectedWordsPath { get; set; } + [JsonProperty("split_on_numerics")] + bool? SplitOnNumerics { get; set; } + + /// + /// If true causes trailing "'s" to be removed for each subword: "O’Neil’s" ⇒ "O", "Neil". Defaults to true. + /// + [JsonProperty("stem_english_possessive")] + bool? StemEnglishPossessive { get; set; } /// /// A custom type mapping table @@ -86,119 +86,119 @@ public interface IWordDelimiterTokenFilter : ITokenFilter /// [JsonProperty("type_table_path")] string TypeTablePath { get; set; } - } - /// + /// public class WordDelimiterTokenFilter : TokenFilterBase, IWordDelimiterTokenFilter { public WordDelimiterTokenFilter() : base("word_delimiter") { } - /// - public bool? GenerateWordParts { get; set; } + /// + public bool? CatenateAll { get; set; } - /// - public bool? GenerateNumberParts { get; set; } + /// + public bool? CatenateNumbers { get; set; } - /// + /// public bool? CatenateWords { get; set; } - /// - public bool? CatenateNumbers { get; set; } - - /// - public bool? CatenateAll { get; set; } + /// + public bool? GenerateNumberParts { get; set; } - /// - public bool? SplitOnCaseChange { get; set; } + /// + public bool? GenerateWordParts { get; set; } - /// + /// public bool? PreserveOriginal { get; set; } - /// - public bool? SplitOnNumerics { get; set; } - - /// - public bool? StemEnglishPossessive { get; set; } - - /// + /// public IEnumerable ProtectedWords { get; set; } - /// + /// public string ProtectedWordsPath { get; set; } - /// + /// + public bool? SplitOnCaseChange { get; set; } + + /// + public bool? SplitOnNumerics { get; set; } + + /// + public bool? StemEnglishPossessive { get; set; } + + /// public IEnumerable TypeTable { get; set; } - /// + /// public string TypeTablePath { get; set; } } - /// - public class WordDelimiterTokenFilterDescriptor + /// + public class WordDelimiterTokenFilterDescriptor : TokenFilterDescriptorBase, IWordDelimiterTokenFilter { protected override string Type => "word_delimiter"; + bool? IWordDelimiterTokenFilter.CatenateAll { get; set; } + bool? IWordDelimiterTokenFilter.CatenateNumbers { get; set; } + bool? IWordDelimiterTokenFilter.CatenateWords { get; set; } + bool? IWordDelimiterTokenFilter.GenerateNumberParts { get; set; } + bool? IWordDelimiterTokenFilter.GenerateWordParts { get; set; } + bool? IWordDelimiterTokenFilter.PreserveOriginal { get; set; } IEnumerable IWordDelimiterTokenFilter.ProtectedWords { get; set; } string IWordDelimiterTokenFilter.ProtectedWordsPath { get; set; } - IEnumerable IWordDelimiterTokenFilter.TypeTable { get; set; } - string IWordDelimiterTokenFilter.TypeTablePath { get; set; } - bool? IWordDelimiterTokenFilter.GenerateWordParts { get; set; } - bool? IWordDelimiterTokenFilter.GenerateNumberParts { get; set; } - bool? IWordDelimiterTokenFilter.CatenateWords { get; set; } - bool? IWordDelimiterTokenFilter.CatenateNumbers { get; set; } - bool? IWordDelimiterTokenFilter.CatenateAll { get; set; } bool? IWordDelimiterTokenFilter.SplitOnCaseChange { get; set; } - bool? IWordDelimiterTokenFilter.PreserveOriginal { get; set; } bool? IWordDelimiterTokenFilter.SplitOnNumerics { get; set; } bool? IWordDelimiterTokenFilter.StemEnglishPossessive { get; set; } + IEnumerable IWordDelimiterTokenFilter.TypeTable { get; set; } + string IWordDelimiterTokenFilter.TypeTablePath { get; set; } - /// - public WordDelimiterTokenFilterDescriptor GenerateWordParts(bool? generateWordParts = true) => Assign(a => a.GenerateWordParts = generateWordParts); + /// + public WordDelimiterTokenFilterDescriptor GenerateWordParts(bool? generateWordParts = true) => + Assign(a => a.GenerateWordParts = generateWordParts); - /// - public WordDelimiterTokenFilterDescriptor GenerateNumberParts(bool? generateNumberParts = true) => Assign(a => a.GenerateNumberParts = generateNumberParts); + /// + public WordDelimiterTokenFilterDescriptor GenerateNumberParts(bool? generateNumberParts = true) => + Assign(a => a.GenerateNumberParts = generateNumberParts); - /// + /// public WordDelimiterTokenFilterDescriptor CatenateWords(bool? catenateWords = true) => Assign(a => a.CatenateWords = catenateWords); - /// + /// public WordDelimiterTokenFilterDescriptor CatenateNumbers(bool? catenateNumbers = true) => Assign(a => a.CatenateNumbers = catenateNumbers); - /// + /// public WordDelimiterTokenFilterDescriptor CatenateAll(bool? catenateAll = true) => Assign(a => a.CatenateAll = catenateAll); - /// + /// public WordDelimiterTokenFilterDescriptor SplitOnCaseChange(bool? split = true) => Assign(a => a.SplitOnCaseChange = split); - /// + /// public WordDelimiterTokenFilterDescriptor SplitOnNumerics(bool? split = true) => Assign(a => a.SplitOnNumerics = split); - /// + /// public WordDelimiterTokenFilterDescriptor PreserveOriginal(bool? preserve = true) => Assign(a => a.PreserveOriginal = preserve); - /// + /// public WordDelimiterTokenFilterDescriptor StemEnglishPossessive(bool? stem = true) => Assign(a => a.StemEnglishPossessive = stem); - /// - public WordDelimiterTokenFilterDescriptor ProtectedWords(IEnumerable protectedWords) => Assign(a => a.ProtectedWords = protectedWords); + /// + public WordDelimiterTokenFilterDescriptor ProtectedWords(IEnumerable protectedWords) => + Assign(a => a.ProtectedWords = protectedWords); - /// + /// public WordDelimiterTokenFilterDescriptor ProtectedWords(params string[] protectedWords) => Assign(a => a.ProtectedWords = protectedWords); - /// + /// public WordDelimiterTokenFilterDescriptor ProtectedWordsPath(string path) => Assign(a => a.ProtectedWordsPath = path); - /// + /// public WordDelimiterTokenFilterDescriptor TypeTable(IEnumerable typeTable) => Assign(a => a.TypeTable = typeTable); - /// + /// public WordDelimiterTokenFilterDescriptor TypeTable(params string[] typeTable) => Assign(a => a.TypeTable = typeTable); - /// + /// public WordDelimiterTokenFilterDescriptor TypeTablePath(string path) => Assign(a => a.TypeTablePath = path); - } - } diff --git a/src/Nest/Analysis/TokenFilters/WordDelimiterGraph/WordDelimiterGraphTokenFilter.cs b/src/Nest/Analysis/TokenFilters/WordDelimiterGraph/WordDelimiterGraphTokenFilter.cs index 12e84aa707c..15dba2f4ae9 100644 --- a/src/Nest/Analysis/TokenFilters/WordDelimiterGraph/WordDelimiterGraphTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/WordDelimiterGraph/WordDelimiterGraphTokenFilter.cs @@ -10,16 +10,16 @@ namespace Nest public interface IWordDelimiterGraphTokenFilter : ITokenFilter { /// - /// If true causes parts of words to be generated: "PowerShot" ⇒ "Power" "Shot". Defaults to true. + /// If true causes all subword parts to be catenated: "wi-fi-4000" ⇒ "wifi4000". Defaults to false. /// - [JsonProperty("generate_word_parts")] - bool? GenerateWordParts { get; set; } + [JsonProperty("catenate_all")] + bool? CatenateAll { get; set; } /// - /// If true causes number subwords to be generated: "500-42" ⇒ "500" "42". Defaults to true. + /// If true causes maximum runs of number parts to be catenated: "500-42" ⇒ "50042". Defaults to false. /// - [JsonProperty("generate_number_parts")] - bool? GenerateNumberParts { get; set; } + [JsonProperty("catenate_numbers")] + bool? CatenateNumbers { get; set; } /// /// If true causes maximum runs of word parts to be catenated: "wi-fi" ⇒ "wifi". Defaults to false. @@ -28,22 +28,16 @@ public interface IWordDelimiterGraphTokenFilter : ITokenFilter bool? CatenateWords { get; set; } /// - /// If true causes maximum runs of number parts to be catenated: "500-42" ⇒ "50042". Defaults to false. - /// - [JsonProperty("catenate_numbers")] - bool? CatenateNumbers { get; set; } - - /// - /// If true causes all subword parts to be catenated: "wi-fi-4000" ⇒ "wifi4000". Defaults to false. + /// If true causes number subwords to be generated: "500-42" ⇒ "500" "42". Defaults to true. /// - [JsonProperty("catenate_all")] - bool? CatenateAll { get; set; } + [JsonProperty("generate_number_parts")] + bool? GenerateNumberParts { get; set; } /// - /// If true causes "PowerShot" to be two tokens; ("Power-Shot" remains two parts regards). Defaults to true. + /// If true causes parts of words to be generated: "PowerShot" ⇒ "Power" "Shot". Defaults to true. /// - [JsonProperty("split_on_case_change")] - bool? SplitOnCaseChange { get; set; } + [JsonProperty("generate_word_parts")] + bool? GenerateWordParts { get; set; } /// /// If true includes original words in subwords: "500-42" ⇒ "500-42" "500" "42". Defaults to false. @@ -52,29 +46,35 @@ public interface IWordDelimiterGraphTokenFilter : ITokenFilter bool? PreserveOriginal { get; set; } /// - /// If true causes "j2se" to be three tokens; "j" "2" "se". Defaults to true. + /// A list of protected words from being delimiter. /// - [JsonProperty("split_on_numerics")] - bool? SplitOnNumerics { get; set; } + [JsonProperty("protected_words")] + IEnumerable ProtectedWords { get; set; } /// - /// If true causes trailing "'s" to be removed for each subword: "O’Neil’s" ⇒ "O", "Neil". Defaults to true. + /// protected_words_path which resolved to a file configured with protected words (one on each line). + /// Automatically resolves to config/ based location if exists. /// - [JsonProperty("stem_english_possessive")] - bool? StemEnglishPossessive { get; set; } + [JsonProperty("protected_words_path ")] + string ProtectedWordsPath { get; set; } /// - /// A list of protected words from being delimiter. + /// If true causes "PowerShot" to be two tokens; ("Power-Shot" remains two parts regards). Defaults to true. /// - [JsonProperty("protected_words")] - IEnumerable ProtectedWords { get; set; } + [JsonProperty("split_on_case_change")] + bool? SplitOnCaseChange { get; set; } /// - ///protected_words_path which resolved to a file configured with protected words (one on each line). - /// Automatically resolves to config/ based location if exists. + /// If true causes "j2se" to be three tokens; "j" "2" "se". Defaults to true. /// - [JsonProperty("protected_words_path ")] - string ProtectedWordsPath { get; set; } + [JsonProperty("split_on_numerics")] + bool? SplitOnNumerics { get; set; } + + /// + /// If true causes trailing "'s" to be removed for each subword: "O’Neil’s" ⇒ "O", "Neil". Defaults to true. + /// + [JsonProperty("stem_english_possessive")] + bool? StemEnglishPossessive { get; set; } /// /// A custom type mapping table @@ -87,119 +87,121 @@ public interface IWordDelimiterGraphTokenFilter : ITokenFilter /// [JsonProperty("type_table_path")] string TypeTablePath { get; set; } - } - /// + /// public class WordDelimiterGraphTokenFilter : TokenFilterBase, IWordDelimiterGraphTokenFilter { public WordDelimiterGraphTokenFilter() : base("word_delimiter_graph") { } - /// - public bool? GenerateWordParts { get; set; } + /// + public bool? CatenateAll { get; set; } - /// - public bool? GenerateNumberParts { get; set; } + /// + public bool? CatenateNumbers { get; set; } - /// + /// public bool? CatenateWords { get; set; } - /// - public bool? CatenateNumbers { get; set; } - - /// - public bool? CatenateAll { get; set; } + /// + public bool? GenerateNumberParts { get; set; } - /// - public bool? SplitOnCaseChange { get; set; } + /// + public bool? GenerateWordParts { get; set; } - /// + /// public bool? PreserveOriginal { get; set; } - /// - public bool? SplitOnNumerics { get; set; } - - /// - public bool? StemEnglishPossessive { get; set; } - - /// + /// public IEnumerable ProtectedWords { get; set; } - /// + /// public string ProtectedWordsPath { get; set; } - /// + /// + public bool? SplitOnCaseChange { get; set; } + + /// + public bool? SplitOnNumerics { get; set; } + + /// + public bool? StemEnglishPossessive { get; set; } + + /// public IEnumerable TypeTable { get; set; } - /// + /// public string TypeTablePath { get; set; } } - /// + /// public class WordDelimiterGraphTokenFilterDescriptor : TokenFilterDescriptorBase, IWordDelimiterGraphTokenFilter { protected override string Type => "word_delimiter_graph"; + bool? IWordDelimiterGraphTokenFilter.CatenateAll { get; set; } + bool? IWordDelimiterGraphTokenFilter.CatenateNumbers { get; set; } + bool? IWordDelimiterGraphTokenFilter.CatenateWords { get; set; } + bool? IWordDelimiterGraphTokenFilter.GenerateNumberParts { get; set; } + bool? IWordDelimiterGraphTokenFilter.GenerateWordParts { get; set; } + bool? IWordDelimiterGraphTokenFilter.PreserveOriginal { get; set; } IEnumerable IWordDelimiterGraphTokenFilter.ProtectedWords { get; set; } string IWordDelimiterGraphTokenFilter.ProtectedWordsPath { get; set; } - IEnumerable IWordDelimiterGraphTokenFilter.TypeTable { get; set; } - string IWordDelimiterGraphTokenFilter.TypeTablePath { get; set; } - bool? IWordDelimiterGraphTokenFilter.GenerateWordParts { get; set; } - bool? IWordDelimiterGraphTokenFilter.GenerateNumberParts { get; set; } - bool? IWordDelimiterGraphTokenFilter.CatenateWords { get; set; } - bool? IWordDelimiterGraphTokenFilter.CatenateNumbers { get; set; } - bool? IWordDelimiterGraphTokenFilter.CatenateAll { get; set; } bool? IWordDelimiterGraphTokenFilter.SplitOnCaseChange { get; set; } - bool? IWordDelimiterGraphTokenFilter.PreserveOriginal { get; set; } bool? IWordDelimiterGraphTokenFilter.SplitOnNumerics { get; set; } bool? IWordDelimiterGraphTokenFilter.StemEnglishPossessive { get; set; } + IEnumerable IWordDelimiterGraphTokenFilter.TypeTable { get; set; } + string IWordDelimiterGraphTokenFilter.TypeTablePath { get; set; } - /// - public WordDelimiterGraphTokenFilterDescriptor GenerateWordParts(bool? generateWordParts = true) => Assign(a => a.GenerateWordParts = generateWordParts); + /// + public WordDelimiterGraphTokenFilterDescriptor GenerateWordParts(bool? generateWordParts = true) => + Assign(a => a.GenerateWordParts = generateWordParts); - /// - public WordDelimiterGraphTokenFilterDescriptor GenerateNumberParts(bool? generateNumberParts = true) => Assign(a => a.GenerateNumberParts = generateNumberParts); + /// + public WordDelimiterGraphTokenFilterDescriptor GenerateNumberParts(bool? generateNumberParts = true) => + Assign(a => a.GenerateNumberParts = generateNumberParts); - /// + /// public WordDelimiterGraphTokenFilterDescriptor CatenateWords(bool? catenateWords = true) => Assign(a => a.CatenateWords = catenateWords); - /// - public WordDelimiterGraphTokenFilterDescriptor CatenateNumbers(bool? catenateNumbers = true) => Assign(a => a.CatenateNumbers = catenateNumbers); + /// + public WordDelimiterGraphTokenFilterDescriptor CatenateNumbers(bool? catenateNumbers = true) => + Assign(a => a.CatenateNumbers = catenateNumbers); - /// + /// public WordDelimiterGraphTokenFilterDescriptor CatenateAll(bool? catenateAll = true) => Assign(a => a.CatenateAll = catenateAll); - /// + /// public WordDelimiterGraphTokenFilterDescriptor SplitOnCaseChange(bool? split = true) => Assign(a => a.SplitOnCaseChange = split); - /// + /// public WordDelimiterGraphTokenFilterDescriptor SplitOnNumerics(bool? split = true) => Assign(a => a.SplitOnNumerics = split); - /// + /// public WordDelimiterGraphTokenFilterDescriptor PreserveOriginal(bool? preserve = true) => Assign(a => a.PreserveOriginal = preserve); - /// + /// public WordDelimiterGraphTokenFilterDescriptor StemEnglishPossessive(bool? stem = true) => Assign(a => a.StemEnglishPossessive = stem); - /// - public WordDelimiterGraphTokenFilterDescriptor ProtectedWords(IEnumerable protectedWords) => Assign(a => a.ProtectedWords = protectedWords); + /// + public WordDelimiterGraphTokenFilterDescriptor ProtectedWords(IEnumerable protectedWords) => + Assign(a => a.ProtectedWords = protectedWords); - /// - public WordDelimiterGraphTokenFilterDescriptor ProtectedWords(params string[] protectedWords) => Assign(a => a.ProtectedWords = protectedWords); + /// + public WordDelimiterGraphTokenFilterDescriptor ProtectedWords(params string[] protectedWords) => + Assign(a => a.ProtectedWords = protectedWords); - /// + /// public WordDelimiterGraphTokenFilterDescriptor ProtectedWordsPath(string path) => Assign(a => a.ProtectedWordsPath = path); - /// + /// public WordDelimiterGraphTokenFilterDescriptor TypeTable(IEnumerable typeTable) => Assign(a => a.TypeTable = typeTable); - /// + /// public WordDelimiterGraphTokenFilterDescriptor TypeTable(params string[] typeTable) => Assign(a => a.TypeTable = typeTable); - /// + /// public WordDelimiterGraphTokenFilterDescriptor TypeTablePath(string path) => Assign(a => a.TypeTablePath = path); - } - } diff --git a/src/Nest/Analysis/Tokenizers/CharGroupTokenizer.cs b/src/Nest/Analysis/Tokenizers/CharGroupTokenizer.cs index 3996824fc8a..1f7d2611155 100644 --- a/src/Nest/Analysis/Tokenizers/CharGroupTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/CharGroupTokenizer.cs @@ -5,7 +5,7 @@ namespace Nest { /// /// A tokenizer that breaks text into terms whenever it encounters a character which is in a defined set. It is mostly useful - /// for cases where a simple custom tokenization is desired, and the overhead of use of is not acceptable. + /// for cases where a simple custom tokenization is desired, and the overhead of use of is not acceptable. /// public interface ICharGroupTokenizer : ITokenizer { @@ -18,18 +18,18 @@ public interface ICharGroupTokenizer : ITokenizer IEnumerable TokenizeOnCharacters { get; set; } } - /// + /// public class CharGroupTokenizer : TokenizerBase, ICharGroupTokenizer - { - internal const string TokenizerType = "char_group"; + { + internal const string TokenizerType = "char_group"; - public CharGroupTokenizer() => this.Type = TokenizerType; + public CharGroupTokenizer() => Type = TokenizerType; - /// + /// public IEnumerable TokenizeOnCharacters { get; set; } - } + } - /// + /// public class CharGroupTokenizerDescriptor : TokenizerDescriptorBase, ICharGroupTokenizer { @@ -37,12 +37,12 @@ public class CharGroupTokenizerDescriptor IEnumerable ICharGroupTokenizer.TokenizeOnCharacters { get; set; } - /// + /// public CharGroupTokenizerDescriptor TokenizeOnCharacters(params string[] characters) => - Assign(a => a.TokenizeOnCharacters = characters); + Assign(a => a.TokenizeOnCharacters = characters); - /// + /// public CharGroupTokenizerDescriptor TokenizeOnCharacters(IEnumerable characters) => - Assign(a => a.TokenizeOnCharacters = characters); + Assign(a => a.TokenizeOnCharacters = characters); } } diff --git a/src/Nest/Analysis/Tokenizers/KeywordTokenizer.cs b/src/Nest/Analysis/Tokenizers/KeywordTokenizer.cs index a348195238c..c7605018e52 100644 --- a/src/Nest/Analysis/Tokenizers/KeywordTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/KeywordTokenizer.cs @@ -13,23 +13,25 @@ public interface IKeywordTokenizer : ITokenizer [JsonProperty("buffer_size")] int? BufferSize { get; set; } } - /// + + /// public class KeywordTokenizer : TokenizerBase, IKeywordTokenizer - { - public KeywordTokenizer() { Type = "keyword"; } + { + public KeywordTokenizer() => Type = "keyword"; - /// + /// public int? BufferSize { get; set; } - } - /// - public class KeywordTokenizerDescriptor + } + + /// + public class KeywordTokenizerDescriptor : TokenizerDescriptorBase, IKeywordTokenizer { protected override string Type => "keyword"; int? IKeywordTokenizer.BufferSize { get; set; } - /// + /// public KeywordTokenizerDescriptor BufferSize(int? size) => Assign(a => a.BufferSize = size); } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Tokenizers/LetterTokenizer.cs b/src/Nest/Analysis/Tokenizers/LetterTokenizer.cs index 9fc074fbffa..b838134f230 100644 --- a/src/Nest/Analysis/Tokenizers/LetterTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/LetterTokenizer.cs @@ -1,19 +1,24 @@ namespace Nest { /// - /// A tokenizer of type letter that divides text at non-letters. That’s to say, it defines tokens as maximal strings of adjacent letters. - /// Note, this does a decent job for most European languages, but does a terrible job for some Asian languages, where words are not separated by spaces. + /// A tokenizer of type letter that divides text at non-letters. That’s to say, it defines tokens as maximal strings of adjacent letters. + /// + /// Note, this does a decent job for most European languages, but does a terrible job for some Asian languages, where words are not + /// separated by spaces. + /// /// public interface ILetterTokenizer : ITokenizer { } - /// + + /// public class LetterTokenizer : TokenizerBase, ILetterTokenizer - { - public LetterTokenizer() { Type = "letter"; } - } - /// - public class LetterTokenizerDescriptor + { + public LetterTokenizer() => Type = "letter"; + } + + /// + public class LetterTokenizerDescriptor : TokenizerDescriptorBase, ILetterTokenizer { protected override string Type => "letter"; } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Tokenizers/LowercaseTokenizer.cs b/src/Nest/Analysis/Tokenizers/LowercaseTokenizer.cs index 253b39421f7..fe7c1ceda97 100644 --- a/src/Nest/Analysis/Tokenizers/LowercaseTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/LowercaseTokenizer.cs @@ -1,21 +1,23 @@ namespace Nest { /// - /// A tokenizer of type lowercase that performs the function of Letter Tokenizer and Lower Case Token Filter together. + /// A tokenizer of type lowercase that performs the function of Letter Tokenizer and Lower Case Token Filter together. /// It divides text at non-letters and converts them to lower case. /// While it is functionally equivalent to the combination of Letter Tokenizer and Lower Case Token Filter, /// there is a performance advantage to doing the two tasks at once, hence this (redundant) implementation. /// public interface ILowercaseTokenizer : ITokenizer { } - /// + + /// public class LowercaseTokenizer : TokenizerBase, ILowercaseTokenizer - { - public LowercaseTokenizer() { Type = "lowercase"; } + { + public LowercaseTokenizer() => Type = "lowercase"; } - /// - public class LowercaseTokenizerDescriptor + + /// + public class LowercaseTokenizerDescriptor : TokenizerDescriptorBase, ILowercaseTokenizer { protected override string Type => "lowercase"; } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Tokenizers/NGram/EdgeNGramTokenizer.cs b/src/Nest/Analysis/Tokenizers/NGram/EdgeNGramTokenizer.cs index c046bb53b2a..524eefc87d7 100644 --- a/src/Nest/Analysis/Tokenizers/NGram/EdgeNGramTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/NGram/EdgeNGramTokenizer.cs @@ -8,18 +8,18 @@ namespace Nest /// public interface IEdgeNGramTokenizer : ITokenizer { - /// - /// Minimum size in codepoints of a single n-gram - /// - [JsonProperty("min_gram")] - int? MinGram { get; set; } - /// /// Maximum size in codepoints of a single n-gram /// [JsonProperty("max_gram")] int? MaxGram { get; set; } + /// + /// Minimum size in codepoints of a single n-gram + /// + [JsonProperty("min_gram")] + int? MinGram { get; set; } + /// /// Characters classes to keep in the tokens, Elasticsearch /// will split on characters that don’t belong to any of these classes. @@ -27,43 +27,44 @@ public interface IEdgeNGramTokenizer : ITokenizer [JsonProperty("token_chars")] IEnumerable TokenChars { get; set; } } - /// + + /// public class EdgeNGramTokenizer : TokenizerBase, IEdgeNGramTokenizer { - public EdgeNGramTokenizer() { Type = "edge_ngram"; } + public EdgeNGramTokenizer() => Type = "edge_ngram"; - /// - public int? MinGram { get; set; } - - /// + /// public int? MaxGram { get; set; } - /// + /// + public int? MinGram { get; set; } + + /// public IEnumerable TokenChars { get; set; } } - /// - public class EdgeNGramTokenizerDescriptor + + /// + public class EdgeNGramTokenizerDescriptor : TokenizerDescriptorBase, IEdgeNGramTokenizer { protected override string Type => "edge_ngram"; + int? IEdgeNGramTokenizer.MaxGram { get; set; } int? IEdgeNGramTokenizer.MinGram { get; set; } - int? IEdgeNGramTokenizer.MaxGram { get; set; } IEnumerable IEdgeNGramTokenizer.TokenChars { get; set; } - /// + /// public EdgeNGramTokenizerDescriptor MinGram(int? minGram) => Assign(a => a.MinGram = minGram); - /// + /// public EdgeNGramTokenizerDescriptor MaxGram(int? maxGram) => Assign(a => a.MaxGram = maxGram); - /// - public EdgeNGramTokenizerDescriptor TokenChars(IEnumerable tokenChars) => + /// + public EdgeNGramTokenizerDescriptor TokenChars(IEnumerable tokenChars) => Assign(a => a.TokenChars = tokenChars); - /// - public EdgeNGramTokenizerDescriptor TokenChars(params TokenChar[] tokenChars) => + /// + public EdgeNGramTokenizerDescriptor TokenChars(params TokenChar[] tokenChars) => Assign(a => a.TokenChars = tokenChars); } - -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Tokenizers/NGram/NGramTokenizer.cs b/src/Nest/Analysis/Tokenizers/NGram/NGramTokenizer.cs index 0d34f26d791..5d287edcd50 100644 --- a/src/Nest/Analysis/Tokenizers/NGram/NGramTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/NGram/NGramTokenizer.cs @@ -8,62 +8,62 @@ namespace Nest /// public interface INGramTokenizer : ITokenizer { - /// - /// Minimum size in codepoints of a single n-gram, defaults to 1. - /// - [JsonProperty("min_gram")] - int? MinGram { get; set; } - /// /// Maximum size in codepoints of a single n-gram, defaults to 2. /// [JsonProperty("max_gram")] int? MaxGram { get; set; } + /// + /// Minimum size in codepoints of a single n-gram, defaults to 1. + /// + [JsonProperty("min_gram")] + int? MinGram { get; set; } + /// /// Characters classes to keep in the tokens, Elasticsearch will - /// split on characters that don’t belong to any of these classes. + /// split on characters that don’t belong to any of these classes. /// [JsonProperty("token_chars")] IEnumerable TokenChars { get; set; } } - /// + /// public class NGramTokenizer : TokenizerBase, INGramTokenizer { - public NGramTokenizer() { Type = "ngram"; } + public NGramTokenizer() => Type = "ngram"; - /// - public int? MinGram { get; set; } - - /// + /// public int? MaxGram { get; set; } - /// + /// + public int? MinGram { get; set; } + + /// public IEnumerable TokenChars { get; set; } } - /// - public class NGramTokenizerDescriptor + + /// + public class NGramTokenizerDescriptor : TokenizerDescriptorBase, INGramTokenizer { protected override string Type => "ngram"; + int? INGramTokenizer.MaxGram { get; set; } int? INGramTokenizer.MinGram { get; set; } - int? INGramTokenizer.MaxGram { get; set; } IEnumerable INGramTokenizer.TokenChars { get; set; } - /// + /// public NGramTokenizerDescriptor MinGram(int? minGram) => Assign(a => a.MinGram = minGram); - /// + /// public NGramTokenizerDescriptor MaxGram(int? minGram) => Assign(a => a.MaxGram = minGram); - /// - public NGramTokenizerDescriptor TokenChars(IEnumerable tokenChars) => + /// + public NGramTokenizerDescriptor TokenChars(IEnumerable tokenChars) => Assign(a => a.TokenChars = tokenChars); - /// + /// public NGramTokenizerDescriptor TokenChars(params TokenChar[] tokenChars) => Assign(a => a.TokenChars = tokenChars); - } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Tokenizers/NGram/TokenChar.cs b/src/Nest/Analysis/Tokenizers/NGram/TokenChar.cs index 81b1889b646..504b564f25c 100644 --- a/src/Nest/Analysis/Tokenizers/NGram/TokenChar.cs +++ b/src/Nest/Analysis/Tokenizers/NGram/TokenChar.cs @@ -9,13 +9,17 @@ public enum TokenChar { [EnumMember(Value = "letter")] Letter, + [EnumMember(Value = "digit")] Digit, + [EnumMember(Value = "whitespace")] Whitespace, + [EnumMember(Value = "punctuation")] Punctuation, + [EnumMember(Value = "symbol")] Symbol, } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Tokenizers/NoriTokenizer.cs b/src/Nest/Analysis/Tokenizers/NoriTokenizer.cs index 435d24f7117..761f4e3d8c4 100644 --- a/src/Nest/Analysis/Tokenizers/NoriTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/NoriTokenizer.cs @@ -9,13 +9,15 @@ namespace Nest public enum NoriDecompoundMode { /// Decomposes compounds and discards the original form (default). - [EnumMember(Value="discard")] + [EnumMember(Value = "discard")] Discard, + /// No decomposition for compounds - [EnumMember(Value="none")] + [EnumMember(Value = "none")] None, + /// Decomposes compounds and keeps the original form - [EnumMember(Value="mixed")] + [EnumMember(Value = "mixed")] Mixed } @@ -36,28 +38,31 @@ public interface INoriTokenizer : ITokenizer string UserDictionary { get; set; } } - /// + /// public class NoriTokenizer : TokenizerBase, INoriTokenizer - { - public NoriTokenizer() => this.Type = "nori_tokenizer"; - /// - public NoriDecompoundMode? DecompoundMode { get; set; } - /// - public string UserDictionary { get; set; } - } - /// + { + public NoriTokenizer() => Type = "nori_tokenizer"; + + /// + public NoriDecompoundMode? DecompoundMode { get; set; } + + /// + public string UserDictionary { get; set; } + } + + /// public class NoriTokenizerDescriptor : TokenizerDescriptorBase, INoriTokenizer { protected override string Type => "nori_tokenizer"; - NoriDecompoundMode? INoriTokenizer.DecompoundMode { get; set; } - string INoriTokenizer.UserDictionary { get; set; } + NoriDecompoundMode? INoriTokenizer.DecompoundMode { get; set; } + string INoriTokenizer.UserDictionary { get; set; } - /// + /// public NoriTokenizerDescriptor DecompoundMode(NoriDecompoundMode? mode) => Assign(a => a.DecompoundMode = mode); - /// + /// public NoriTokenizerDescriptor UserDictionary(string path) => Assign(a => a.UserDictionary = path); } } diff --git a/src/Nest/Analysis/Tokenizers/PathHierarchyTokenizer.cs b/src/Nest/Analysis/Tokenizers/PathHierarchyTokenizer.cs index 52b84e46fe5..319c3c73901 100644 --- a/src/Nest/Analysis/Tokenizers/PathHierarchyTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/PathHierarchyTokenizer.cs @@ -3,16 +3,22 @@ namespace Nest { /// - /// The path_hierarchy tokenizer takes something like this: - ////something/something/else - ///And produces tokens: - /// - ////something - ////something/something - ////something/something/else + /// The path_hierarchy tokenizer takes something like this: + /// /something/something/else + /// And produces tokens: + /// + /// /something + /// /something/something + /// /something/something/else /// public interface IPathHierarchyTokenizer : ITokenizer { + /// + /// The buffer size to use, defaults to 1024. + /// + [JsonProperty("buffer_size")] + int? BufferSize { get; set; } + /// /// The character delimiter to use, defaults to /. /// @@ -25,12 +31,6 @@ public interface IPathHierarchyTokenizer : ITokenizer [JsonProperty("replacement")] char? Replacement { get; set; } - /// - /// The buffer size to use, defaults to 1024. - /// - [JsonProperty("buffer_size")] - int? BufferSize { get; set; } - /// /// Generates tokens in reverse order, defaults to false. /// @@ -44,53 +44,53 @@ public interface IPathHierarchyTokenizer : ITokenizer int? Skip { get; set; } } - /// + /// public class PathHierarchyTokenizer : TokenizerBase, IPathHierarchyTokenizer { - public PathHierarchyTokenizer() { Type = "path_hierarchy"; } + public PathHierarchyTokenizer() => Type = "path_hierarchy"; + + /// + public int? BufferSize { get; set; } - /// + /// public char? Delimiter { get; set; } - /// + /// public char? Replacement { get; set; } - /// - public int? BufferSize { get; set; } - - /// + /// public bool? Reverse { get; set; } - /// + /// public int? Skip { get; set; } } - /// + + /// public class PathHierarchyTokenizerDescriptor : TokenizerDescriptorBase, IPathHierarchyTokenizer { protected override string Type => "path_hierarchy"; int? IPathHierarchyTokenizer.BufferSize { get; set; } - int? IPathHierarchyTokenizer.Skip { get; set; } - bool? IPathHierarchyTokenizer.Reverse { get; set; } char? IPathHierarchyTokenizer.Delimiter { get; set; } char? IPathHierarchyTokenizer.Replacement { get; set; } + bool? IPathHierarchyTokenizer.Reverse { get; set; } + int? IPathHierarchyTokenizer.Skip { get; set; } - /// + /// public PathHierarchyTokenizerDescriptor BufferSize(int? bufferSize) => Assign(a => a.BufferSize = bufferSize); - /// + /// public PathHierarchyTokenizerDescriptor Skip(int? skip) => Assign(a => a.Skip = skip); - /// + /// public PathHierarchyTokenizerDescriptor Reverse(bool? reverse = true) => Assign(a => a.Reverse = reverse); - /// + /// public PathHierarchyTokenizerDescriptor Delimiter(char? delimiter) => Assign(a => a.Delimiter = delimiter); - /// + /// public PathHierarchyTokenizerDescriptor Replacement(char? replacement) => Assign(a => a.Replacement = replacement); - } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Tokenizers/PatternTokenizer.cs b/src/Nest/Analysis/Tokenizers/PatternTokenizer.cs index 23df200c6c5..5ab367aad6b 100644 --- a/src/Nest/Analysis/Tokenizers/PatternTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/PatternTokenizer.cs @@ -7,12 +7,6 @@ namespace Nest /// public interface IPatternTokenizer : ITokenizer { - /// - /// The regular expression pattern, defaults to \W+. - /// - [JsonProperty("pattern")] - string Pattern { get; set; } - /// /// The regular expression flags. /// @@ -25,40 +19,45 @@ public interface IPatternTokenizer : ITokenizer [JsonProperty("group")] int? Group { get; set; } + /// + /// The regular expression pattern, defaults to \W+. + /// + [JsonProperty("pattern")] + string Pattern { get; set; } } - /// + /// public class PatternTokenizer : TokenizerBase, IPatternTokenizer - { - public PatternTokenizer() { Type = "pattern"; } - - /// - public string Pattern { get; set; } + { + public PatternTokenizer() => Type = "pattern"; - /// + /// public string Flags { get; set; } - /// + /// public int? Group { get; set; } - } - /// + + /// + public string Pattern { get; set; } + } + + /// public class PatternTokenizerDescriptor : TokenizerDescriptorBase, IPatternTokenizer { protected override string Type => "pattern"; + string IPatternTokenizer.Flags { get; set; } int? IPatternTokenizer.Group { get; set; } string IPatternTokenizer.Pattern { get; set; } - string IPatternTokenizer.Flags { get; set; } - /// + /// public PatternTokenizerDescriptor Group(int? group) => Assign(a => a.Group = group); - /// + /// public PatternTokenizerDescriptor Pattern(string pattern) => Assign(a => a.Pattern = pattern); - /// + /// public PatternTokenizerDescriptor Flags(string flags) => Assign(a => a.Flags = flags); - } } diff --git a/src/Nest/Analysis/Tokenizers/StandardTokenizer.cs b/src/Nest/Analysis/Tokenizers/StandardTokenizer.cs index 8771022ea72..ace2e48064e 100644 --- a/src/Nest/Analysis/Tokenizers/StandardTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/StandardTokenizer.cs @@ -3,7 +3,7 @@ namespace Nest { /// - /// A tokenizer of type standard providing grammar based tokenizer that is a good tokenizer for most European language documents. + /// A tokenizer of type standard providing grammar based tokenizer that is a good tokenizer for most European language documents. /// The tokenizer implements the Unicode Text Segmentation algorithm, as specified in Unicode Standard Annex #29. /// public interface IStandardTokenizer : ITokenizer @@ -12,24 +12,26 @@ public interface IStandardTokenizer : ITokenizer /// The maximum token length. If a token is seen that exceeds this length then it is discarded. Defaults to 255. /// [JsonProperty("max_token_length")] - int? MaxTokenLength { get; set; } + int? MaxTokenLength { get; set; } } - /// + + /// public class StandardTokenizer : TokenizerBase, IStandardTokenizer - { - public StandardTokenizer() { Type = "standard"; } + { + public StandardTokenizer() => Type = "standard"; + + /// + public int? MaxTokenLength { get; set; } + } - /// - public int? MaxTokenLength { get; set; } - } - public class StandardTokenizerDescriptor + public class StandardTokenizerDescriptor : TokenizerDescriptorBase, IStandardTokenizer { protected override string Type => "standard"; int? IStandardTokenizer.MaxTokenLength { get; set; } - /// + /// public StandardTokenizerDescriptor MaxTokenLength(int? maxLength) => Assign(a => a.MaxTokenLength = maxLength); } -} \ No newline at end of file +} diff --git a/src/Nest/Analysis/Tokenizers/TokenizerBase.cs b/src/Nest/Analysis/Tokenizers/TokenizerBase.cs index e484092dcce..8bd1bf35a7e 100644 --- a/src/Nest/Analysis/Tokenizers/TokenizerBase.cs +++ b/src/Nest/Analysis/Tokenizers/TokenizerBase.cs @@ -5,18 +5,17 @@ namespace Nest [ContractJsonConverter(typeof(TokenizerJsonConverter))] public interface ITokenizer { - [JsonProperty("version")] - string Version { get; set; } - [JsonProperty("type")] string Type { get; } + + [JsonProperty("version")] + string Version { get; set; } } public abstract class TokenizerBase : ITokenizer { - public string Version { get; set; } - public string Type { get; protected set; } + public string Version { get; set; } } public abstract class TokenizerDescriptorBase @@ -24,11 +23,10 @@ public abstract class TokenizerDescriptorBase where TTokenizer : TokenizerDescriptorBase, TTokenizerInterface where TTokenizerInterface : class, ITokenizer { - string ITokenizer.Version { get; set; } - string ITokenizer.Type => this.Type; protected abstract string Type { get; } + string ITokenizer.Type => Type; + string ITokenizer.Version { get; set; } public TTokenizer Version(string version) => Assign(a => a.Version = version); } - } diff --git a/src/Nest/Analysis/Tokenizers/TokenizerJsonConverter.cs b/src/Nest/Analysis/Tokenizers/TokenizerJsonConverter.cs index 2f0b34cd91a..e6be0f235a6 100644 --- a/src/Nest/Analysis/Tokenizers/TokenizerJsonConverter.cs +++ b/src/Nest/Analysis/Tokenizers/TokenizerJsonConverter.cs @@ -6,19 +6,20 @@ namespace Nest { internal class TokenizerJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) => true; - public override bool CanWrite => false; public override bool CanRead => true; + public override bool CanWrite => false; + + public override bool CanConvert(Type objectType) => true; public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - JObject o = JObject.Load(reader); + var o = JObject.Load(reader); - JProperty typeProperty = o.Property("type"); + var typeProperty = o.Property("type"); if (typeProperty == null) return null; var typePropertyValue = typeProperty.Value.ToString(); - switch(typePropertyValue.ToLowerInvariant()) + switch (typePropertyValue.ToLowerInvariant()) { case "edgengram": case "edge_ngram": return o.ToObject(ElasticContractResolver.Empty); @@ -34,9 +35,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return null; } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotSupportedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); } } diff --git a/src/Nest/Analysis/Tokenizers/Tokenizers.cs b/src/Nest/Analysis/Tokenizers/Tokenizers.cs index 330162c49b4..ed9cd1cc1d7 100644 --- a/src/Nest/Analysis/Tokenizers/Tokenizers.cs +++ b/src/Nest/Analysis/Tokenizers/Tokenizers.cs @@ -10,11 +10,12 @@ public interface ITokenizers : IIsADictionary { } public class Tokenizers : IsADictionaryBase, ITokenizers { - public Tokenizers() {} + public Tokenizers() { } + public Tokenizers(IDictionary container) : base(container) { } + public Tokenizers(Dictionary container) - : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) - {} + : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) { } public void Add(string name, ITokenizer analyzer) => BackingDictionary.Add(name, analyzer); } @@ -45,7 +46,10 @@ public TokenizersDescriptor Keyword(string name, Func /// A tokenizer of type letter that divides text at non-letters. That’s to say, it defines tokens as maximal strings of adjacent letters. - /// Note, this does a decent job for most European languages, but does a terrible job for some Asian languages, where words are not separated by spaces. + /// + /// Note, this does a decent job for most European languages, but does a terrible job for some Asian languages, where words are not + /// separated by spaces. + /// /// public TokenizersDescriptor Letter(string name, Func selector) => Assign(name, selector?.Invoke(new LetterTokenizerDescriptor())); @@ -60,13 +64,13 @@ public TokenizersDescriptor Lowercase(string name, Func - /// The path_hierarchy tokenizer takes something like this: - ////something/something/else - ///And produces tokens: - /// - ////something - ////something/something - ////something/something/else + /// The path_hierarchy tokenizer takes something like this: + /// /something/something/else + /// And produces tokens: + /// + /// /something + /// /something/something + /// /something/something/else /// public TokenizersDescriptor PathHierarchy(string name, Func selector) => Assign(name, selector?.Invoke(new PathHierarchyTokenizerDescriptor())); @@ -113,11 +117,12 @@ public TokenizersDescriptor Kuromoji(string name, Func selector) => Assign(name, selector?.Invoke(new IcuTokenizerDescriptor())); - /// + /// public TokenizersDescriptor Nori(string name, Func selector) => Assign(name, selector?.Invoke(new NoriTokenizerDescriptor())); - /// > + /// + /// > public TokenizersDescriptor CharGroup(string name, Func selector) => Assign(name, selector?.Invoke(new CharGroupTokenizerDescriptor())); } diff --git a/src/Nest/Analysis/Tokenizers/UaxEmailUrlTokenizer.cs b/src/Nest/Analysis/Tokenizers/UaxEmailUrlTokenizer.cs index e1e07530ce7..005d6274566 100644 --- a/src/Nest/Analysis/Tokenizers/UaxEmailUrlTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/UaxEmailUrlTokenizer.cs @@ -11,25 +11,27 @@ public interface IUaxEmailUrlTokenizer : ITokenizer /// The maximum token length. If a token is seen that exceeds this length then it is discarded. Defaults to 255. /// [JsonProperty("max_token_length")] - int? MaxTokenLength { get; set; } + int? MaxTokenLength { get; set; } } - /// + + /// public class UaxEmailUrlTokenizer : TokenizerBase, IUaxEmailUrlTokenizer - { - public UaxEmailUrlTokenizer() { Type = "uax_url_email"; } + { + public UaxEmailUrlTokenizer() => Type = "uax_url_email"; + + /// + public int? MaxTokenLength { get; set; } + } - /// - public int? MaxTokenLength { get; set; } - } - /// - public class UaxEmailUrlTokenizerDescriptor + /// + public class UaxEmailUrlTokenizerDescriptor : TokenizerDescriptorBase, IUaxEmailUrlTokenizer { protected override string Type => "uax_url_email"; int? IUaxEmailUrlTokenizer.MaxTokenLength { get; set; } - /// + /// public UaxEmailUrlTokenizerDescriptor MaxTokenLength(int? maxLength) => Assign(a => a.MaxTokenLength = maxLength); } } diff --git a/src/Nest/Analysis/Tokenizers/WhitespaceTokenizer.cs b/src/Nest/Analysis/Tokenizers/WhitespaceTokenizer.cs index 00787340a49..c86a67c7a66 100644 --- a/src/Nest/Analysis/Tokenizers/WhitespaceTokenizer.cs +++ b/src/Nest/Analysis/Tokenizers/WhitespaceTokenizer.cs @@ -9,7 +9,7 @@ public interface IWhitespaceTokenizer : ITokenizer { /// /// The maximum token length. If a token is seen that exceeds this length then it is split at - /// intervals. Defaults to 255. + /// intervals. Defaults to 255. /// /// /// Valid for Elasticsearch 6.1.0+ @@ -18,16 +18,16 @@ public interface IWhitespaceTokenizer : ITokenizer int? MaxTokenLength { get; set; } } - /// + /// public class WhitespaceTokenizer : TokenizerBase, IWhitespaceTokenizer - { - public WhitespaceTokenizer() { Type = "whitespace"; } + { + public WhitespaceTokenizer() => Type = "whitespace"; - /// - public int? MaxTokenLength { get; set; } - } + /// + public int? MaxTokenLength { get; set; } + } - /// + /// public class WhitespaceTokenizerDescriptor : TokenizerDescriptorBase, IWhitespaceTokenizer { @@ -35,7 +35,7 @@ public class WhitespaceTokenizerDescriptor int? IWhitespaceTokenizer.MaxTokenLength { get; set; } - /// + /// public WhitespaceTokenizerDescriptor MaxTokenLength(int? maxTokenLength) => Assign(a => a.MaxTokenLength = maxTokenLength); } diff --git a/src/Nest/Cat/CatAliases/CatAliasesRecord.cs b/src/Nest/Cat/CatAliases/CatAliasesRecord.cs index 9b5e3b54055..8f959df3835 100644 --- a/src/Nest/Cat/CatAliases/CatAliasesRecord.cs +++ b/src/Nest/Cat/CatAliases/CatAliasesRecord.cs @@ -8,16 +8,16 @@ public class CatAliasesRecord : ICatRecord [JsonProperty("alias")] public string Alias { get; set; } - [JsonProperty("index")] - public string Index { get; set; } - [JsonProperty("filter")] public string Filter { get; set; } + [JsonProperty("index")] + public string Index { get; set; } + [JsonProperty("indexRouting")] public string IndexRouting { get; set; } [JsonProperty("searchRouting")] public string SearchRouting { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatAliases/ElasticClient-CatAliases.cs b/src/Nest/Cat/CatAliases/ElasticClient-CatAliases.cs index fe56122acec..0ae2210d327 100644 --- a/src/Nest/Cat/CatAliases/ElasticClient-CatAliases.cs +++ b/src/Nest/Cat/CatAliases/ElasticClient-CatAliases.cs @@ -1,43 +1,51 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatAliases(Func selector = null); - /// + /// ICatResponse CatAliases(ICatAliasesRequest request); - /// - Task> CatAliasesAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); - - /// - Task> CatAliasesAsync(ICatAliasesRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatAliasesAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); + /// + Task> CatAliasesAsync(ICatAliasesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatAliases(Func selector = null) => - this.CatAliases(selector.InvokeOrDefault(new CatAliasesDescriptor())); + CatAliases(selector.InvokeOrDefault(new CatAliasesDescriptor())); - /// + /// public ICatResponse CatAliases(ICatAliasesRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatAliasesDispatch>); - - /// - public Task> CatAliasesAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.CatAliasesAsync(selector.InvokeOrDefault(new CatAliasesDescriptor()), cancellationToken); - - /// - public Task> CatAliasesAsync(ICatAliasesRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatAliasesDispatchAsync>); - + DoCat(request, + LowLevelDispatch.CatAliasesDispatch>); + + /// + public Task> CatAliasesAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + CatAliasesAsync(selector.InvokeOrDefault(new CatAliasesDescriptor()), cancellationToken); + + /// + public Task> CatAliasesAsync(ICatAliasesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatAliasesDispatchAsync>); } } diff --git a/src/Nest/Cat/CatAllocation/CatAllocationRecord.cs b/src/Nest/Cat/CatAllocation/CatAllocationRecord.cs index 1a4c9375b9a..fb92cb007b0 100644 --- a/src/Nest/Cat/CatAllocation/CatAllocationRecord.cs +++ b/src/Nest/Cat/CatAllocation/CatAllocationRecord.cs @@ -5,22 +5,22 @@ namespace Nest [JsonObject] public class CatAllocationRecord : ICatRecord { - [JsonProperty("shards")] - public string Shards { get; set; } - - [JsonProperty("diskUsed")] - public string DiskUsed { get; set; } - [JsonProperty("diskAvail")] public string DiskAvailable { get; set; } [JsonProperty("diskRatio")] public string DiskRatio { get; set; } + [JsonProperty("diskUsed")] + public string DiskUsed { get; set; } + [JsonProperty("ip")] public string Ip { get; set; } [JsonProperty("node")] public string Node { get; set; } + + [JsonProperty("shards")] + public string Shards { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatAllocation/ElasticClient-CatAllocation.cs b/src/Nest/Cat/CatAllocation/ElasticClient-CatAllocation.cs index f065c67f3db..08c2b529a48 100644 --- a/src/Nest/Cat/CatAllocation/ElasticClient-CatAllocation.cs +++ b/src/Nest/Cat/CatAllocation/ElasticClient-CatAllocation.cs @@ -1,50 +1,55 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatAllocation(Func selector = null); - /// + /// ICatResponse CatAllocation(ICatAllocationRequest request); - /// + /// Task> CatAllocationAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatAllocationAsync(ICatAllocationRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatAllocationAsync(ICatAllocationRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } + public partial class ElasticClient { - /// + /// public ICatResponse CatAllocation(Func selector = null) => - this.CatAllocation(selector.InvokeOrDefault(new CatAllocationDescriptor())); + CatAllocation(selector.InvokeOrDefault(new CatAllocationDescriptor())); - /// + /// public ICatResponse CatAllocation(ICatAllocationRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatAllocationDispatch>); + DoCat(request, + LowLevelDispatch.CatAllocationDispatch>); - /// + /// public Task> CatAllocationAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatAllocationAsync(selector.InvokeOrDefault(new CatAllocationDescriptor()), cancellationToken); + ) => CatAllocationAsync(selector.InvokeOrDefault(new CatAllocationDescriptor()), cancellationToken); - /// - public Task> CatAllocationAsync(ICatAllocationRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync( + /// + public Task> CatAllocationAsync(ICatAllocationRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync( request, cancellationToken, - this.LowLevelDispatch.CatAllocationDispatchAsync> + LowLevelDispatch.CatAllocationDispatchAsync> ); } } diff --git a/src/Nest/Cat/CatCount/CatCountRecord.cs b/src/Nest/Cat/CatCount/CatCountRecord.cs index 99efe3535f2..8b57ca5b74a 100644 --- a/src/Nest/Cat/CatCount/CatCountRecord.cs +++ b/src/Nest/Cat/CatCount/CatCountRecord.cs @@ -5,13 +5,13 @@ namespace Nest [JsonObject] public class CatCountRecord : ICatRecord { + [JsonProperty("count")] + public string Count { get; set; } + [JsonProperty("epoch")] public string Epoch { get; set; } [JsonProperty("timestamp")] public string Timestamp { get; set; } - - [JsonProperty("count")] - public string Count { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatCount/ElasticClient-CatCount.cs b/src/Nest/Cat/CatCount/ElasticClient-CatCount.cs index 346859d50ee..f616d5f6455 100644 --- a/src/Nest/Cat/CatCount/ElasticClient-CatCount.cs +++ b/src/Nest/Cat/CatCount/ElasticClient-CatCount.cs @@ -1,42 +1,49 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatCount(Func selector = null); - /// + /// ICatResponse CatCount(ICatCountRequest request); - /// - Task> CatCountAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatCountAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task> CatCountAsync(ICatCountRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public ICatResponse CatCount(Func selector = null) => - this.CatCount(selector.InvokeOrDefault(new CatCountDescriptor())); - - /// - public ICatResponse CatCount(ICatCountRequest request)=> - this.DoCat(request, this.LowLevelDispatch.CatCountDispatch>); - - /// - public Task> CatCountAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.CatCountAsync(selector.InvokeOrDefault(new CatCountDescriptor()), cancellationToken); - - /// - public Task> CatCountAsync(ICatCountRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatCountDispatchAsync>); - + CatCount(selector.InvokeOrDefault(new CatCountDescriptor())); + + /// + public ICatResponse CatCount(ICatCountRequest request) => + DoCat(request, + LowLevelDispatch.CatCountDispatch>); + + /// + public Task> CatCountAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + CatCountAsync(selector.InvokeOrDefault(new CatCountDescriptor()), cancellationToken); + + /// + public Task> CatCountAsync(ICatCountRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatCountDispatchAsync>); } } diff --git a/src/Nest/Cat/CatFielddata/CatFielddataRecord.cs b/src/Nest/Cat/CatFielddata/CatFielddataRecord.cs index e2b15f06818..380cf768c1d 100644 --- a/src/Nest/Cat/CatFielddata/CatFielddataRecord.cs +++ b/src/Nest/Cat/CatFielddata/CatFielddataRecord.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -7,11 +6,11 @@ namespace Nest [JsonConverter(typeof(CatFielddataRecordJsonConverter))] public class CatFielddataRecord : ICatRecord { - public string Id { get; set; } + public string Field { get; set; } public string Host { get; set; } + public string Id { get; set; } public string Ip { get; set; } public string Node { get; set; } - public string Field { get; set; } public string Size { get; set; } } } diff --git a/src/Nest/Cat/CatFielddata/CatFielddataRecordJsonConverter.cs b/src/Nest/Cat/CatFielddata/CatFielddataRecordJsonConverter.cs index c08853de631..53dad182ce2 100644 --- a/src/Nest/Cat/CatFielddata/CatFielddataRecordJsonConverter.cs +++ b/src/Nest/Cat/CatFielddata/CatFielddataRecordJsonConverter.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Newtonsoft.Json; namespace Nest @@ -8,13 +7,11 @@ internal class CatFielddataRecordJsonConverter : JsonConverter { public override bool CanWrite => false; - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotSupportedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); public override object ReadJson(JsonReader reader, Type objectType, object existingValue, - JsonSerializer serializer) + JsonSerializer serializer + ) { var record = new CatFielddataRecord(); while (reader.Read()) diff --git a/src/Nest/Cat/CatFielddata/ElasticClient-CatFielddata.cs b/src/Nest/Cat/CatFielddata/ElasticClient-CatFielddata.cs index 0d75d860721..ef7f6d3c2b3 100644 --- a/src/Nest/Cat/CatFielddata/ElasticClient-CatFielddata.cs +++ b/src/Nest/Cat/CatFielddata/ElasticClient-CatFielddata.cs @@ -1,48 +1,52 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatFielddata(Func selector = null); - /// + /// ICatResponse CatFielddata(ICatFielddataRequest request); - /// + /// Task> CatFielddataAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatFielddataAsync(ICatFielddataRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatFielddataAsync(ICatFielddataRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatFielddata(Func selector = null) => - this.CatFielddata(selector.InvokeOrDefault(new CatFielddataDescriptor())); + CatFielddata(selector.InvokeOrDefault(new CatFielddataDescriptor())); - /// + /// public ICatResponse CatFielddata(ICatFielddataRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatFielddataDispatch>); + DoCat(request, + LowLevelDispatch.CatFielddataDispatch>); - /// + /// public Task> CatFielddataAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatFielddataAsync(selector.InvokeOrDefault(new CatFielddataDescriptor()), cancellationToken); - - /// - public Task> CatFielddataAsync(ICatFielddataRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatFielddataDispatchAsync>); + ) => CatFielddataAsync(selector.InvokeOrDefault(new CatFielddataDescriptor()), cancellationToken); + /// + public Task> CatFielddataAsync(ICatFielddataRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatFielddataDispatchAsync>); } } diff --git a/src/Nest/Cat/CatHealth/CatHealthRecord.cs b/src/Nest/Cat/CatHealth/CatHealthRecord.cs index c8c4104b88e..68ef41efbf1 100644 --- a/src/Nest/Cat/CatHealth/CatHealthRecord.cs +++ b/src/Nest/Cat/CatHealth/CatHealthRecord.cs @@ -11,21 +11,24 @@ public class CatHealthRecord : ICatRecord [JsonProperty("epoch")] public string Epoch { get; set; } + [JsonProperty("init")] + public string Initializing { get; set; } + [JsonProperty("node.data")] public string NodeData { get; set; } [JsonProperty("node.total")] public string NodeTotal { get; set; } + [JsonProperty("pending_tasks")] + public string PendingTasks { get; set; } + [JsonProperty("pri")] public string Primary { get; set; } [JsonProperty("relo")] public string Relocating { get; set; } - [JsonProperty("init")] - public string Initializing { get; set; } - [JsonProperty("shards")] public string Shards { get; set; } @@ -37,8 +40,5 @@ public class CatHealthRecord : ICatRecord [JsonProperty("unassign")] public string Unassigned { get; set; } - - [JsonProperty("pending_tasks")] - public string PendingTasks { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatHealth/ElasticClient-CatHealth.cs b/src/Nest/Cat/CatHealth/ElasticClient-CatHealth.cs index d115bfbc474..0bacbdea5f4 100644 --- a/src/Nest/Cat/CatHealth/ElasticClient-CatHealth.cs +++ b/src/Nest/Cat/CatHealth/ElasticClient-CatHealth.cs @@ -1,47 +1,51 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatHealth(Func selector = null); - /// + /// ICatResponse CatHealth(ICatHealthRequest request); - /// + /// Task> CatHealthAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatHealthAsync(ICatHealthRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatHealthAsync(ICatHealthRequest request, CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatHealth(Func selector = null) => - this.CatHealth(selector.InvokeOrDefault(new CatHealthDescriptor())); + CatHealth(selector.InvokeOrDefault(new CatHealthDescriptor())); - /// + /// public ICatResponse CatHealth(ICatHealthRequest request) => - DoCat(request, LowLevelDispatch.CatHealthDispatch>); + DoCat(request, + LowLevelDispatch.CatHealthDispatch>); - /// + /// public Task> CatHealthAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatHealthAsync(selector.InvokeOrDefault(new CatHealthDescriptor()), cancellationToken); + ) => CatHealthAsync(selector.InvokeOrDefault(new CatHealthDescriptor()), cancellationToken); - /// - public Task> CatHealthAsync(ICatHealthRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - DoCatAsync(request, cancellationToken, LowLevelDispatch.CatHealthDispatchAsync>); + /// + public Task> CatHealthAsync(ICatHealthRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatHealthDispatchAsync>); } } diff --git a/src/Nest/Cat/CatHelp/CatHelpRecord.cs b/src/Nest/Cat/CatHelp/CatHelpRecord.cs index 107e37db804..24d67ab0bda 100644 --- a/src/Nest/Cat/CatHelp/CatHelpRecord.cs +++ b/src/Nest/Cat/CatHelp/CatHelpRecord.cs @@ -7,6 +7,5 @@ public class CatHelpRecord : ICatRecord { [JsonProperty("endpoint")] public string Endpoint { get; set; } - } } diff --git a/src/Nest/Cat/CatHelp/ElasticClient-CatHelp.cs b/src/Nest/Cat/CatHelp/ElasticClient-CatHelp.cs index e3409fa4e5a..464bc78e7af 100644 --- a/src/Nest/Cat/CatHelp/ElasticClient-CatHelp.cs +++ b/src/Nest/Cat/CatHelp/ElasticClient-CatHelp.cs @@ -1,32 +1,59 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatHelp(Func selector = null); - /// + /// ICatResponse CatHelp(ICatHelpRequest request); - /// - Task> CatHelpAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatHelpAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task> CatHelpAsync(ICatHelpRequest request, CancellationToken cancellationToken = default(CancellationToken)); - } public partial class ElasticClient { + /// + public ICatResponse CatHelp(Func selector = null) => + CatHelp(selector.InvokeOrDefault(new CatHelpDescriptor())); + + /// + public ICatResponse CatHelp(ICatHelpRequest request) => + Dispatcher.Dispatch>( + request, + new Func>(DeserializeCatHelpResponse), + (p, d) => LowLevelDispatch.CatHelpDispatch>(p) + ); + + /// + public Task> CatHelpAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + CatHelpAsync(selector.InvokeOrDefault(new CatHelpDescriptor()), cancellationToken); + + /// + public Task> CatHelpAsync(ICatHelpRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync, ICatResponse>( + request, + cancellationToken, + new Func>(DeserializeCatHelpResponse), + (p, d, c) => LowLevelDispatch.CatHelpDispatchAsync>(p, c) + ); private CatResponse DeserializeCatHelpResponse(IApiCallDetails response, Stream stream) { @@ -37,37 +64,12 @@ private CatResponse DeserializeCatHelpResponse(IApiCallDetails re var body = ms.ToArray().Utf8String(); return new CatResponse { - Records = body.Split('\n').Skip(1) + Records = body.Split('\n') + .Skip(1) .Select(f => new CatHelpRecord { Endpoint = f.Trim() }) .ToList() }; } } - - /// - public ICatResponse CatHelp(Func selector = null) => - this.CatHelp(selector.InvokeOrDefault(new CatHelpDescriptor())); - - /// - public ICatResponse CatHelp(ICatHelpRequest request) => - this.Dispatcher.Dispatch>( - request, - new Func>(this.DeserializeCatHelpResponse), - (p, d) => this.LowLevelDispatch.CatHelpDispatch>(p) - ); - - /// - public Task> CatHelpAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.CatHelpAsync(selector.InvokeOrDefault(new CatHelpDescriptor()), cancellationToken); - - /// - public Task> CatHelpAsync(ICatHelpRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync, ICatResponse>( - request, - cancellationToken, - new Func>(this.DeserializeCatHelpResponse), - (p, d, c) => this.LowLevelDispatch.CatHelpDispatchAsync>(p, c) - ); - } } diff --git a/src/Nest/Cat/CatIndices/CatIndicesRecord.cs b/src/Nest/Cat/CatIndices/CatIndicesRecord.cs index e96e68af3e9..1c934512397 100644 --- a/src/Nest/Cat/CatIndices/CatIndicesRecord.cs +++ b/src/Nest/Cat/CatIndices/CatIndicesRecord.cs @@ -26,13 +26,13 @@ public class CatIndicesRecord : ICatRecord [JsonProperty("rep")] public string Replica { get; set; } - [JsonProperty("store.size")] - public string StoreSize { get; set; } - [JsonProperty("status")] public string Status { get; set; } + [JsonProperty("store.size")] + public string StoreSize { get; set; } + [JsonProperty("tm")] public string TotalMemory { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatIndices/ElasticClient-CatIndices.cs b/src/Nest/Cat/CatIndices/ElasticClient-CatIndices.cs index 59f970090c6..322f9df40e9 100644 --- a/src/Nest/Cat/CatIndices/ElasticClient-CatIndices.cs +++ b/src/Nest/Cat/CatIndices/ElasticClient-CatIndices.cs @@ -1,47 +1,52 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatIndices(Func selector = null); - /// + /// ICatResponse CatIndices(ICatIndicesRequest request); - /// + /// Task> CatIndicesAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatIndicesAsync(ICatIndicesRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatIndicesAsync(ICatIndicesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatIndices(Func selector = null) => - this.CatIndices(selector.InvokeOrDefault(new CatIndicesDescriptor())); + CatIndices(selector.InvokeOrDefault(new CatIndicesDescriptor())); - /// + /// public ICatResponse CatIndices(ICatIndicesRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatIndicesDispatch>); + DoCat(request, + LowLevelDispatch.CatIndicesDispatch>); - /// + /// public Task> CatIndicesAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatIndicesAsync(selector.InvokeOrDefault(new CatIndicesDescriptor()), cancellationToken); + ) => CatIndicesAsync(selector.InvokeOrDefault(new CatIndicesDescriptor()), cancellationToken); - /// - public Task> CatIndicesAsync(ICatIndicesRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatIndicesDispatchAsync>); + /// + public Task> CatIndicesAsync(ICatIndicesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatIndicesDispatchAsync>); } } diff --git a/src/Nest/Cat/CatMaster/CatMasterRecord.cs b/src/Nest/Cat/CatMaster/CatMasterRecord.cs index b4963861d09..ff631f86c01 100644 --- a/src/Nest/Cat/CatMaster/CatMasterRecord.cs +++ b/src/Nest/Cat/CatMaster/CatMasterRecord.cs @@ -14,4 +14,4 @@ public class CatMasterRecord : ICatRecord [JsonProperty("node")] public string Node { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatMaster/ElasticClient-CatMaster.cs b/src/Nest/Cat/CatMaster/ElasticClient-CatMaster.cs index 78e8acad4f3..ad326c6e9a7 100644 --- a/src/Nest/Cat/CatMaster/ElasticClient-CatMaster.cs +++ b/src/Nest/Cat/CatMaster/ElasticClient-CatMaster.cs @@ -1,45 +1,51 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatMaster(Func selector = null); - /// + /// ICatResponse CatMaster(ICatMasterRequest request); - /// + /// Task> CatMasterAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatMasterAsync(ICatMasterRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatMasterAsync(ICatMasterRequest request, CancellationToken cancellationToken = default(CancellationToken) + ); } + public partial class ElasticClient { - /// + /// public ICatResponse CatMaster(Func selector = null) => - this.CatMaster(selector.InvokeOrDefault(new CatMasterDescriptor())); + CatMaster(selector.InvokeOrDefault(new CatMasterDescriptor())); - /// + /// public ICatResponse CatMaster(ICatMasterRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatMasterDispatch>); + DoCat(request, + LowLevelDispatch.CatMasterDispatch>); - /// - public Task> CatMasterAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.CatMasterAsync(selector.InvokeOrDefault(new CatMasterDescriptor()), cancellationToken); + /// + public Task> CatMasterAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + CatMasterAsync(selector.InvokeOrDefault(new CatMasterDescriptor()), cancellationToken); - /// - public Task> CatMasterAsync(ICatMasterRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatMasterDispatchAsync>); + /// + public Task> CatMasterAsync(ICatMasterRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatMasterDispatchAsync>); } } - diff --git a/src/Nest/Cat/CatNodeAttributes/CatNodeAttributesRecord.cs b/src/Nest/Cat/CatNodeAttributes/CatNodeAttributesRecord.cs index 787f069f106..77515bb0704 100644 --- a/src/Nest/Cat/CatNodeAttributes/CatNodeAttributesRecord.cs +++ b/src/Nest/Cat/CatNodeAttributes/CatNodeAttributesRecord.cs @@ -5,30 +5,29 @@ namespace Nest [JsonObject] public class CatNodeAttributesRecord : ICatRecord { - // duration indices successful_shards failed_shards total_shards - [JsonProperty("id")] - public string Id { get; set; } - - [JsonProperty("node")] - public string Node { get; set; } - - [JsonProperty("pid")] - public long ProcessId { get; set; } + [JsonProperty("attr")] + public string Attribute { get; set; } [JsonProperty("host")] public string Host { get; set; } + // duration indices successful_shards failed_shards total_shards + [JsonProperty("id")] + public string Id { get; set; } + [JsonProperty("ip")] public string Ip { get; set; } + [JsonProperty("node")] + public string Node { get; set; } + [JsonProperty("port")] public long Port { get; set; } - [JsonProperty("attr")] - public string Attribute { get; set; } + [JsonProperty("pid")] + public long ProcessId { get; set; } [JsonProperty("value")] public string Value { get; set; } - } } diff --git a/src/Nest/Cat/CatNodeAttributes/CatNodeAttributesRequest.cs b/src/Nest/Cat/CatNodeAttributes/CatNodeAttributesRequest.cs index ca8329771f9..3c3957cc7e2 100644 --- a/src/Nest/Cat/CatNodeAttributes/CatNodeAttributesRequest.cs +++ b/src/Nest/Cat/CatNodeAttributes/CatNodeAttributesRequest.cs @@ -1,5 +1,4 @@ -using System; -#pragma warning disable 612, 618 +#pragma warning disable 612, 618 namespace Nest { diff --git a/src/Nest/Cat/CatNodeAttributes/ElasticClient-CatNodeAttributes.cs b/src/Nest/Cat/CatNodeAttributes/ElasticClient-CatNodeAttributes.cs index 42cf4ec2fad..eedfc0665b7 100644 --- a/src/Nest/Cat/CatNodeAttributes/ElasticClient-CatNodeAttributes.cs +++ b/src/Nest/Cat/CatNodeAttributes/ElasticClient-CatNodeAttributes.cs @@ -1,48 +1,53 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatNodeAttributes(Func selector = null); - /// + /// ICatResponse CatNodeAttributes(ICatNodeAttributesRequest request); - /// + /// Task> CatNodeAttributesAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatNodeAttributesAsync(ICatNodeAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatNodeAttributesAsync(ICatNodeAttributesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// - public ICatResponse CatNodeAttributes(Func selector = null) => - this.CatNodeAttributes(selector.InvokeOrDefault(new CatNodeAttributesDescriptor())); + /// + public ICatResponse + CatNodeAttributes(Func selector = null) => + CatNodeAttributes(selector.InvokeOrDefault(new CatNodeAttributesDescriptor())); - /// + /// public ICatResponse CatNodeAttributes(ICatNodeAttributesRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatNodeattrsDispatch>); + DoCat(request, + LowLevelDispatch.CatNodeattrsDispatch>); - /// + /// public Task> CatNodeAttributesAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatNodeAttributesAsync(selector.InvokeOrDefault(new CatNodeAttributesDescriptor()), cancellationToken); - - /// - public Task> CatNodeAttributesAsync(ICatNodeAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatNodeattrsDispatchAsync>); + ) => CatNodeAttributesAsync(selector.InvokeOrDefault(new CatNodeAttributesDescriptor()), cancellationToken); + /// + public Task> CatNodeAttributesAsync(ICatNodeAttributesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatNodeattrsDispatchAsync>); } } diff --git a/src/Nest/Cat/CatNodes/CatNodesRecord.cs b/src/Nest/Cat/CatNodes/CatNodesRecord.cs index 81a53a8884a..62951c42261 100644 --- a/src/Nest/Cat/CatNodes/CatNodesRecord.cs +++ b/src/Nest/Cat/CatNodes/CatNodesRecord.cs @@ -5,538 +5,668 @@ namespace Nest [JsonObject(MemberSerialization.OptIn)] public class CatNodesRecord : ICatRecord { - [JsonProperty("id")] - internal string _id { get; set; } - [JsonProperty("nodeId")] - internal string _nodeId { get; set; } - public string NodeId => this._id ?? this._nodeId; + public string Build => _b ?? _build; + public string CompletionSize => _completionSize ?? _cs ?? _completion_size; - [JsonProperty("pid")] - internal string _pid { get; set; } - [JsonProperty("p")] - internal string _p { get; set; } - public string Pid => this._p ?? this._pid; + [JsonProperty("cpu")] + public string CPU { get; internal set; } - [JsonProperty("ip")] - internal string _ip { get; set; } - [JsonProperty("i")] - internal string _i { get; set; } - public string Ip => this._i ?? this._ip; + public string DiskAvailable => _diskAvail ?? _disk ?? _d ?? _disk_avail; + public string FielddataEvictions => _fielddataEvictions ?? _fe ?? _fielddata_evictions; + public string FielddataMemory => _fielddataMemory ?? _fm ?? _fielddata_memory_size; + public int? FileDescriptorCurrent => _fileDescriptorCurrent ?? _fdc ?? _file_desc_current; + public int? FileDescriptorMax => _fileDescriptorMax ?? _fdm ?? _file_desc_max; + public int? FileDescriptorPercent => _fileDescriptorPercent ?? _fdp ?? _file_desc_percent; + public string FilterCacheEvictions => _filterCacheEvictions ?? _fce ?? _filter_cache_evictions; + public string FilterCacheMemory => _filterCacheMemory ?? _fcm ?? _filter_cache_memory_size; + public string FlushTotal => _flushTotal ?? _ft ?? _flush_total; + public string FlushTotalTime => _flushTotalTime ?? _ftt ?? _flush_total_time; + public string GetCurrent => _getCurrent ?? _gc ?? _get_current; + public string GetExistsTime => _getExistsTime ?? _geti ?? _get_exists_time; + public string GetExistsTotal => _getExistsTotal ?? _geto ?? _get_exists_total; + public string GetMissingTime => _getMissingTime ?? _gmti ?? _get_missing_time; + public string GetMissingTotal => _getMissingTotal ?? _gmto ?? _get_missing_total; + public string GetTime => _getTime ?? _gti ?? _get_time; + public string GetTotal => _getTotal ?? _gto ?? _get_total; + public string HeapCurrent => _heapCurrent ?? _hc ?? _heap_current; + public string HeapMax => _heapMax ?? _hm ?? _heap_max; + public string HeapPercent => _heapPercent ?? _hp ?? _heap_percent; + public string IdCacheMemory => _idCacheMemory ?? _im ?? _id_cache_memory_size; + public string IndexingDeleteCurrent => _indexingDeleteCurrent ?? _idcs ?? _indexing_delete_current; + public string IndexingDeleteTime => _indexingDeleteTime ?? _idti ?? _indexing_delete_time; + public string IndexingDeleteTotal => _indexingDeleteTotal ?? _idto ?? _indexing_delete_total; + public string IndexingIndexCurrent => _indexingIndexCurrent ?? _iic ?? _indexing_index_current; + public string IndexingIndexTime => _indexingIndexTime ?? _iiti ?? _indexing_index_time; + public string IndexingIndexTotal => _indexingIndexTotal ?? _iito ?? _indexing_index_total; + public string Ip => _i ?? _ip; + public string Jdk => _j ?? _jdk; - [JsonProperty("port")] - internal string _port { get; set; } - [JsonProperty("po")] - internal string _po { get; set; } - public string Port => this._po ?? this._port; + [JsonProperty("load_15m")] + public string LoadFifteenMinute { get; internal set; } - [JsonProperty("version")] - internal string _version { get; set; } - [JsonProperty("v")] - internal string _v { get; set; } - public string Version => this._v ?? this._version; + [JsonProperty("load_5m")] + public string LoadFiveMinute { get; internal set; } + + [JsonProperty("load_1m")] + public string LoadOneMinute { get; internal set; } + + public string Master => _m ?? _master; + public string MergesCurrent => _mergesCurrent ?? _mc ?? _merges_current; + public string MergesCurrentDocs => _mergesCurrentDocs ?? _mcd ?? _merges_current_docs; + public string MergesCurrentSize => _mergesCurrentSize ?? _mcs ?? _merges_current_size; + public string MergesTotal => _mergesTotal ?? _mt ?? _merges_total; + public string MergesTotalDocs => _mergesTotalDocs ?? _mtd ?? _merges_total_docs; + public string MergesTotalTime => _mergesTotalTime ?? _mtt ?? _merges_total_time; + public string Name => _n ?? _name; + public string NodeId => _id ?? _nodeId; + public string NodeRole => _nodeRole ?? _data_client ?? _dc ?? _r ?? _node_role; + public string PercolateCurrent => _percolateCurrent ?? _pc ?? _percolate_current; + public string PercolateMemory => _percolateMemory ?? _pm ?? _percolate_memory_size; + public string PercolateQueries => _percolate_queries ?? _pq ?? _percolate_queries; + public string PercolateTime => _percolateTime ?? _pti ?? _percolate_time; + public string PercolateTotal => _percolateTotal ?? _pto ?? _percolate_total; + public string Pid => _p ?? _pid; + public string Port => _po ?? _port; + public string RamCurrent => _ramCurrent ?? _rc ?? _ram_current; + public string RamMax => _ramMax ?? _rm ?? _ram_max; + public string RamPercent => _ramPercent ?? _rp ?? _ram_percent; + public string RefreshTime => _refreshTime ?? _rti ?? _refreshTime; + public string RefreshTotal => _refreshTotal ?? _rto ?? _refresh_total; + public string SearchFetchCurrent => _searchFetchCurrent ?? _sfc ?? _search_fetch_current; + public string SearchFetchTime => _searchFetchTime ?? _sfti ?? _search_fetch_time; + public string SearchFetchTotal => _searchFetchTotal ?? _sfto ?? _searchFetchTotal; + public string SearchOpenContexts => _searchOpenContexts ?? _so ?? _search_open_contexts; + public string SearchQueryCurrent => _searchQueryCurrent ?? _sqc ?? _search_query_current; + public string SearchQueryTime => _searchQueryTime ?? _sqti ?? _search_query_time; + public string SearchQueryTotal => _searchQueryTotal ?? _sqto ?? _search_query_total; + public string SegmentsCount => _segmentsCount ?? _sc ?? _segmentsCount; + public string SegmentsIndexWriterMaxMemory => _segmentsIndexWriterMaxMemory ?? _siwmx ?? _segments_index_writer_max_memory; + public string SegmentsIndexWriterMemory => _segmentsIndexWriterMemory ?? _siwm ?? _segments_index_writer_memory; + public string SegmentsMemory => _segmentsMemory ?? _sm ?? _segments_memory; + public string SegmentsVersionMapMemory => _segmentsVersionMapMemory ?? _svmm ?? _segments_version_map_memory; + public string Uptime => _u ?? _uptime; + public string Version => _v ?? _version; - [JsonProperty("build")] - internal string _build { get; set; } [JsonProperty("b")] internal string _b { get; set; } - public string Build => this._b ?? this._build; - [JsonProperty("jdk")] - internal string _jdk { get; set; } - [JsonProperty("j")] - internal string _j { get; set; } - public string Jdk => this._j ?? this._jdk; + [JsonProperty("build")] + internal string _build { get; set; } + + [JsonProperty("completion.size")] + internal string _completion_size { get; set; } + + [JsonProperty("completionSize")] + internal string _completionSize { get; set; } + + [JsonProperty("cs")] + internal string _cs { get; set; } - [JsonProperty("disk.avail")] - internal string _disk_avail { get; set; } [JsonProperty("d")] internal string _d { get; set; } + + [JsonProperty("data/client")] + internal string _data_client { get; set; } + + [JsonProperty("dc")] + internal string _dc { get; set; } + [JsonProperty("disk")] internal string _disk { get; set; } + + [JsonProperty("disk.avail")] + internal string _disk_avail { get; set; } + [JsonProperty("diskAvail")] internal string _diskAvail { get; set; } - public string DiskAvailable => this._diskAvail ?? this._disk ?? this._d ?? this._disk_avail; - [JsonProperty("heap.current")] - internal string _heap_current { get; set; } - [JsonProperty("hc")] - internal string _hc { get; set; } - [JsonProperty("heapCurrent")] - internal string _heapCurrent { get; set; } - public string HeapCurrent => this._heapCurrent ?? this._hc ?? this._heap_current; + [JsonProperty("fce")] + internal string _fce { get; set; } - [JsonProperty("heap.percent")] - internal string _heap_percent { get; set; } - [JsonProperty("hp")] - internal string _hp { get; set; } - [JsonProperty("heapPercent")] - internal string _heapPercent { get; set; } - public string HeapPercent => this._heapPercent ?? this._hp ?? this._heap_percent; + [JsonProperty("fcm")] + internal string _fcm { get; set; } - [JsonProperty("heap.max")] - internal string _heap_max { get; set; } - [JsonProperty("hm")] - internal string _hm { get; set; } - [JsonProperty("heapMax")] - internal string _heapMax { get; set; } - public string HeapMax => this._heapMax ?? this._hm ?? this._heap_max; + [JsonProperty("fdc")] + internal int? _fdc { get; set; } - [JsonProperty("ram.current")] - internal string _ram_current { get; set; } - [JsonProperty("rc")] - internal string _rc { get; set; } - [JsonProperty("ramCurrent")] - internal string _ramCurrent { get; set; } - public string RamCurrent => this._ramCurrent ?? this._rc ?? this._ram_current; + [JsonProperty("fdm")] + internal int? _fdm { get; set; } - [JsonProperty("ram.percent")] - internal string _ram_percent { get; set; } - [JsonProperty("rp")] - internal string _rp { get; set; } - [JsonProperty("ramPercent")] - internal string _ramPercent { get; set; } - public string RamPercent => this._ramPercent ?? this._rp ?? this._ram_percent; + [JsonProperty("fdp")] + internal int? _fdp { get; set; } - [JsonProperty("ram.max")] - internal string _ram_max { get; set; } - [JsonProperty("rm")] - internal string _rm { get; set; } - [JsonProperty("ramMax")] - internal string _ramMax { get; set; } - public string RamMax => this._ramMax ?? this._rm ?? this._ram_max; + [JsonProperty("fe")] + internal string _fe { get; set; } - [JsonProperty("load_1m")] - public string LoadOneMinute { get; internal set; } + [JsonProperty("fielddata.evictions")] + internal string _fielddata_evictions { get; set; } - [JsonProperty("load_5m")] - public string LoadFiveMinute { get; internal set; } + [JsonProperty("fielddata.memory_size")] + internal string _fielddata_memory_size { get; set; } - [JsonProperty("load_15m")] - public string LoadFifteenMinute { get; internal set; } + [JsonProperty("fielddataEvictions")] + internal string _fielddataEvictions { get; set; } - [JsonProperty("cpu")] - public string CPU { get; internal set; } + [JsonProperty("fielddataMemory")] + internal string _fielddataMemory { get; set; } - [JsonProperty("uptime")] - internal string _uptime { get; set; } - [JsonProperty("u")] - internal string _u { get; set; } - public string Uptime => this._u ?? this._uptime; + [JsonProperty("file_desc.current")] + internal int? _file_desc_current { get; set; } - [JsonProperty("node.role")] - internal string _node_role { get; set; } - [JsonProperty("r")] - internal string _r { get; set; } - [JsonProperty("dc")] - internal string _dc { get; set; } - [JsonProperty("data/client")] - internal string _data_client { get; set; } - [JsonProperty("nodeRole")] - internal string _nodeRole { get; set; } - public string NodeRole => this._nodeRole ?? this._data_client ?? this._dc ?? this._r ?? this._node_role; + [JsonProperty("file_desc.max")] + internal int? _file_desc_max { get; set; } - [JsonProperty("master")] - internal string _master { get; set; } - [JsonProperty("m")] - internal string _m { get; set; } - public string Master => this._m ?? this._master; + [JsonProperty("file_desc.percent")] + internal int? _file_desc_percent { get; set; } - [JsonProperty("name")] - internal string _name { get; set; } - [JsonProperty("n")] - internal string _n { get; set; } - public string Name => this._n ?? this._name; + [JsonProperty("fileDescriptorCurrent")] + internal int? _fileDescriptorCurrent { get; set; } - [JsonProperty("completion.size")] - internal string _completion_size { get; set; } - [JsonProperty("cs")] - internal string _cs { get; set; } - [JsonProperty("completionSize")] - internal string _completionSize { get; set; } - public string CompletionSize => this._completionSize ?? this._cs ?? this._completion_size; + [JsonProperty("fileDescriptorMax")] + internal int? _fileDescriptorMax { get; set; } - [JsonProperty("fielddata.memory_size")] - internal string _fielddata_memory_size { get; set; } - [JsonProperty("fm")] - internal string _fm { get; set; } - [JsonProperty("fielddataMemory")] - internal string _fielddataMemory { get; set; } - public string FielddataMemory => this._fielddataMemory ?? this._fm ?? this._fielddata_memory_size; + [JsonProperty("fileDescriptorPercent")] + internal int? _fileDescriptorPercent { get; set; } - [JsonProperty("fielddata.evictions")] - internal string _fielddata_evictions { get; set; } - [JsonProperty("fe")] - internal string _fe { get; set; } - [JsonProperty("fielddataEvictions")] - internal string _fielddataEvictions { get; set; } - public string FielddataEvictions => this._fielddataEvictions ?? this._fe ?? this._fielddata_evictions; + [JsonProperty("filter_cache.evictions")] + internal string _filter_cache_evictions { get; set; } [JsonProperty("filter_cache.memory_size")] internal string _filter_cache_memory_size { get; set; } - [JsonProperty("fcm")] - internal string _fcm { get; set; } - [JsonProperty("filterCacheMemory")] - internal string _filterCacheMemory { get; set; } - public string FilterCacheMemory => this._filterCacheMemory ?? this._fcm ?? this._filter_cache_memory_size; - [JsonProperty("filter_cache.evictions")] - internal string _filter_cache_evictions { get; set; } - [JsonProperty("fce")] - internal string _fce { get; set; } [JsonProperty("filterCacheEvictions")] internal string _filterCacheEvictions { get; set; } - public string FilterCacheEvictions => this._filterCacheEvictions ?? this._fce ?? this._filter_cache_evictions; + + [JsonProperty("filterCacheMemory")] + internal string _filterCacheMemory { get; set; } [JsonProperty("flush.total")] internal string _flush_total { get; set; } - [JsonProperty("ft")] - internal string _ft { get; set; } - [JsonProperty("flushTotal")] - internal string _flushTotal { get; set; } - public string FlushTotal => this._flushTotal ?? this._ft ?? this._flush_total; [JsonProperty("flush.total_time")] internal string _flush_total_time { get; set; } - [JsonProperty("ftt")] - internal string _ftt { get; set; } + + [JsonProperty("flushTotal")] + internal string _flushTotal { get; set; } + [JsonProperty("flushTotalTime")] internal string _flushTotalTime { get; set; } - public string FlushTotalTime => this._flushTotalTime ?? this._ftt ?? this._flush_total_time; - [JsonProperty("file_desc.current")] - internal int? _file_desc_current { get; set; } - [JsonProperty("fdc")] - internal int? _fdc { get; set; } - [JsonProperty("fileDescriptorCurrent")] - internal int? _fileDescriptorCurrent { get; set; } - public int? FileDescriptorCurrent => this._fileDescriptorCurrent ?? this._fdc ?? this._file_desc_current; + [JsonProperty("fm")] + internal string _fm { get; set; } - [JsonProperty("file_desc.percent")] - internal int? _file_desc_percent { get; set; } - [JsonProperty("fdp")] - internal int? _fdp { get; set; } - [JsonProperty("fileDescriptorPercent")] - internal int? _fileDescriptorPercent { get; set; } - public int? FileDescriptorPercent => this._fileDescriptorPercent ?? this._fdp ?? this._file_desc_percent; + [JsonProperty("ft")] + internal string _ft { get; set; } - [JsonProperty("file_desc.max")] - internal int? _file_desc_max { get; set; } - [JsonProperty("fdm")] - internal int? _fdm { get; set; } - [JsonProperty("fileDescriptorMax")] - internal int? _fileDescriptorMax { get; set; } - public int? FileDescriptorMax => this._fileDescriptorMax ?? this._fdm ?? this._file_desc_max; + [JsonProperty("ftt")] + internal string _ftt { get; set; } - [JsonProperty("get.current")] - internal string _get_current { get; set; } [JsonProperty("gc")] internal string _gc { get; set; } - [JsonProperty("getCurrent")] - internal string _getCurrent { get; set; } - public string GetCurrent => this._getCurrent ?? this._gc ?? this._get_current; + + [JsonProperty("get.current")] + internal string _get_current { get; set; } + + [JsonProperty("get.exists_time")] + internal string _get_exists_time { get; set; } + + [JsonProperty("get.exists_total")] + internal string _get_exists_total { get; set; } + + [JsonProperty("get.missing_time")] + internal string _get_missing_time { get; set; } + + [JsonProperty("get.missing_total")] + internal string _get_missing_total { get; set; } [JsonProperty("get.time")] internal string _get_time { get; set; } - [JsonProperty("gti")] - internal string _gti { get; set; } - [JsonProperty("getTime")] - internal string _getTime { get; set; } - public string GetTime => this._getTime ?? this._gti ?? this._get_time; [JsonProperty("get.total")] internal string _get_total { get; set; } - [JsonProperty("gto")] - internal string _gto { get; set; } - [JsonProperty("getTotal")] - internal string _getTotal { get; set; } - public string GetTotal => this._getTotal ?? this._gto ?? this._get_total; - [JsonProperty("get.exists_time")] - internal string _get_exists_time { get; set; } - [JsonProperty("geti")] - internal string _geti { get; set; } + [JsonProperty("getCurrent")] + internal string _getCurrent { get; set; } + [JsonProperty("getExistsTime")] internal string _getExistsTime { get; set; } - public string GetExistsTime => this._getExistsTime ?? this._geti ?? this._get_exists_time; - [JsonProperty("get.exists_total")] - internal string _get_exists_total { get; set; } - [JsonProperty("geto")] - internal string _geto { get; set; } [JsonProperty("getExistsTotal")] internal string _getExistsTotal { get; set; } - public string GetExistsTotal => this._getExistsTotal ?? this._geto ?? this._get_exists_total; - [JsonProperty("get.missing_time")] - internal string _get_missing_time { get; set; } - [JsonProperty("gmti")] - internal string _gmti { get; set; } + [JsonProperty("geti")] + internal string _geti { get; set; } + [JsonProperty("getMissingTime")] internal string _getMissingTime { get; set; } - public string GetMissingTime => this._getMissingTime ?? this._gmti ?? this._get_missing_time; - [JsonProperty("get.missing_total")] - internal string _get_missing_total { get; set; } - [JsonProperty("gmto")] - internal string _gmto { get; set; } [JsonProperty("getMissingTotal")] internal string _getMissingTotal { get; set; } - public string GetMissingTotal => this._getMissingTotal ?? this._gmto ?? this._get_missing_total; + + [JsonProperty("geto")] + internal string _geto { get; set; } + + [JsonProperty("getTime")] + internal string _getTime { get; set; } + + [JsonProperty("getTotal")] + internal string _getTotal { get; set; } + + [JsonProperty("gmti")] + internal string _gmti { get; set; } + + [JsonProperty("gmto")] + internal string _gmto { get; set; } + + [JsonProperty("gti")] + internal string _gti { get; set; } + + [JsonProperty("gto")] + internal string _gto { get; set; } + + [JsonProperty("hc")] + internal string _hc { get; set; } + + [JsonProperty("heap.current")] + internal string _heap_current { get; set; } + + [JsonProperty("heap.max")] + internal string _heap_max { get; set; } + + [JsonProperty("heap.percent")] + internal string _heap_percent { get; set; } + + [JsonProperty("heapCurrent")] + internal string _heapCurrent { get; set; } + + [JsonProperty("heapMax")] + internal string _heapMax { get; set; } + + [JsonProperty("heapPercent")] + internal string _heapPercent { get; set; } + + [JsonProperty("hm")] + internal string _hm { get; set; } + + [JsonProperty("hp")] + internal string _hp { get; set; } + + [JsonProperty("i")] + internal string _i { get; set; } + + [JsonProperty("id")] + internal string _id { get; set; } [JsonProperty("id_cache.memory_size")] internal string _id_cache_memory_size { get; set; } - [JsonProperty("im")] - internal string _im { get; set; } + [JsonProperty("idCacheMemory")] internal string _idCacheMemory { get; set; } - public string IdCacheMemory => this._idCacheMemory ?? this._im ?? this._id_cache_memory_size; - [JsonProperty("indexing.delete_current")] - internal string _indexing_delete_current { get; set; } [JsonProperty("idc")] internal string _idcs { get; set; } - [JsonProperty("indexingDeleteCurrent")] - internal string _indexingDeleteCurrent { get; set; } - public string IndexingDeleteCurrent => this._indexingDeleteCurrent ?? this._idcs ?? this._indexing_delete_current; - [JsonProperty("indexing.delete_time")] - internal string _indexing_delete_time { get; set; } [JsonProperty("idti")] internal string _idti { get; set; } - [JsonProperty("indexingDeleteTime")] - internal string _indexingDeleteTime { get; set; } - public string IndexingDeleteTime => this._indexingDeleteTime ?? this._idti ?? this._indexing_delete_time; - [JsonProperty("indexing.delete_total")] - internal string _indexing_delete_total { get; set; } [JsonProperty("idto")] internal string _idto { get; set; } - [JsonProperty("indexingDeleteTotal")] - internal string _indexingDeleteTotal { get; set; } - public string IndexingDeleteTotal => this._indexingDeleteTotal ?? this._idto ?? this._indexing_delete_total; - [JsonProperty("indexing.index_current")] - internal string _indexing_index_current { get; set; } [JsonProperty("iic")] internal string _iic { get; set; } - [JsonProperty("indexingIndexCurrent")] - internal string _indexingIndexCurrent { get; set; } - public string IndexingIndexCurrent => this._indexingIndexCurrent ?? this._iic ?? this._indexing_index_current; - [JsonProperty("indexing.index_time")] - internal string _indexing_index_time { get; set; } [JsonProperty("iiti")] internal string _iiti { get; set; } - [JsonProperty("indexingIndexTime")] - internal string _indexingIndexTime { get; set; } - public string IndexingIndexTime => this._indexingIndexTime ?? this._iiti ?? this._indexing_index_time; - [JsonProperty("indexing.index_total")] - internal string _indexing_index_total { get; set; } [JsonProperty("iito")] internal string _iito { get; set; } + + [JsonProperty("im")] + internal string _im { get; set; } + + [JsonProperty("indexing.delete_current")] + internal string _indexing_delete_current { get; set; } + + [JsonProperty("indexing.delete_time")] + internal string _indexing_delete_time { get; set; } + + [JsonProperty("indexing.delete_total")] + internal string _indexing_delete_total { get; set; } + + [JsonProperty("indexing.index_current")] + internal string _indexing_index_current { get; set; } + + [JsonProperty("indexing.index_time")] + internal string _indexing_index_time { get; set; } + + [JsonProperty("indexing.index_total")] + internal string _indexing_index_total { get; set; } + + [JsonProperty("indexingDeleteCurrent")] + internal string _indexingDeleteCurrent { get; set; } + + [JsonProperty("indexingDeleteTime")] + internal string _indexingDeleteTime { get; set; } + + [JsonProperty("indexingDeleteTotal")] + internal string _indexingDeleteTotal { get; set; } + + [JsonProperty("indexingIndexCurrent")] + internal string _indexingIndexCurrent { get; set; } + + [JsonProperty("indexingIndexTime")] + internal string _indexingIndexTime { get; set; } + [JsonProperty("indexingIndexTotal")] internal string _indexingIndexTotal { get; set; } - public string IndexingIndexTotal => this._indexingIndexTotal ?? this._iito ?? this._indexing_index_total; - [JsonProperty("merges.current")] - internal string _merges_current { get; set; } + [JsonProperty("ip")] + internal string _ip { get; set; } + + [JsonProperty("j")] + internal string _j { get; set; } + + [JsonProperty("jdk")] + internal string _jdk { get; set; } + + [JsonProperty("m")] + internal string _m { get; set; } + + [JsonProperty("master")] + internal string _master { get; set; } + [JsonProperty("mc")] internal string _mc { get; set; } - [JsonProperty("mergesCurrent")] - internal string _mergesCurrent { get; set; } - public string MergesCurrent => this._mergesCurrent ?? this._mc ?? this._merges_current; - [JsonProperty("merges.current_docs")] - internal string _merges_current_docs { get; set; } [JsonProperty("mcd")] internal string _mcd { get; set; } - [JsonProperty("mergesCurrentDocs")] - internal string _mergesCurrentDocs { get; set; } - public string MergesCurrentDocs => this._mergesCurrentDocs ?? this._mcd ?? this._merges_current_docs; - [JsonProperty("merges.current_size")] - internal string _merges_current_size { get; set; } [JsonProperty("mcs")] internal string _mcs { get; set; } + + [JsonProperty("merges.current")] + internal string _merges_current { get; set; } + + [JsonProperty("merges.current_docs")] + internal string _merges_current_docs { get; set; } + + [JsonProperty("merges.current_size")] + internal string _merges_current_size { get; set; } + + [JsonProperty("merges.total")] + internal string _merges_total { get; set; } + + [JsonProperty("merges.total_docs")] + internal string _merges_total_docs { get; set; } + + [JsonProperty("merges.total_time")] + internal string _merges_total_time { get; set; } + + [JsonProperty("mergesCurrent")] + internal string _mergesCurrent { get; set; } + + [JsonProperty("mergesCurrentDocs")] + internal string _mergesCurrentDocs { get; set; } + [JsonProperty("mergesCurrentSize")] internal string _mergesCurrentSize { get; set; } - public string MergesCurrentSize => this._mergesCurrentSize ?? this._mcs ?? this._merges_current_size; - [JsonProperty("merges.total")] - internal string _merges_total { get; set; } + [JsonProperty("mergesTotal")] + internal string _mergesTotal { get; set; } + + [JsonProperty("mergesTotalDocs")] + internal string _mergesTotalDocs { get; set; } + + [JsonProperty("mergesTotalTime")] + internal string _mergesTotalTime { get; set; } + [JsonProperty("mt")] internal string _mt { get; set; } - [JsonProperty("mergesTotal")] - internal string _mergesTotal { get; set; } - public string MergesTotal => this._mergesTotal ?? this._mt ?? this._merges_total; - [JsonProperty("merges.total_docs")] - internal string _merges_total_docs { get; set; } [JsonProperty("mtd")] internal string _mtd { get; set; } - [JsonProperty("mergesTotalDocs")] - internal string _mergesTotalDocs { get; set; } - public string MergesTotalDocs => this._mergesTotalDocs ?? this._mtd ?? this._merges_total_docs; - [JsonProperty("merges.total_time")] - internal string _merges_total_time { get; set; } [JsonProperty("mtt")] internal string _mtt { get; set; } - [JsonProperty("mergesTotalTime")] - internal string _mergesTotalTime { get; set; } - public string MergesTotalTime => this._mergesTotalTime ?? this._mtt ?? this._merges_total_time; - [JsonProperty("percolate.current")] - internal string _percolate_current { get; set; } + [JsonProperty("n")] + internal string _n { get; set; } + + [JsonProperty("name")] + internal string _name { get; set; } + + [JsonProperty("node.role")] + internal string _node_role { get; set; } + + [JsonProperty("nodeId")] + internal string _nodeId { get; set; } + + [JsonProperty("nodeRole")] + internal string _nodeRole { get; set; } + + [JsonProperty("p")] + internal string _p { get; set; } + [JsonProperty("pc")] internal string _pc { get; set; } - [JsonProperty("percolateCurrent")] - internal string _percolateCurrent { get; set; } - public string PercolateCurrent => this._percolateCurrent ?? this._pc ?? this._percolate_current; + + [JsonProperty("percolate.current")] + internal string _percolate_current { get; set; } [JsonProperty("percolate.memory_size")] internal string _percolate_memory_size { get; set; } - [JsonProperty("pm")] - internal string _pm { get; set; } - [JsonProperty("percolateMemory")] - internal string _percolateMemory { get; set; } - public string PercolateMemory => this._percolateMemory ?? this._pm ?? this._percolate_memory_size; [JsonProperty("percolate.queries")] internal string _percolate_queries { get; set; } - [JsonProperty("pq")] - internal string _pq { get; set; } - [JsonProperty("percolateQueries")] - internal string _percolateQueries { get; set; } - public string PercolateQueries => this._percolate_queries ?? this._pq ?? this._percolate_queries; [JsonProperty("percolate.time")] internal string _percolate_time { get; set; } - [JsonProperty("pti")] - internal string _pti { get; set; } - [JsonProperty("percolateTime")] - internal string _percolateTime { get; set; } - public string PercolateTime => this._percolateTime ?? this._pti ?? this._percolate_time; [JsonProperty("percolate.total")] internal string _percolate_total { get; set; } - [JsonProperty("pto")] - internal string _pto { get; set; } + + [JsonProperty("percolateCurrent")] + internal string _percolateCurrent { get; set; } + + [JsonProperty("percolateMemory")] + internal string _percolateMemory { get; set; } + + [JsonProperty("percolateQueries")] + internal string _percolateQueries { get; set; } + + [JsonProperty("percolateTime")] + internal string _percolateTime { get; set; } + [JsonProperty("percolateTotal")] internal string _percolateTotal { get; set; } - public string PercolateTotal => this._percolateTotal ?? this._pto ?? this._percolate_total; + + [JsonProperty("pid")] + internal string _pid { get; set; } + + [JsonProperty("pm")] + internal string _pm { get; set; } + + [JsonProperty("po")] + internal string _po { get; set; } + + [JsonProperty("port")] + internal string _port { get; set; } + + [JsonProperty("pq")] + internal string _pq { get; set; } + + [JsonProperty("pti")] + internal string _pti { get; set; } + + [JsonProperty("pto")] + internal string _pto { get; set; } + + [JsonProperty("r")] + internal string _r { get; set; } + + [JsonProperty("ram.current")] + internal string _ram_current { get; set; } + + [JsonProperty("ram.max")] + internal string _ram_max { get; set; } + + [JsonProperty("ram.percent")] + internal string _ram_percent { get; set; } + + [JsonProperty("ramCurrent")] + internal string _ramCurrent { get; set; } + + [JsonProperty("ramMax")] + internal string _ramMax { get; set; } + + [JsonProperty("ramPercent")] + internal string _ramPercent { get; set; } + + [JsonProperty("rc")] + internal string _rc { get; set; } + + [JsonProperty("refresh.time")] + internal string _refresh_time { get; set; } [JsonProperty("refresh.total")] internal string _refresh_total { get; set; } - [JsonProperty("rto")] - internal string _rto { get; set; } + + [JsonProperty("refreshTime")] + internal string _refreshTime { get; set; } + [JsonProperty("refreshTotal")] internal string _refreshTotal { get; set; } - public string RefreshTotal => this._refreshTotal ?? this._rto ?? this._refresh_total; - [JsonProperty("refresh.time")] - internal string _refresh_time { get; set; } + [JsonProperty("rm")] + internal string _rm { get; set; } + + [JsonProperty("rp")] + internal string _rp { get; set; } + [JsonProperty("rti")] internal string _rti { get; set; } - [JsonProperty("refreshTime")] - internal string _refreshTime { get; set; } - public string RefreshTime => this._refreshTime ?? this._rti ?? this._refreshTime; + + [JsonProperty("rto")] + internal string _rto { get; set; } + + [JsonProperty("sc")] + internal string _sc { get; set; } [JsonProperty("search.fetch_current")] internal string _search_fetch_current { get; set; } - [JsonProperty("sfc")] - internal string _sfc { get; set; } - [JsonProperty("searchFetchCurrent")] - internal string _searchFetchCurrent { get; set; } - public string SearchFetchCurrent => this._searchFetchCurrent ?? this._sfc ?? this._search_fetch_current; [JsonProperty("search.fetch_time")] internal string _search_fetch_time { get; set; } - [JsonProperty("sfti")] - internal string _sfti { get; set; } - [JsonProperty("searchFetchTime")] - internal string _searchFetchTime { get; set; } - public string SearchFetchTime => this._searchFetchTime ?? this._sfti ?? this._search_fetch_time; [JsonProperty("search.fetch_total")] internal string _search_fetch_total { get; set; } - [JsonProperty("sfto")] - internal string _sfto { get; set; } - [JsonProperty("searchFetchTotal")] - internal string _searchFetchTotal { get; set; } - public string SearchFetchTotal => this._searchFetchTotal ?? this._sfto ?? this._searchFetchTotal; [JsonProperty("search.open_contexts")] internal string _search_open_contexts { get; set; } - [JsonProperty("so")] - internal string _so { get; set; } - [JsonProperty("searchOpenContexts")] - internal string _searchOpenContexts { get; set; } - public string SearchOpenContexts => this._searchOpenContexts ?? this._so ?? this._search_open_contexts; [JsonProperty("search.query_current")] internal string _search_query_current { get; set; } - [JsonProperty("sqc")] - internal string _sqc { get; set; } - [JsonProperty("searchQueryCurrent")] - internal string _searchQueryCurrent { get; set; } - public string SearchQueryCurrent => this._searchQueryCurrent ?? this._sqc ?? this._search_query_current; [JsonProperty("search.query_time")] internal string _search_query_time { get; set; } - [JsonProperty("sqti")] - internal string _sqti { get; set; } - [JsonProperty("searchQueryTime")] - internal string _searchQueryTime { get; set; } - public string SearchQueryTime => this._searchQueryTime ?? this._sqti ?? this._search_query_time; [JsonProperty("search.query_total")] internal string _search_query_total { get; set; } - [JsonProperty("sqto")] - internal string _sqto { get; set; } + + [JsonProperty("searchFetchCurrent")] + internal string _searchFetchCurrent { get; set; } + + [JsonProperty("searchFetchTime")] + internal string _searchFetchTime { get; set; } + + [JsonProperty("searchFetchTotal")] + internal string _searchFetchTotal { get; set; } + + [JsonProperty("searchOpenContexts")] + internal string _searchOpenContexts { get; set; } + + [JsonProperty("searchQueryCurrent")] + internal string _searchQueryCurrent { get; set; } + + [JsonProperty("searchQueryTime")] + internal string _searchQueryTime { get; set; } + [JsonProperty("searchQueryTotal")] internal string _searchQueryTotal { get; set; } - public string SearchQueryTotal => this._searchQueryTotal ?? this._sqto ?? this._search_query_total; [JsonProperty("segments.count")] internal string _segments_count { get; set; } - [JsonProperty("sc")] - internal string _sc { get; set; } - [JsonProperty("segmentsCount")] - internal string _segmentsCount { get; set; } - public string SegmentsCount => this._segmentsCount ?? this._sc ?? this._segmentsCount; + + [JsonProperty("segments.index_writer_max_memory")] + internal string _segments_index_writer_max_memory { get; set; } + + [JsonProperty("segments.index_writer_memory")] + internal string _segments_index_writer_memory { get; set; } [JsonProperty("segments.memory")] internal string _segments_memory { get; set; } - [JsonProperty("sm")] - internal string _sm { get; set; } + + [JsonProperty("segments.version_map_memory")] + internal string _segments_version_map_memory { get; set; } + + [JsonProperty("segmentsCount")] + internal string _segmentsCount { get; set; } + + [JsonProperty("segmentsIndexWriterMaxMemory")] + internal string _segmentsIndexWriterMaxMemory { get; set; } + + [JsonProperty("segmentsIndexWriterMemory")] + internal string _segmentsIndexWriterMemory { get; set; } + [JsonProperty("segmentsMemory")] internal string _segmentsMemory { get; set; } - public string SegmentsMemory => this._segmentsMemory ?? this._sm ?? this._segments_memory; - [JsonProperty("segments.index_writer_memory")] - internal string _segments_index_writer_memory { get; set; } + [JsonProperty("segmentsVersionMapMemory")] + internal string _segmentsVersionMapMemory { get; set; } + + [JsonProperty("sfc")] + internal string _sfc { get; set; } + + [JsonProperty("sfti")] + internal string _sfti { get; set; } + + [JsonProperty("sfto")] + internal string _sfto { get; set; } + [JsonProperty("siwm")] internal string _siwm { get; set; } - [JsonProperty("segmentsIndexWriterMemory")] - internal string _segmentsIndexWriterMemory { get; set; } - public string SegmentsIndexWriterMemory => this._segmentsIndexWriterMemory ?? this._siwm ?? this._segments_index_writer_memory; - [JsonProperty("segments.index_writer_max_memory")] - internal string _segments_index_writer_max_memory { get; set; } [JsonProperty("siwmx")] internal string _siwmx { get; set; } - [JsonProperty("segmentsIndexWriterMaxMemory")] - internal string _segmentsIndexWriterMaxMemory { get; set; } - public string SegmentsIndexWriterMaxMemory => this._segmentsIndexWriterMaxMemory ?? this._siwmx ?? this._segments_index_writer_max_memory; - [JsonProperty("segments.version_map_memory")] - internal string _segments_version_map_memory { get; set; } + [JsonProperty("sm")] + internal string _sm { get; set; } + + [JsonProperty("so")] + internal string _so { get; set; } + + [JsonProperty("sqc")] + internal string _sqc { get; set; } + + [JsonProperty("sqti")] + internal string _sqti { get; set; } + + [JsonProperty("sqto")] + internal string _sqto { get; set; } + [JsonProperty("svmm")] internal string _svmm { get; set; } - [JsonProperty("segmentsVersionMapMemory")] - internal string _segmentsVersionMapMemory { get; set; } - public string SegmentsVersionMapMemory => this._segmentsVersionMapMemory ?? this._svmm ?? this._segments_version_map_memory; + + [JsonProperty("u")] + internal string _u { get; set; } + + [JsonProperty("uptime")] + internal string _uptime { get; set; } + + [JsonProperty("v")] + internal string _v { get; set; } + + [JsonProperty("version")] + internal string _version { get; set; } } } diff --git a/src/Nest/Cat/CatNodes/ElasticClient-CatNodes.cs b/src/Nest/Cat/CatNodes/ElasticClient-CatNodes.cs index 513ef6f0756..c5c28690b29 100644 --- a/src/Nest/Cat/CatNodes/ElasticClient-CatNodes.cs +++ b/src/Nest/Cat/CatNodes/ElasticClient-CatNodes.cs @@ -1,42 +1,49 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatNodes(Func selector = null); - /// + /// ICatResponse CatNodes(ICatNodesRequest request); - /// - Task> CatNodesAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatNodesAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task> CatNodesAsync(ICatNodesRequest request, CancellationToken cancellationToken = default(CancellationToken)); - } public partial class ElasticClient { - /// + /// public ICatResponse CatNodes(Func selector = null) => - this.CatNodes(selector.InvokeOrDefault(new CatNodesDescriptor())); - - /// - public ICatResponse CatNodes(ICatNodesRequest request)=> - this.DoCat(request, this.LowLevelDispatch.CatNodesDispatch>); - - /// - public Task> CatNodesAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.CatNodesAsync(selector.InvokeOrDefault(new CatNodesDescriptor()), cancellationToken); - - /// - public Task> CatNodesAsync(ICatNodesRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatNodesDispatchAsync>); + CatNodes(selector.InvokeOrDefault(new CatNodesDescriptor())); + + /// + public ICatResponse CatNodes(ICatNodesRequest request) => + DoCat(request, + LowLevelDispatch.CatNodesDispatch>); + + /// + public Task> CatNodesAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + CatNodesAsync(selector.InvokeOrDefault(new CatNodesDescriptor()), cancellationToken); + + /// + public Task> CatNodesAsync(ICatNodesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatNodesDispatchAsync>); } } diff --git a/src/Nest/Cat/CatPendingTasks/CatPendingTasksRecord.cs b/src/Nest/Cat/CatPendingTasks/CatPendingTasksRecord.cs index b29a4c82665..63db30b72af 100644 --- a/src/Nest/Cat/CatPendingTasks/CatPendingTasksRecord.cs +++ b/src/Nest/Cat/CatPendingTasks/CatPendingTasksRecord.cs @@ -8,14 +8,13 @@ public class CatPendingTasksRecord : ICatRecord [JsonProperty("insertOrder")] public int? InsertOrder { get; set; } - [JsonProperty("timeInQueue")] - public string TimeInQueue { get; set; } - [JsonProperty("priority")] public string Priority { get; set; } [JsonProperty("source")] public string Source { get; set; } + [JsonProperty("timeInQueue")] + public string TimeInQueue { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatPendingTasks/ElasticClient-CatPendingTasks.cs b/src/Nest/Cat/CatPendingTasks/ElasticClient-CatPendingTasks.cs index 07b423cf1ca..e790d5862ed 100644 --- a/src/Nest/Cat/CatPendingTasks/ElasticClient-CatPendingTasks.cs +++ b/src/Nest/Cat/CatPendingTasks/ElasticClient-CatPendingTasks.cs @@ -1,46 +1,52 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatPendingTasks(Func selector = null); - /// + /// ICatResponse CatPendingTasks(ICatPendingTasksRequest request); - /// + /// Task> CatPendingTasksAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatPendingTasksAsync(ICatPendingTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatPendingTasksAsync(ICatPendingTasksRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatPendingTasks(Func selector = null) => - this.CatPendingTasks(selector.InvokeOrDefault(new CatPendingTasksDescriptor())); + CatPendingTasks(selector.InvokeOrDefault(new CatPendingTasksDescriptor())); - /// + /// public ICatResponse CatPendingTasks(ICatPendingTasksRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatPendingTasksDispatch>); + DoCat(request, + LowLevelDispatch.CatPendingTasksDispatch>); - /// + /// public Task> CatPendingTasksAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatPendingTasksAsync(selector.InvokeOrDefault(new CatPendingTasksDescriptor()), cancellationToken); + ) => CatPendingTasksAsync(selector.InvokeOrDefault(new CatPendingTasksDescriptor()), cancellationToken); - /// - public Task> CatPendingTasksAsync(ICatPendingTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatPendingTasksDispatchAsync>); + /// + public Task> CatPendingTasksAsync(ICatPendingTasksRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatPendingTasksDispatchAsync>); } } diff --git a/src/Nest/Cat/CatPlugins/CatPluginsRecord.cs b/src/Nest/Cat/CatPlugins/CatPluginsRecord.cs index d0b245315ac..2f62769676f 100644 --- a/src/Nest/Cat/CatPlugins/CatPluginsRecord.cs +++ b/src/Nest/Cat/CatPlugins/CatPluginsRecord.cs @@ -5,28 +5,28 @@ namespace Nest [JsonObject] public class CatPluginsRecord : ICatRecord { - [JsonProperty("id")] - public string Id { get; set; } - - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("component")] public string Component { get; set; } - [JsonProperty("version")] - public string Version { get; set; } + [JsonProperty("description")] + public string Description { get; set; } - [JsonProperty("type")] - public string Type { get; set; } + [JsonProperty("id")] + public string Id { get; set; } [JsonProperty("isolation")] public string Isolation { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } + [JsonProperty("url")] public string Url { get; set; } - [JsonProperty("description")] - public string Description { get; set; } + [JsonProperty("version")] + public string Version { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatPlugins/ElasticClient-CatPlugins.cs b/src/Nest/Cat/CatPlugins/ElasticClient-CatPlugins.cs index 4a61325bd09..1c8e1d00d15 100644 --- a/src/Nest/Cat/CatPlugins/ElasticClient-CatPlugins.cs +++ b/src/Nest/Cat/CatPlugins/ElasticClient-CatPlugins.cs @@ -1,43 +1,49 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatPlugins(Func selector = null); - /// + /// ICatResponse CatPlugins(ICatPluginsRequest request); - /// - Task> CatPluginsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); - - /// - Task> CatPluginsAsync(ICatPluginsRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatPluginsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); + /// + Task> CatPluginsAsync(ICatPluginsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatPlugins(Func selector = null) => - this.CatPlugins(selector.InvokeOrDefault(new CatPluginsDescriptor())); + CatPlugins(selector.InvokeOrDefault(new CatPluginsDescriptor())); - /// + /// public ICatResponse CatPlugins(ICatPluginsRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatPluginsDispatch>); + DoCat(request, + LowLevelDispatch.CatPluginsDispatch>); - /// + /// public Task> CatPluginsAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatPluginsAsync(selector.InvokeOrDefault(new CatPluginsDescriptor()), cancellationToken); - - public Task> CatPluginsAsync(ICatPluginsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatPluginsDispatchAsync>); + ) => CatPluginsAsync(selector.InvokeOrDefault(new CatPluginsDescriptor()), cancellationToken); + public Task> CatPluginsAsync(ICatPluginsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatPluginsDispatchAsync>); } } diff --git a/src/Nest/Cat/CatRecovery/CatRecoveryRecord.cs b/src/Nest/Cat/CatRecovery/CatRecoveryRecord.cs index 5d138e69a65..627e128490e 100644 --- a/src/Nest/Cat/CatRecovery/CatRecoveryRecord.cs +++ b/src/Nest/Cat/CatRecovery/CatRecoveryRecord.cs @@ -5,62 +5,59 @@ namespace Nest [JsonObject] public class CatRecoveryRecord : ICatRecord { - [JsonProperty("index")] - public string Index { get; set; } + [JsonProperty("bytes")] + public string Bytes { get; set; } - [JsonProperty("shard")] - public string Shard { get; set; } + [JsonProperty("bytes_percent")] + public string BytesPercent { get; set; } - [JsonProperty("time")] - public string Time { get; set; } + [JsonProperty("bytes_recovered")] + public string BytesRecovered { get; set; } - [JsonProperty("type")] - public string Type { get; set; } + [JsonProperty("bytes_total")] + public string BytesTotal { get; set; } - [JsonProperty("stage")] - public string Stage { get; set; } + [JsonProperty("files")] + public string Files { get; set; } - [JsonProperty("source_host")] - public string SourceHost { get; set; } + [JsonProperty("files_percent")] + public string FilesPercent { get; set; } - [JsonProperty("source_node")] - public string SourceNode { get; set; } + [JsonProperty("files_recovered")] + public string FilesRecovered { get; set; } - [JsonProperty("target_host")] - public string TargetHost { get; set; } + [JsonProperty("files_total")] + public string FilesTotal { get; set; } - [JsonProperty("target_node")] - public string TargetNode { get; set; } + [JsonProperty("index")] + public string Index { get; set; } [JsonProperty("repository")] public string Repository { get; set; } + [JsonProperty("shard")] + public string Shard { get; set; } + [JsonProperty("snapshot")] public string Snapshot { get; set; } - [JsonProperty("files")] - public string Files { get; set; } - - [JsonProperty("files_recovered")] - public string FilesRecovered { get; set; } - - [JsonProperty("files_percent")] - public string FilesPercent { get; set; } + [JsonProperty("source_host")] + public string SourceHost { get; set; } - [JsonProperty("files_total")] - public string FilesTotal { get; set; } + [JsonProperty("source_node")] + public string SourceNode { get; set; } - [JsonProperty("bytes")] - public string Bytes { get; set; } + [JsonProperty("stage")] + public string Stage { get; set; } - [JsonProperty("bytes_recovered")] - public string BytesRecovered { get; set; } + [JsonProperty("target_host")] + public string TargetHost { get; set; } - [JsonProperty("bytes_percent")] - public string BytesPercent { get; set; } + [JsonProperty("target_node")] + public string TargetNode { get; set; } - [JsonProperty("bytes_total")] - public string BytesTotal { get; set; } + [JsonProperty("time")] + public string Time { get; set; } [JsonProperty("translog_ops")] public long? TranslogOps { get; set; } @@ -70,5 +67,8 @@ public class CatRecoveryRecord : ICatRecord [JsonProperty("translog_ops_recovered")] public long? TranslogOpsRecovered { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } } } diff --git a/src/Nest/Cat/CatRecovery/ElasticClient-CatRecovery.cs b/src/Nest/Cat/CatRecovery/ElasticClient-CatRecovery.cs index a168532f45e..b18e1fd0438 100644 --- a/src/Nest/Cat/CatRecovery/ElasticClient-CatRecovery.cs +++ b/src/Nest/Cat/CatRecovery/ElasticClient-CatRecovery.cs @@ -1,47 +1,53 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatRecovery(Func selector = null); - /// + /// ICatResponse CatRecovery(ICatRecoveryRequest request); - /// + /// Task> CatRecoveryAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatRecoveryAsync(ICatRecoveryRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatRecoveryAsync(ICatRecoveryRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatRecovery(Func selector = null) => - this.CatRecovery(selector.InvokeOrDefault(new CatRecoveryDescriptor())); + CatRecovery(selector.InvokeOrDefault(new CatRecoveryDescriptor())); - /// + /// public ICatResponse CatRecovery(ICatRecoveryRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatRecoveryDispatch>); + DoCat(request, + LowLevelDispatch.CatRecoveryDispatch>); - /// + /// public Task> CatRecoveryAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatRecoveryAsync(selector.InvokeOrDefault(new CatRecoveryDescriptor()), cancellationToken); + ) => CatRecoveryAsync(selector.InvokeOrDefault(new CatRecoveryDescriptor()), cancellationToken); - /// - public Task> CatRecoveryAsync(ICatRecoveryRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatRecoveryDispatchAsync>); + /// + public Task> CatRecoveryAsync(ICatRecoveryRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatRecoveryDispatchAsync>); } } diff --git a/src/Nest/Cat/CatRepositories/ElasticClient-CatRepositories.cs b/src/Nest/Cat/CatRepositories/ElasticClient-CatRepositories.cs index e2995346e15..51fe56a8605 100644 --- a/src/Nest/Cat/CatRepositories/ElasticClient-CatRepositories.cs +++ b/src/Nest/Cat/CatRepositories/ElasticClient-CatRepositories.cs @@ -1,48 +1,52 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatRepositories(Func selector = null); - /// + /// ICatResponse CatRepositories(ICatRepositoriesRequest request); - /// + /// Task> CatRepositoriesAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatRepositoriesAsync(ICatRepositoriesRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatRepositoriesAsync(ICatRepositoriesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatRepositories(Func selector = null) => - this.CatRepositories(selector.InvokeOrDefault(new CatRepositoriesDescriptor())); + CatRepositories(selector.InvokeOrDefault(new CatRepositoriesDescriptor())); - /// + /// public ICatResponse CatRepositories(ICatRepositoriesRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatRepositoriesDispatch>); + DoCat(request, + LowLevelDispatch.CatRepositoriesDispatch>); - /// + /// public Task> CatRepositoriesAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatRepositoriesAsync(selector.InvokeOrDefault(new CatRepositoriesDescriptor()), cancellationToken); - - /// - public Task> CatRepositoriesAsync(ICatRepositoriesRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatRepositoriesDispatchAsync>); + ) => CatRepositoriesAsync(selector.InvokeOrDefault(new CatRepositoriesDescriptor()), cancellationToken); + /// + public Task> CatRepositoriesAsync(ICatRepositoriesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatRepositoriesDispatchAsync>); } } diff --git a/src/Nest/Cat/CatResponse.cs b/src/Nest/Cat/CatResponse.cs index dbbda524a89..195bf8c1293 100644 --- a/src/Nest/Cat/CatResponse.cs +++ b/src/Nest/Cat/CatResponse.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using Newtonsoft.Json; namespace Nest diff --git a/src/Nest/Cat/CatSegments/CatSegmentsRecord.cs b/src/Nest/Cat/CatSegments/CatSegmentsRecord.cs index 1fd09d04e2a..c1c0bbb0451 100644 --- a/src/Nest/Cat/CatSegments/CatSegmentsRecord.cs +++ b/src/Nest/Cat/CatSegments/CatSegmentsRecord.cs @@ -5,32 +5,41 @@ namespace Nest [JsonObject] public class CatSegmentsRecord : ICatRecord { + [JsonProperty("committed")] + public string Committed { get; set; } + + [JsonProperty("compound")] + public string Compound { get; set; } + + [JsonProperty("docs.count")] + public string DocsCount { get; set; } + + [JsonProperty("docs.deleted")] + public string DocsDeleted { get; set; } + + [JsonProperty("generation")] + public string Generation { get; set; } + + [JsonProperty("id")] + public string Id { get; set; } + [JsonProperty("index")] public string Index { get; set; } - [JsonProperty("shard")] - public string Shard { get; set; } - - [JsonProperty("prirep")] - public string PrimaryReplica { get; set; } - [JsonProperty("ip")] public string Ip { get; set; } - [JsonProperty("id")] - public string Id { get; set; } + [JsonProperty("prirep")] + public string PrimaryReplica { get; set; } + + [JsonProperty("searchable")] + public string Searchable { get; set; } [JsonProperty("segment")] public string Segment { get; set; } - [JsonProperty("generation")] - public string Generation { get; set; } - - [JsonProperty("docs.count")] - public string DocsCount { get; set; } - - [JsonProperty("docs.deleted")] - public string DocsDeleted { get; set; } + [JsonProperty("shard")] + public string Shard { get; set; } [JsonProperty("size")] public string Size { get; set; } @@ -38,16 +47,7 @@ public class CatSegmentsRecord : ICatRecord [JsonProperty("size.memory")] public string SizeMemory { get; set; } - [JsonProperty("committed")] - public string Committed { get; set; } - - [JsonProperty("searchable")] - public string Searchable { get; set; } - [JsonProperty("version")] public string Version { get; set; } - - [JsonProperty("compound")] - public string Compound { get; set; } } } diff --git a/src/Nest/Cat/CatSegments/ElasticClient-CatSegments.cs b/src/Nest/Cat/CatSegments/ElasticClient-CatSegments.cs index 4f4d9088c20..01b392b51a5 100644 --- a/src/Nest/Cat/CatSegments/ElasticClient-CatSegments.cs +++ b/src/Nest/Cat/CatSegments/ElasticClient-CatSegments.cs @@ -1,48 +1,52 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatSegments(Func selector = null); - /// + /// ICatResponse CatSegments(ICatSegmentsRequest request); - /// + /// Task> CatSegmentsAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatSegmentsAsync(ICatSegmentsRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatSegmentsAsync(ICatSegmentsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatSegments(Func selector = null) => - this.CatSegments(selector.InvokeOrDefault(new CatSegmentsDescriptor())); + CatSegments(selector.InvokeOrDefault(new CatSegmentsDescriptor())); - /// + /// public ICatResponse CatSegments(ICatSegmentsRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatSegmentsDispatch>); + DoCat(request, + LowLevelDispatch.CatSegmentsDispatch>); - /// + /// public Task> CatSegmentsAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatSegmentsAsync(selector.InvokeOrDefault(new CatSegmentsDescriptor()), cancellationToken); - - /// - public Task> CatSegmentsAsync(ICatSegmentsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatSegmentsDispatchAsync>); + ) => CatSegmentsAsync(selector.InvokeOrDefault(new CatSegmentsDescriptor()), cancellationToken); + /// + public Task> CatSegmentsAsync(ICatSegmentsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatSegmentsDispatchAsync>); } } diff --git a/src/Nest/Cat/CatShards/CatShardsRecord.cs b/src/Nest/Cat/CatShards/CatShardsRecord.cs index ae6b2862264..404a157d113 100644 --- a/src/Nest/Cat/CatShards/CatShardsRecord.cs +++ b/src/Nest/Cat/CatShards/CatShardsRecord.cs @@ -5,45 +5,21 @@ namespace Nest [JsonObject] public class CatShardsRecord : ICatRecord { - [JsonProperty("index")] - public string Index { get; set; } - - [JsonProperty("shard")] - public string Shard { get; set; } - - [JsonProperty("prirep")] - public string PrimaryOrReplica { get; set; } - - [JsonProperty("state")] - public string State { get; set; } + [JsonProperty("completion.size")] + public string CompletionSize { get; set; } [JsonProperty("docs")] public string Docs { get; set; } - [JsonProperty("store")] - public string Store { get; set; } - - [JsonProperty("ip")] - public string Ip { get; set; } - - [JsonProperty("id")] - public string Id { get; set; } - - [JsonProperty("node")] - public string Node { get; set; } - - [JsonProperty("completion.size")] - public string CompletionSize { get; set; } + [JsonProperty("fielddata.evictions")] + public string FielddataEvictions { get; set; } [JsonProperty("fielddata.memory_size")] public string FielddataMemorySize { get; set; } - [JsonProperty("fielddata.evictions")] - public string FielddataEvictions { get; set; } - [JsonProperty("filter_cache.memory_size")] public string FilterCacheMemorySize { get; set; } - + [JsonProperty("flush.total")] public string FlushTotal { get; set; } @@ -53,12 +29,6 @@ public class CatShardsRecord : ICatRecord [JsonProperty("get.current")] public string GetCurrent { get; set; } - [JsonProperty("get.time")] - public string GetTime { get; set; } - - [JsonProperty("get.total")] - public string GetTotal { get; set; } - [JsonProperty("get.exists_time")] public string GetExistsTime { get; set; } @@ -71,9 +41,21 @@ public class CatShardsRecord : ICatRecord [JsonProperty("get.missing_total")] public string GetMissingTotal { get; set; } + [JsonProperty("get.time")] + public string GetTime { get; set; } + + [JsonProperty("get.total")] + public string GetTotal { get; set; } + + [JsonProperty("id")] + public string Id { get; set; } + [JsonProperty("id_cache.memory_size")] public string IdCacheMemorySize { get; set; } + [JsonProperty("index")] + public string Index { get; set; } + [JsonProperty("indexing.delete_current")] public string IndexingDeleteCurrent { get; set; } @@ -92,6 +74,9 @@ public class CatShardsRecord : ICatRecord [JsonProperty("indexing.index_total")] public string IndexingIndexTotal { get; set; } + [JsonProperty("ip")] + public string Ip { get; set; } + [JsonProperty("merges.current")] public string MergesCurrent { get; set; } @@ -100,83 +85,98 @@ public class CatShardsRecord : ICatRecord [JsonProperty("merges.current_size")] public string MergesCurrentSize { get; set; } - + [JsonProperty("merges.total_docs")] public string MergesTotalDocs { get; set; } - + [JsonProperty("merges.total_size")] public string MergesTotalSize { get; set; } - + [JsonProperty("merges.total_time")] public string MergesTotalTime { get; set; } - + + [JsonProperty("node")] + public string Node { get; set; } + [JsonProperty("percolate.current")] public string PercolateCurrent { get; set; } - + [JsonProperty("percolate.memory_size")] public string PercolateMemorySize { get; set; } - + [JsonProperty("percolate.queries")] public string PercolateQueries { get; set; } - + [JsonProperty("percolate.time")] public string PercolateTime { get; set; } - + [JsonProperty("percolate.total")] public string PercolateTotal { get; set; } - - [JsonProperty("refresh.total")] - public string RefreshTotal { get; set; } - + + [JsonProperty("prirep")] + public string PrimaryOrReplica { get; set; } + [JsonProperty("refresh.time")] public string RefreshTime { get; set; } - + + [JsonProperty("refresh.total")] + public string RefreshTotal { get; set; } + [JsonProperty("search.fetch_current")] public string SearchFetchCurrent { get; set; } - + [JsonProperty("search.fetch_time")] public string SearchFetchTime { get; set; } - + [JsonProperty("search.fetch_total")] public string SearchFetchTotal { get; set; } - + [JsonProperty("search.open_contexts")] public string SearchOpenContexts { get; set; } - + [JsonProperty("search.query_current")] public string SearchQueryCurrent { get; set; } - + [JsonProperty("search.query_time")] public string SearchQueryTime { get; set; } - + [JsonProperty("search.query_total")] public string SearchQueryTotal { get; set; } - + [JsonProperty("segments.count")] public string SegmentsCount { get; set; } - - [JsonProperty("segments.memory")] - public string SegmentsMemory { get; set; } - - [JsonProperty("segments.index_writer_memory")] - public string SegmentsIndexWriterMemory { get; set; } - + + [JsonProperty("segments.fixed_bitset_memory")] + public string SegmentsFixedBitsetMemory { get; set; } + [JsonProperty("segments.index_writer_max_memory")] public string SegmentsIndexWriterMaxMemory { get; set; } - + + [JsonProperty("segments.index_writer_memory")] + public string SegmentsIndexWriterMemory { get; set; } + + [JsonProperty("segments.memory")] + public string SegmentsMemory { get; set; } + [JsonProperty("segments.version_map_memory")] public string SegmentsVersionMapMemory { get; set; } - - [JsonProperty("segments.fixed_bitset_memory")] - public string SegmentsFixedBitsetMemory { get; set; } - + + [JsonProperty("shard")] + public string Shard { get; set; } + + [JsonProperty("state")] + public string State { get; set; } + + [JsonProperty("store")] + public string Store { get; set; } + [JsonProperty("warmer.current")] public string WarmerCurrent { get; set; } - + [JsonProperty("warmer.total")] public string WarmerTotal { get; set; } - + [JsonProperty("warmer.total_time")] public string WarmerTotalTime { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cat/CatShards/CatShardsRequest.cs b/src/Nest/Cat/CatShards/CatShardsRequest.cs index 9e1ac58ac4d..6de13678b04 100644 --- a/src/Nest/Cat/CatShards/CatShardsRequest.cs +++ b/src/Nest/Cat/CatShards/CatShardsRequest.cs @@ -1,7 +1,7 @@ namespace Nest { public partial interface ICatShardsRequest { } - + public partial class CatShardsRequest { } public partial class CatShardsDescriptor { } diff --git a/src/Nest/Cat/CatShards/ElasticClient-CatShards.cs b/src/Nest/Cat/CatShards/ElasticClient-CatShards.cs index c60224da132..485ecd6e6e9 100644 --- a/src/Nest/Cat/CatShards/ElasticClient-CatShards.cs +++ b/src/Nest/Cat/CatShards/ElasticClient-CatShards.cs @@ -1,41 +1,49 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatShards(Func selector = null); - /// + /// ICatResponse CatShards(ICatShardsRequest request); - /// - Task> CatShardsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatShardsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// - Task> CatShardsAsync(ICatShardsRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatShardsAsync(ICatShardsRequest request, CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatShards(Func selector = null) => - this.CatShards(selector.InvokeOrDefault(new CatShardsDescriptor())); + CatShards(selector.InvokeOrDefault(new CatShardsDescriptor())); - /// + /// public ICatResponse CatShards(ICatShardsRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatShardsDispatch>); - - /// - public Task> CatShardsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.CatShardsAsync(selector.InvokeOrDefault(new CatShardsDescriptor()), cancellationToken); - - public Task> CatShardsAsync(ICatShardsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatShardsDispatchAsync>); - + DoCat(request, + LowLevelDispatch.CatShardsDispatch>); + + /// + public Task> CatShardsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + CatShardsAsync(selector.InvokeOrDefault(new CatShardsDescriptor()), cancellationToken); + + public Task> CatShardsAsync(ICatShardsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatShardsDispatchAsync>); } } diff --git a/src/Nest/Cat/CatSnapshots/CatSnapshotsRecord.cs b/src/Nest/Cat/CatSnapshots/CatSnapshotsRecord.cs index 38ab9ea16b9..b2ef9fb82fe 100644 --- a/src/Nest/Cat/CatSnapshots/CatSnapshotsRecord.cs +++ b/src/Nest/Cat/CatSnapshots/CatSnapshotsRecord.cs @@ -5,12 +5,24 @@ namespace Nest [JsonObject] public class CatSnapshotsRecord : ICatRecord { + [JsonProperty("duration")] + public Time Duration { get; set; } + + [JsonProperty("end_epoch")] + public long EndEpoch { get; set; } + + [JsonProperty("end_time")] + public string EndTime { get; set; } + + [JsonProperty("failed_shards")] + public long FailedShards { get; set; } + // duration indices successful_shards failed_shards total_shards [JsonProperty("id")] public string Id { get; set; } - [JsonProperty("status")] - public string Status { get; set; } + [JsonProperty("indices")] + public long Indices { get; set; } [JsonProperty("start_epoch")] public long StartEpoch { get; set; } @@ -18,26 +30,13 @@ public class CatSnapshotsRecord : ICatRecord [JsonProperty("start_time")] public string StartTime { get; set; } - [JsonProperty("end_epoch")] - public long EndEpoch { get; set; } - - [JsonProperty("end_time")] - public string EndTime { get; set; } - - [JsonProperty("duration")] - public Time Duration { get; set; } - - [JsonProperty("indices")] - public long Indices { get; set; } + [JsonProperty("status")] + public string Status { get; set; } [JsonProperty("succesful_shards")] public long SuccesfulShards { get; set; } - [JsonProperty("failed_shards")] - public long FailedShards { get; set; } - [JsonProperty("total_shards")] public long TotalShards { get; set; } - } } diff --git a/src/Nest/Cat/CatSnapshots/ElasticClient-CatSnapshots.cs b/src/Nest/Cat/CatSnapshots/ElasticClient-CatSnapshots.cs index d774744bc81..d3833fe7f6b 100644 --- a/src/Nest/Cat/CatSnapshots/ElasticClient-CatSnapshots.cs +++ b/src/Nest/Cat/CatSnapshots/ElasticClient-CatSnapshots.cs @@ -1,50 +1,55 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatSnapshots(Names repositories, Func selector = null); - /// + /// ICatResponse CatSnapshots(ICatSnapshotsRequest request); - /// + /// Task> CatSnapshotsAsync( Names repositories, Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatSnapshotsAsync(ICatSnapshotsRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatSnapshotsAsync(ICatSnapshotsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// - public ICatResponse CatSnapshots(Names repositories, Func selector = null) => - this.CatSnapshots(selector.InvokeOrDefault(new CatSnapshotsDescriptor().RepositoryName(repositories))); + /// + public ICatResponse + CatSnapshots(Names repositories, Func selector = null) => + CatSnapshots(selector.InvokeOrDefault(new CatSnapshotsDescriptor().RepositoryName(repositories))); - /// + /// public ICatResponse CatSnapshots(ICatSnapshotsRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatSnapshotsDispatch>); + DoCat(request, + LowLevelDispatch.CatSnapshotsDispatch>); - /// + /// public Task> CatSnapshotsAsync( Names repositories, Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatSnapshotsAsync(selector.InvokeOrDefault(new CatSnapshotsDescriptor().RepositoryName(repositories)), cancellationToken); - - /// - public Task> CatSnapshotsAsync(ICatSnapshotsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatSnapshotsDispatchAsync>); + ) => CatSnapshotsAsync(selector.InvokeOrDefault(new CatSnapshotsDescriptor().RepositoryName(repositories)), cancellationToken); + /// + public Task> CatSnapshotsAsync(ICatSnapshotsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatSnapshotsDispatchAsync>); } } diff --git a/src/Nest/Cat/CatTasks/CatTasksRequest.cs b/src/Nest/Cat/CatTasks/CatTasksRequest.cs index 5d349e0669a..2189178c1c0 100644 --- a/src/Nest/Cat/CatTasks/CatTasksRequest.cs +++ b/src/Nest/Cat/CatTasks/CatTasksRequest.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Nest +namespace Nest { public partial interface ICatTasksRequest { } diff --git a/src/Nest/Cat/CatTasks/ElasticClient-CatTasks.cs b/src/Nest/Cat/CatTasks/ElasticClient-CatTasks.cs index d7f9c82eac4..112dcd55643 100644 --- a/src/Nest/Cat/CatTasks/ElasticClient-CatTasks.cs +++ b/src/Nest/Cat/CatTasks/ElasticClient-CatTasks.cs @@ -1,53 +1,54 @@ using System; -using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatTasks(Func selector = null); - /// + /// ICatResponse CatTasks(ICatTasksRequest request); - /// + /// Task> CatTasksAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// + /// Task> CatTasksAsync(ICatTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public ICatResponse CatTasks(Func selector = null) => - this.CatTasks(selector.InvokeOrDefault(new CatTasksDescriptor())); + CatTasks(selector.InvokeOrDefault(new CatTasksDescriptor())); - /// + /// public ICatResponse CatTasks(ICatTasksRequest request) => - this.DoCat( + DoCat( request, - this.LowLevelDispatch.CatTasksDispatch>); + LowLevelDispatch.CatTasksDispatch>); - /// + /// public Task> CatTasksAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatTasksAsync(selector.InvokeOrDefault(new CatTasksDescriptor())); + ) => CatTasksAsync(selector.InvokeOrDefault(new CatTasksDescriptor())); - /// - public Task> CatTasksAsync(ICatTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync( + /// + public Task> CatTasksAsync(ICatTasksRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync( request, cancellationToken, - this.LowLevelDispatch.CatTasksDispatchAsync> + LowLevelDispatch.CatTasksDispatchAsync> ); } } diff --git a/src/Nest/Cat/CatTemplates/CatTemplatesRecord.cs b/src/Nest/Cat/CatTemplates/CatTemplatesRecord.cs index c8bfcbcc38d..09618ee4925 100644 --- a/src/Nest/Cat/CatTemplates/CatTemplatesRecord.cs +++ b/src/Nest/Cat/CatTemplates/CatTemplatesRecord.cs @@ -1,18 +1,16 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { [JsonObject] public class CatTemplatesRecord : ICatRecord { - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("index_patterns")] public string IndexPatterns { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("order")] public long Order { get; set; } diff --git a/src/Nest/Cat/CatTemplates/CatTemplatesRequest.cs b/src/Nest/Cat/CatTemplates/CatTemplatesRequest.cs index e9fcf6b00fc..3a86910d268 100644 --- a/src/Nest/Cat/CatTemplates/CatTemplatesRequest.cs +++ b/src/Nest/Cat/CatTemplates/CatTemplatesRequest.cs @@ -1,5 +1,4 @@ -using System; -#pragma warning disable 612, 618 +#pragma warning disable 612, 618 namespace Nest { diff --git a/src/Nest/Cat/CatTemplates/ElasticClient-CatTemplates.cs b/src/Nest/Cat/CatTemplates/ElasticClient-CatTemplates.cs index f391e8d1164..74ecfe2e3b3 100644 --- a/src/Nest/Cat/CatTemplates/ElasticClient-CatTemplates.cs +++ b/src/Nest/Cat/CatTemplates/ElasticClient-CatTemplates.cs @@ -1,48 +1,52 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatTemplates(Func selector = null); - /// + /// ICatResponse CatTemplates(ICatTemplatesRequest request); - /// + /// Task> CatTemplatesAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatTemplatesAsync(ICatTemplatesRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task> CatTemplatesAsync(ICatTemplatesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatTemplates(Func selector = null) => - this.CatTemplates(selector.InvokeOrDefault(new CatTemplatesDescriptor())); + CatTemplates(selector.InvokeOrDefault(new CatTemplatesDescriptor())); - /// + /// public ICatResponse CatTemplates(ICatTemplatesRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatTemplatesDispatch>); + DoCat(request, + LowLevelDispatch.CatTemplatesDispatch>); - /// + /// public Task> CatTemplatesAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatTemplatesAsync(selector.InvokeOrDefault(new CatTemplatesDescriptor()), cancellationToken); - - /// - public Task> CatTemplatesAsync(ICatTemplatesRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatTemplatesDispatchAsync>); + ) => CatTemplatesAsync(selector.InvokeOrDefault(new CatTemplatesDescriptor()), cancellationToken); + /// + public Task> CatTemplatesAsync(ICatTemplatesRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatTemplatesDispatchAsync>); } } diff --git a/src/Nest/Cat/CatThreadPool/CatThreadPoolRecord.cs b/src/Nest/Cat/CatThreadPool/CatThreadPoolRecord.cs index 881ebc68187..99bf750ad34 100644 --- a/src/Nest/Cat/CatThreadPool/CatThreadPoolRecord.cs +++ b/src/Nest/Cat/CatThreadPool/CatThreadPoolRecord.cs @@ -5,44 +5,61 @@ namespace Nest [JsonObject] public class CatThreadPoolRecord : ICatRecord { - [JsonProperty("node_name")] - public string NodeName { get; set; } - [JsonProperty("node_id")] - public string NodeId { get; set; } + [JsonProperty("active")] + public int Active { get; set; } + + [JsonProperty("completed")] + public long Completed { get; set; } + [JsonProperty("ephemeral_node_id")] public string EphemeralNodeId { get; set; } - [JsonProperty("pid")] - public int ProcessId { get; set; } + [JsonProperty("host")] public string Host { get; set; } + [JsonProperty("ip")] public string Ip { get; set; } - [JsonProperty("port")] - public int Port { get; set; } + + [JsonProperty("keep_alive")] + public Time KeepAlive { get; set; } + + [JsonProperty("largest")] + public int Largest { get; set; } + + [JsonProperty("max")] + public int Maximum { get; set; } + + [JsonProperty("min")] + public int Minimum { get; set; } + [JsonProperty("name")] public string Name { get; set; } - [JsonProperty("type")] - public string Type { get; set; } - [JsonProperty("active")] - public int Active { get; set; } - [JsonProperty("size")] - public int Size { get; set; } + + [JsonProperty("node_id")] + public string NodeId { get; set; } + + [JsonProperty("node_name")] + public string NodeName { get; set; } + + [JsonProperty("port")] + public int Port { get; set; } + + [JsonProperty("pid")] + public int ProcessId { get; set; } + [JsonProperty("queue")] public int Queue { get; set; } + [JsonProperty("queue_size")] public int? QueueSize { get; set; } + [JsonProperty("rejected")] public long Rejected { get; set; } - [JsonProperty("largest")] - public int Largest { get; set; } - [JsonProperty("completed")] - public long Completed { get; set; } - [JsonProperty("min")] - public int Minimum { get; set; } - [JsonProperty("max")] - public int Maximum { get; set; } - [JsonProperty("keep_alive")] - public Time KeepAlive { get; set; } + [JsonProperty("size")] + public int Size { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } } } diff --git a/src/Nest/Cat/CatThreadPool/ElasticClient-CatThreadpool.cs b/src/Nest/Cat/CatThreadPool/ElasticClient-CatThreadpool.cs index f97647e654c..ccd79cfb44b 100644 --- a/src/Nest/Cat/CatThreadPool/ElasticClient-CatThreadpool.cs +++ b/src/Nest/Cat/CatThreadPool/ElasticClient-CatThreadpool.cs @@ -1,46 +1,52 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial interface IElasticClient { - /// + /// ICatResponse CatThreadPool(Func selector = null); - /// + /// ICatResponse CatThreadPool(ICatThreadPoolRequest request); - /// + /// Task> CatThreadPoolAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) ); - /// - Task> CatThreadPoolAsync(ICatThreadPoolRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task> CatThreadPoolAsync(ICatThreadPoolRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public ICatResponse CatThreadPool(Func selector = null) => - this.CatThreadPool(selector.InvokeOrDefault(new CatThreadPoolDescriptor())); + CatThreadPool(selector.InvokeOrDefault(new CatThreadPoolDescriptor())); - /// + /// public ICatResponse CatThreadPool(ICatThreadPoolRequest request) => - this.DoCat(request, this.LowLevelDispatch.CatThreadPoolDispatch>); + DoCat(request, + LowLevelDispatch.CatThreadPoolDispatch>); - /// + /// public Task> CatThreadPoolAsync( Func selector = null, CancellationToken cancellationToken = default(CancellationToken) - ) => this.CatThreadPoolAsync(selector.InvokeOrDefault(new CatThreadPoolDescriptor()), cancellationToken); + ) => CatThreadPoolAsync(selector.InvokeOrDefault(new CatThreadPoolDescriptor()), cancellationToken); - /// - public Task> CatThreadPoolAsync(ICatThreadPoolRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.DoCatAsync(request, cancellationToken, this.LowLevelDispatch.CatThreadPoolDispatchAsync>); + /// + public Task> CatThreadPoolAsync(ICatThreadPoolRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + DoCatAsync(request, cancellationToken, + LowLevelDispatch.CatThreadPoolDispatchAsync>); } } diff --git a/src/Nest/Cat/ElasticClient-Cat.cs b/src/Nest/Cat/ElasticClient-Cat.cs index fb22341d278..ed85a19c756 100644 --- a/src/Nest/Cat/ElasticClient-Cat.cs +++ b/src/Nest/Cat/ElasticClient-Cat.cs @@ -1,15 +1,14 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { public partial class ElasticClient { - private CatResponse DeserializeCatResponse(IApiCallDetails response, Stream stream) where TCatRecord : ICatRecord { @@ -17,7 +16,7 @@ private CatResponse DeserializeCatResponse(IApiCallDetai if (!response.Success) return catResponse; - var records = this.RequestResponseSerializer.Deserialize>(stream); + var records = RequestResponseSerializer.Deserialize>(stream); catResponse.Records = records; return catResponse; @@ -26,16 +25,17 @@ private CatResponse DeserializeCatResponse(IApiCallDetai private ICatResponse DoCat( TRequest request, Func, CatResponse> dispatch - ) + ) where TCatRecord : ICatRecord where TParams : RequestParameters, new() where TRequest : IRequest => - this.Dispatcher.Dispatch>( - ForceConfiguration(request, c => { + Dispatcher.Dispatch>( + ForceConfiguration(request, c => + { c.Accept = RequestData.MimeType; c.ContentType = RequestData.MimeType; }), - new Func>(this.DeserializeCatResponse), + new Func>(DeserializeCatResponse), (p, d) => dispatch(p) ); @@ -43,20 +43,19 @@ private Task> DoCatAsync TRequest request, CancellationToken cancellationToken, Func, CancellationToken, Task>> dispatch - ) + ) where TCatRecord : ICatRecord where TParams : RequestParameters, new() where TRequest : IRequest => - this.Dispatcher.DispatchAsync, ICatResponse>( + Dispatcher.DispatchAsync, ICatResponse>( ForceConfiguration(request, c => { c.Accept = RequestData.MimeType; c.ContentType = RequestData.MimeType; }), cancellationToken, - new Func>(this.DeserializeCatResponse), + new Func>(DeserializeCatResponse), (p, d, c) => dispatch(p, c) ); - } } diff --git a/src/Nest/Cat/ICatRecord.cs b/src/Nest/Cat/ICatRecord.cs index 3dee65cc781..ea4cdea7606 100644 --- a/src/Nest/Cat/ICatRecord.cs +++ b/src/Nest/Cat/ICatRecord.cs @@ -1,4 +1,4 @@ namespace Nest { - public interface ICatRecord {} -} \ No newline at end of file + public interface ICatRecord { } +} diff --git a/src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainRequest.cs b/src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainRequest.cs index 3a343bca12e..453a497550c 100644 --- a/src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainRequest.cs +++ b/src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainRequest.cs @@ -11,17 +11,17 @@ public partial interface IClusterAllocationExplainRequest [JsonProperty("index")] IndexName Index { get; set; } - /// - /// The shard id to provide an explanation for - /// - [JsonProperty("shard")] - int? Shard { get; set; } - /// /// Whether to explain a primary or replica shard /// [JsonProperty("primary")] bool? Primary { get; set; } + + /// + /// The shard id to provide an explanation for + /// + [JsonProperty("shard")] + int? Shard { get; set; } } public partial class ClusterAllocationExplainRequest @@ -32,21 +32,21 @@ public partial class ClusterAllocationExplainRequest public IndexName Index { get; set; } /// - /// The shard id to provide an explanation for + /// Whether to explain a primary or replica shard /// - public int? Shard { get; set; } + public bool? Primary { get; set; } /// - /// Whether to explain a primary or replica shard + /// The shard id to provide an explanation for /// - public bool? Primary { get; set; } + public int? Shard { get; set; } } public partial class ClusterAllocationExplainDescriptor { IndexName IClusterAllocationExplainRequest.Index { get; set; } - int? IClusterAllocationExplainRequest.Shard { get; set; } bool? IClusterAllocationExplainRequest.Primary { get; set; } + int? IClusterAllocationExplainRequest.Shard { get; set; } /// /// The name of the index to provide an explanation for diff --git a/src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainResponse.cs b/src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainResponse.cs index a6bdd539283..e162e874b3b 100644 --- a/src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainResponse.cs +++ b/src/Nest/Cluster/ClusterAllocationExplain/ClusterAllocationExplainResponse.cs @@ -9,123 +9,123 @@ namespace Nest [JsonObject] public interface IClusterAllocationExplainResponse : IResponse { - [JsonProperty("index")] - string Index { get; } - - [JsonProperty("shard")] - int Shard { get; } - - [JsonProperty("primary")] - bool Primary { get; } + [JsonProperty("allocate_explanation")] + string AllocateExplanation { get; } - [JsonProperty("current_state")] - string CurrentState { get; } + [JsonProperty("allocation_delay")] + string AllocationDelay { get; } - [JsonProperty("unassigned_info")] - UnassignedInformation UnassignedInformation { get; } + [JsonProperty("allocation_delay_in_millis")] + long AllocationDelayInMilliseconds { get; } [JsonProperty("can_allocate")] Decision? CanAllocate { get; } - [JsonProperty("allocate_explanation")] - string AllocateExplanation { get; } - - [JsonProperty("configured_delay")] - string ConfiguredDelay { get; } + [JsonProperty("can_move_to_other_node")] + Decision? CanMoveToOtherNode { get; } - [JsonProperty("configured_delay_in_mills")] - long ConfiguredDelayInMilliseconds { get; } + [JsonProperty("can_rebalance_cluster")] + Decision? CanRebalanceCluster { get; } - [JsonProperty("current_node")] - CurrentNode CurrentNode { get; } + [JsonProperty("can_rebalance_cluster_decisions")] + IReadOnlyCollection CanRebalanceClusterDecisions { get; } - [JsonProperty("can_remain_on_current_node")] - Decision? CanRemainOnCurrentNode { get; } + [JsonProperty("can_rebalance_to_other_node")] + Decision? CanRebalanceToOtherNode { get; } [JsonProperty("can_remain_decisions")] IReadOnlyCollection CanRemainDecisions { get; } - [JsonProperty("can_rebalance_cluster")] - Decision? CanRebalanceCluster { get; } + [JsonProperty("can_remain_on_current_node")] + Decision? CanRemainOnCurrentNode { get; } - [JsonProperty("can_rebalance_to_other_node")] - Decision? CanRebalanceToOtherNode { get; } + [JsonProperty("configured_delay")] + string ConfiguredDelay { get; } - [JsonProperty("can_rebalance_cluster_decisions")] - IReadOnlyCollection CanRebalanceClusterDecisions { get; } + [JsonProperty("configured_delay_in_mills")] + long ConfiguredDelayInMilliseconds { get; } - [JsonProperty("rebalance_explanation")] - string RebalanceExplanation { get; } + [JsonProperty("current_node")] + CurrentNode CurrentNode { get; } - [JsonProperty("node_allocation_decisions")] - IReadOnlyCollection NodeAllocationDecisions { get; } + [JsonProperty("current_state")] + string CurrentState { get; } - [JsonProperty("can_move_to_other_node")] - Decision? CanMoveToOtherNode { get; } + [JsonProperty("index")] + string Index { get; } [JsonProperty("move_explanation")] string MoveExplanation { get; } - [JsonProperty("allocation_delay")] - string AllocationDelay { get; } + [JsonProperty("node_allocation_decisions")] + IReadOnlyCollection NodeAllocationDecisions { get; } - [JsonProperty("allocation_delay_in_millis")] - long AllocationDelayInMilliseconds { get; } + [JsonProperty("primary")] + bool Primary { get; } + + [JsonProperty("rebalance_explanation")] + string RebalanceExplanation { get; } [JsonProperty("remaining_delay")] string RemainingDelay { get; } [JsonProperty("remaining_delay_in_millis")] long RemainingDelayInMilliseconds { get; } + + [JsonProperty("shard")] + int Shard { get; } + + [JsonProperty("unassigned_info")] + UnassignedInformation UnassignedInformation { get; } } public class ClusterAllocationExplainResponse : ResponseBase, IClusterAllocationExplainResponse { - public string Index { get; internal set; } - - public int Shard { get; internal set; } - - public bool Primary { get; internal set; } + public string AllocateExplanation { get; internal set; } - public string CurrentState { get; internal set; } + public string AllocationDelay { get; internal set; } - public UnassignedInformation UnassignedInformation { get; internal set; } + public long AllocationDelayInMilliseconds { get; internal set; } public Decision? CanAllocate { get; internal set; } - public string AllocateExplanation { get; internal set; } - - public string ConfiguredDelay { get; internal set; } + public Decision? CanMoveToOtherNode { get; internal set; } - public long ConfiguredDelayInMilliseconds { get; internal set; } + public Decision? CanRebalanceCluster { get; internal set; } - public CurrentNode CurrentNode { get; internal set; } + public IReadOnlyCollection CanRebalanceClusterDecisions { get; internal set; } = + EmptyReadOnly.Collection; - public Decision? CanRemainOnCurrentNode { get; internal set; } + public Decision? CanRebalanceToOtherNode { get; internal set; } public IReadOnlyCollection CanRemainDecisions { get; internal set; } - public Decision? CanRebalanceCluster { get; internal set; } - - public Decision? CanRebalanceToOtherNode { get; internal set; } + public Decision? CanRemainOnCurrentNode { get; internal set; } - public IReadOnlyCollection CanRebalanceClusterDecisions { get; internal set; } = EmptyReadOnly.Collection; + public string ConfiguredDelay { get; internal set; } - public string RebalanceExplanation { get; internal set; } + public long ConfiguredDelayInMilliseconds { get; internal set; } - public IReadOnlyCollection NodeAllocationDecisions { get; internal set; } + public CurrentNode CurrentNode { get; internal set; } - public Decision? CanMoveToOtherNode { get; internal set; } + public string CurrentState { get; internal set; } + public string Index { get; internal set; } public string MoveExplanation { get; internal set; } - public string AllocationDelay { get; internal set; } + public IReadOnlyCollection NodeAllocationDecisions { get; internal set; } - public long AllocationDelayInMilliseconds { get; internal set; } + public bool Primary { get; internal set; } + + public string RebalanceExplanation { get; internal set; } public string RemainingDelay { get; internal set; } public long RemainingDelayInMilliseconds { get; internal set; } + + public int Shard { get; internal set; } + + public UnassignedInformation UnassignedInformation { get; internal set; } } [JsonObject] @@ -137,14 +137,14 @@ public class CurrentNode [JsonProperty("name")] public string Name { get; internal set; } + [JsonProperty("attributes")] + public IReadOnlyDictionary NodeAttributes { get; set; } = EmptyReadOnly.Dictionary; + [JsonProperty("transport_address")] public string TransportAddress { get; internal set; } [JsonProperty("weight_ranking")] public string WeightRanking { get; internal set; } - - [JsonProperty("attributes")] - public IReadOnlyDictionary NodeAttributes { get; set; } = EmptyReadOnly.Dictionary; } [JsonConverter(typeof(StringEnumConverter))] @@ -166,29 +166,29 @@ public enum AllocationExplainDecision [JsonObject] public class NodeAllocationExplanation { - [JsonProperty("node_id")] - public string NodeId { get; set; } - - [JsonProperty("node_name")] - public string NodeName { get; set; } + [JsonProperty("deciders")] + public IReadOnlyCollection Deciders { get; set; } = EmptyReadOnly.Collection; - [JsonProperty("transport_address")] - public string TransportAddress { get; set; } + [JsonProperty("node_attributes")] + public IReadOnlyDictionary NodeAttributes { get; set; } = EmptyReadOnly.Dictionary; [JsonProperty("node_decision")] public Decision? NodeDecision { get; set; } - [JsonProperty("node_attributes")] - public IReadOnlyDictionary NodeAttributes { get; set; } = EmptyReadOnly.Dictionary; + [JsonProperty("node_id")] + public string NodeId { get; set; } + + [JsonProperty("node_name")] + public string NodeName { get; set; } [JsonProperty("store")] public AllocationStore Store { get; set; } + [JsonProperty("transport_address")] + public string TransportAddress { get; set; } + [JsonProperty("weight_ranking")] public int? WeightRanking { get; set; } - - [JsonProperty("deciders")] - public IReadOnlyCollection Deciders { get; set; } = EmptyReadOnly.Collection; } [JsonConverter(typeof(StringEnumConverter))] @@ -244,21 +244,21 @@ public enum StoreCopy [JsonObject] public class AllocationStore { + [JsonProperty("allocation_id")] + public string AllocationId { get; set; } + [JsonProperty("found")] public bool? Found { get; set; } [JsonProperty("in_sync")] public bool? InSync { get; set; } - [JsonProperty("allocation_id")] - public string AllocationId { get; set; } + [JsonProperty("matching_size_in_bytes")] + public long? MatchingSizeInBytes { get; set; } [JsonProperty("matching_sync_id")] public bool? MatchingSyncId { get; set; } - [JsonProperty("matching_size_in_bytes")] - public long? MatchingSizeInBytes { get; set; } - [JsonProperty("store_exception")] public string StoreException { get; set; } } @@ -278,27 +278,27 @@ public class AllocationDecision public class UnassignedInformation { - [JsonProperty("reason")] - public UnassignedInformationReason Reason { get; set; } - [JsonProperty("at")] public DateTime At { get; set; } [JsonProperty("last_allocation_status")] public string LastAllocationStatus { get; set; } + + [JsonProperty("reason")] + public UnassignedInformationReason Reason { get; set; } } public class ShardAllocationExplanation { + [JsonProperty("id")] + public int Id { get; set; } + [JsonProperty("index")] public IndexName Index { get; set; } [JsonProperty("index_uuid")] public string IndexUniqueId { get; set; } - [JsonProperty("id")] - public int Id { get; set; } - [JsonProperty("primary")] public bool Primary { get; set; } } @@ -306,93 +306,93 @@ public class ShardAllocationExplanation [JsonConverter(typeof(StringEnumConverter))] public enum UnassignedInformationReason { - /// - /// Unassigned as a result of an API creation of an index. - /// + /// + /// Unassigned as a result of an API creation of an index. + /// [EnumMember(Value = "INDEX_CREATED")] IndexCreated, - /// - /// Unassigned as a result of a full cluster recovery. - /// + /// + /// Unassigned as a result of a full cluster recovery. + /// [EnumMember(Value = "CLUSTER_RECOVERED")] ClusterRecovered, - /// - /// Unassigned as a result of opening a closed index. - /// + /// + /// Unassigned as a result of opening a closed index. + /// [EnumMember(Value = "INDEX_REOPENED")] IndexReopened, - /// - /// Unassigned as a result of importing a dangling index. - /// + /// + /// Unassigned as a result of importing a dangling index. + /// [EnumMember(Value = "DANGLING_INDEX_IMPORTED")] DanglingIndexImported, - /// - /// Unassigned as a result of restoring into a new index. - /// + /// + /// Unassigned as a result of restoring into a new index. + /// [EnumMember(Value = "NEW_INDEX_RESTORED")] NewIndexRestored, - /// - /// Unassigned as a result of restoring into a closed index. - /// + /// + /// Unassigned as a result of restoring into a closed index. + /// [EnumMember(Value = "EXISTING_INDEX_RESTORED")] ExistingIndexRestored, - /// - /// Unassigned as a result of explicit addition of a replica. - /// + /// + /// Unassigned as a result of explicit addition of a replica. + /// [EnumMember(Value = "REPLICA_ADDED")] ReplicaAdded, - /// - /// Unassigned as a result of a failed allocation of the shard. - /// + /// + /// Unassigned as a result of a failed allocation of the shard. + /// [EnumMember(Value = "ALLOCATION_FAILED")] AllocationFailed, - /// - /// Unassigned as a result of the node hosting it leaving the cluster. - /// + /// + /// Unassigned as a result of the node hosting it leaving the cluster. + /// [EnumMember(Value = "NODE_LEFT")] NodeLeft, - /// - /// Unassigned as a result of explicit cancel reroute command. - /// + /// + /// Unassigned as a result of explicit cancel reroute command. + /// [EnumMember(Value = "REROUTE_CANCELLED")] RerouteCancelled, - /// - /// When a shard moves from started back to initializing, for example, during shadow replica - /// + /// + /// When a shard moves from started back to initializing, for example, during shadow replica + /// [EnumMember(Value = "REINITIALIZED")] Reinitialized, - /// - /// A better replica location is identified and causes the existing replica allocation to be cancelled. - /// + /// + /// A better replica location is identified and causes the existing replica allocation to be cancelled. + /// [EnumMember(Value = "REALLOCATED_REPLICA")] ReallocatedReplica, - /// - /// Unassigned as a result of a failed primary while the replica was initializing. - /// + /// + /// Unassigned as a result of a failed primary while the replica was initializing. + /// [EnumMember(Value = "PRIMARY_FAILED")] PrimaryFailed, - /// - /// Unassigned after forcing an empty primary - /// + /// + /// Unassigned after forcing an empty primary + /// [EnumMember(Value = "FORCED_EMPTY_PRIMARY")] ForcedEmptyPrimary, - /// - /// Forced manually to allocate - /// + /// + /// Forced manually to allocate + /// [EnumMember(Value = "MANUAL_ALLOCATION")] ManualAllocation } diff --git a/src/Nest/Cluster/ClusterAllocationExplain/ElasticClient-ClusterAllocationExplain.cs b/src/Nest/Cluster/ClusterAllocationExplain/ElasticClient-ClusterAllocationExplain.cs index 9ee676ab92b..f39824a2b38 100644 --- a/src/Nest/Cluster/ClusterAllocationExplain/ElasticClient-ClusterAllocationExplain.cs +++ b/src/Nest/Cluster/ClusterAllocationExplain/ElasticClient-ClusterAllocationExplain.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -12,44 +9,61 @@ public partial interface IElasticClient { /// /// The cluster allocation explanation API is designed to assist in answering the question "why is this shard unassigned?" - /// https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html /// /// An optional descriptor to further describe the cluster allocation explain operation - IClusterAllocationExplainResponse ClusterAllocationExplain(Func selector = null); + IClusterAllocationExplainResponse ClusterAllocationExplain( + Func selector = null + ); - /// + /// IClusterAllocationExplainResponse ClusterAllocationExplain(IClusterAllocationExplainRequest request); - /// - Task ClusterAllocationExplainAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterAllocationExplainAsync( + Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// - Task ClusterAllocationExplainAsync(IClusterAllocationExplainRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterAllocationExplainAsync(IClusterAllocationExplainRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// - public IClusterAllocationExplainResponse ClusterAllocationExplain(Func selector = null) => - this.ClusterAllocationExplain(selector.InvokeOrDefault(new ClusterAllocationExplainDescriptor())); + /// + public IClusterAllocationExplainResponse ClusterAllocationExplain( + Func selector = null + ) => + ClusterAllocationExplain(selector.InvokeOrDefault(new ClusterAllocationExplainDescriptor())); - /// + /// public IClusterAllocationExplainResponse ClusterAllocationExplain(IClusterAllocationExplainRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.ClusterAllocationExplainDispatch(p, d) + (p, d) => LowLevelDispatch.ClusterAllocationExplainDispatch(p, d) ); - /// - public Task ClusterAllocationExplainAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.ClusterAllocationExplainAsync(selector.InvokeOrDefault(new ClusterAllocationExplainDescriptor()), cancellationToken); + /// + public Task ClusterAllocationExplainAsync( + Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ClusterAllocationExplainAsync(selector.InvokeOrDefault(new ClusterAllocationExplainDescriptor()), cancellationToken); - /// - public Task ClusterAllocationExplainAsync(IClusterAllocationExplainRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( - request, - cancellationToken, - (p, d, c) => this.LowLevelDispatch.ClusterAllocationExplainDispatchAsync(p, d, c) - ); + /// + public Task ClusterAllocationExplainAsync(IClusterAllocationExplainRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher + .DispatchAsync( + request, + cancellationToken, + (p, d, c) => LowLevelDispatch.ClusterAllocationExplainDispatchAsync(p, d, c) + ); } } diff --git a/src/Nest/Cluster/ClusterHealth.cs b/src/Nest/Cluster/ClusterHealth.cs index ea98a05e657..29dc6a28999 100644 --- a/src/Nest/Cluster/ClusterHealth.cs +++ b/src/Nest/Cluster/ClusterHealth.cs @@ -5,12 +5,14 @@ namespace Nest { [JsonConverter(typeof(StringEnumConverter))] - public enum ClusterStatus + public enum ClusterStatus { [EnumMember(Value = "green")] Green, + [EnumMember(Value = "yellow")] Yellow, + [EnumMember(Value = "red")] Red } diff --git a/src/Nest/Cluster/ClusterHealth/ClusterHealthResponse.cs b/src/Nest/Cluster/ClusterHealth/ClusterHealthResponse.cs index 28d9625b42f..3b936bbcc44 100644 --- a/src/Nest/Cluster/ClusterHealth/ClusterHealthResponse.cs +++ b/src/Nest/Cluster/ClusterHealth/ClusterHealthResponse.cs @@ -6,49 +6,59 @@ namespace Nest { public interface IClusterHealthResponse : IResponse { - string ClusterName { get; } - Health Status { get; } - bool TimedOut { get; } - int NumberOfNodes { get; } - int NumberOfDataNodes { get; } int ActivePrimaryShards { get; } int ActiveShards { get; } - int RelocatingShards { get; } + string ClusterName { get; } + IReadOnlyDictionary Indices { get; } int InitializingShards { get; } - int UnassignedShards { get; } + int NumberOfDataNodes { get; } + int NumberOfNodes { get; } int NumberOfPendingTasks { get; } - IReadOnlyDictionary Indices { get; } + int RelocatingShards { get; } + Health Status { get; } + bool TimedOut { get; } + int UnassignedShards { get; } } [JsonObject] public class ClusterHealthResponse : ResponseBase, IClusterHealthResponse { + [JsonProperty("active_primary_shards")] + public int ActivePrimaryShards { get; internal set; } + + [JsonProperty("active_shards")] + public int ActiveShards { get; internal set; } + [JsonProperty("cluster_name")] public string ClusterName { get; internal set; } - [JsonProperty("status")] - public Health Status { get; internal set; } - [JsonProperty("timed_out")] - public bool TimedOut { get; internal set; } - [JsonProperty("number_of_nodes")] - public int NumberOfNodes { get; internal set; } + [JsonProperty("indices")] + [JsonConverter(typeof(ResolvableDictionaryJsonConverter))] + public IReadOnlyDictionary Indices { get; internal set; } = + EmptyReadOnly.Dictionary; + + [JsonProperty("initializing_shards")] + public int InitializingShards { get; internal set; } + [JsonProperty("number_of_data_nodes")] public int NumberOfDataNodes { get; internal set; } - [JsonProperty("active_primary_shards")] - public int ActivePrimaryShards { get; internal set; } - [JsonProperty("active_shards")] - public int ActiveShards { get; internal set; } + [JsonProperty("number_of_nodes")] + public int NumberOfNodes { get; internal set; } + + [JsonProperty(PropertyName = "number_of_pending_tasks")] + public int NumberOfPendingTasks { get; internal set; } + [JsonProperty("relocating_shards")] public int RelocatingShards { get; internal set; } - [JsonProperty("initializing_shards")] - public int InitializingShards { get; internal set; } + + [JsonProperty("status")] + public Health Status { get; internal set; } + + [JsonProperty("timed_out")] + public bool TimedOut { get; internal set; } + [JsonProperty("unassigned_shards")] public int UnassignedShards { get; internal set; } - [JsonProperty(PropertyName="number_of_pending_tasks")] - public int NumberOfPendingTasks { get; internal set; } - [JsonProperty("indices")] - [JsonConverter(typeof(ResolvableDictionaryJsonConverter))] - public IReadOnlyDictionary Indices { get; internal set; } = EmptyReadOnly.Dictionary; } } diff --git a/src/Nest/Cluster/ClusterHealth/ElasticClient-ClusterHealth.cs b/src/Nest/Cluster/ClusterHealth/ElasticClient-ClusterHealth.cs index 8d1c92aa1e7..7e4eddca5af 100644 --- a/src/Nest/Cluster/ClusterHealth/ElasticClient-ClusterHealth.cs +++ b/src/Nest/Cluster/ClusterHealth/ElasticClient-ClusterHealth.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -9,44 +9,53 @@ public partial interface IElasticClient { /// /// The cluster health API allows to get a very simple status on the health of the cluster. - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html + /// + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html /// /// An optional descriptor to further describe the cluster health operation IClusterHealthResponse ClusterHealth(Func selector = null); - /// + /// IClusterHealthResponse ClusterHealth(IClusterHealthRequest request); - /// - Task ClusterHealthAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterHealthAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// - Task ClusterHealthAsync(IClusterHealthRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterHealthAsync(IClusterHealthRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public IClusterHealthResponse ClusterHealth(Func selector = null) => - this.ClusterHealth(selector.InvokeOrDefault(new ClusterHealthDescriptor())); + ClusterHealth(selector.InvokeOrDefault(new ClusterHealthDescriptor())); - /// + /// public IClusterHealthResponse ClusterHealth(IClusterHealthRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.ClusterHealthDispatch(p) + (p, d) => LowLevelDispatch.ClusterHealthDispatch(p) ); - /// - public Task ClusterHealthAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.ClusterHealthAsync(selector.InvokeOrDefault(new ClusterHealthDescriptor()), cancellationToken); - - /// - public Task ClusterHealthAsync(IClusterHealthRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task ClusterHealthAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ClusterHealthAsync(selector.InvokeOrDefault(new ClusterHealthDescriptor()), cancellationToken); + + /// + public Task ClusterHealthAsync(IClusterHealthRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.ClusterHealthDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.ClusterHealthDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/ClusterHealth/IndexHealthStats.cs b/src/Nest/Cluster/ClusterHealth/IndexHealthStats.cs index 0ef74207990..e57925fe13b 100644 --- a/src/Nest/Cluster/ClusterHealth/IndexHealthStats.cs +++ b/src/Nest/Cluster/ClusterHealth/IndexHealthStats.cs @@ -7,27 +7,32 @@ namespace Nest [JsonObject] public class IndexHealthStats { - [JsonProperty("status")] - public Health Status { get; internal set; } - - [JsonProperty("number_of_shards")] - public int NumberOfShards { get; internal set; } - [JsonProperty("number_of_replicas")] - public int NumberOfReplicas { get; internal set; } - [JsonProperty("active_primary_shards")] public int ActivePrimaryShards { get; internal set; } + [JsonProperty("active_shards")] public int ActiveShards { get; internal set; } - [JsonProperty("relocating_shards")] - public int RelocatingShards { get; internal set; } + [JsonProperty("initializing_shards")] public int InitializingShards { get; internal set; } - [JsonProperty("unassigned_shards")] - public int UnassignedShards { get; internal set; } + + [JsonProperty("number_of_replicas")] + public int NumberOfReplicas { get; internal set; } + + [JsonProperty("number_of_shards")] + public int NumberOfShards { get; internal set; } + + [JsonProperty("relocating_shards")] + public int RelocatingShards { get; internal set; } [JsonProperty("shards")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public IReadOnlyDictionary Shards { get; internal set; } = EmptyReadOnly.Dictionary; + + [JsonProperty("status")] + public Health Status { get; internal set; } + + [JsonProperty("unassigned_shards")] + public int UnassignedShards { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterHealth/ShardHealthStats.cs b/src/Nest/Cluster/ClusterHealth/ShardHealthStats.cs index 94c172ad8f6..4755b8671a8 100644 --- a/src/Nest/Cluster/ClusterHealth/ShardHealthStats.cs +++ b/src/Nest/Cluster/ClusterHealth/ShardHealthStats.cs @@ -6,16 +6,21 @@ namespace Nest [JsonObject] public class ShardHealthStats { - [JsonProperty("status")] - public Health Status { get; internal set; } - [JsonProperty("primary_active")] - public bool PrimaryActive { get; internal set; } [JsonProperty("active_shards")] public int ActiveShards { get; internal set; } - [JsonProperty("relocating_shards")] - public int RelocatingShards { get; internal set; } + [JsonProperty("initializing_shards")] public int InitializingShards { get; internal set; } + + [JsonProperty("primary_active")] + public bool PrimaryActive { get; internal set; } + + [JsonProperty("relocating_shards")] + public int RelocatingShards { get; internal set; } + + [JsonProperty("status")] + public Health Status { get; internal set; } + [JsonProperty("unassigned_shards")] public int UnassignedShards { get; internal set; } } diff --git a/src/Nest/Cluster/ClusterPendingTasks/ClusterPendingTasksResponse.cs b/src/Nest/Cluster/ClusterPendingTasks/ClusterPendingTasksResponse.cs index 867f7324883..b3593ecc96b 100644 --- a/src/Nest/Cluster/ClusterPendingTasks/ClusterPendingTasksResponse.cs +++ b/src/Nest/Cluster/ClusterPendingTasks/ClusterPendingTasksResponse.cs @@ -27,10 +27,10 @@ public class PendingTask [JsonProperty("source")] public string Source { get; internal set; } - [JsonProperty("time_in_queue_millis")] - public int TimeInQueueMilliseconds { get; internal set; } - [JsonProperty("time_in_queue")] public string TimeInQueue { get; internal set; } + + [JsonProperty("time_in_queue_millis")] + public int TimeInQueueMilliseconds { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterPendingTasks/ElasticClient-ClusterPendingTasks.cs b/src/Nest/Cluster/ClusterPendingTasks/ElasticClient-ClusterPendingTasks.cs index b3a2b3db54c..2f8a000143f 100644 --- a/src/Nest/Cluster/ClusterPendingTasks/ElasticClient-ClusterPendingTasks.cs +++ b/src/Nest/Cluster/ClusterPendingTasks/ElasticClient-ClusterPendingTasks.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -9,43 +9,55 @@ public partial interface IElasticClient { /// /// Returns a list of any cluster-level changes (e.g. create index, update mapping, allocate or fail shard) which have not yet been executed. - /// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html /// IClusterPendingTasksResponse ClusterPendingTasks(Func selector = null); - /// - Task ClusterPendingTasksAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterPendingTasksAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// IClusterPendingTasksResponse ClusterPendingTasks(IClusterPendingTasksRequest request); - /// - Task ClusterPendingTasksAsync(IClusterPendingTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterPendingTasksAsync(IClusterPendingTasksRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public IClusterPendingTasksResponse ClusterPendingTasks(Func selector = null) => - this.ClusterPendingTasks(selector.InvokeOrDefault(new ClusterPendingTasksDescriptor())); - - /// - public Task ClusterPendingTasksAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.ClusterPendingTasksAsync(selector.InvokeOrDefault(new ClusterPendingTasksDescriptor()), cancellationToken); + ClusterPendingTasks(selector.InvokeOrDefault(new ClusterPendingTasksDescriptor())); - /// + /// public IClusterPendingTasksResponse ClusterPendingTasks(IClusterPendingTasksRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.ClusterPendingTasksDispatch(p) + (p, d) => LowLevelDispatch.ClusterPendingTasksDispatch(p) ); - /// - public Task ClusterPendingTasksAsync(IClusterPendingTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( - request, - cancellationToken, - (p, d, c) => this.LowLevelDispatch.ClusterPendingTasksDispatchAsync(p, c) - ); + /// + public Task ClusterPendingTasksAsync( + Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ClusterPendingTasksAsync(selector.InvokeOrDefault(new ClusterPendingTasksDescriptor()), cancellationToken); + + /// + public Task ClusterPendingTasksAsync(IClusterPendingTasksRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher + .DispatchAsync( + request, + cancellationToken, + (p, d, c) => LowLevelDispatch.ClusterPendingTasksDispatchAsync(p, c) + ); } } diff --git a/src/Nest/Cluster/ClusterReroute/ClusterRerouteExplanation.cs b/src/Nest/Cluster/ClusterReroute/ClusterRerouteExplanation.cs index 04966e70963..d84291c9a8c 100644 --- a/src/Nest/Cluster/ClusterReroute/ClusterRerouteExplanation.cs +++ b/src/Nest/Cluster/ClusterReroute/ClusterRerouteExplanation.cs @@ -8,11 +8,11 @@ public class ClusterRerouteExplanation { [JsonProperty("command")] public string Command { get; set; } - - [JsonProperty("parameters")] - public ClusterRerouteParameters Parameters { get; set; } [JsonProperty("decisions")] public IEnumerable Decisions { get; set; } + + [JsonProperty("parameters")] + public ClusterRerouteParameters Parameters { get; set; } } } diff --git a/src/Nest/Cluster/ClusterReroute/ClusterRerouteParameters.cs b/src/Nest/Cluster/ClusterReroute/ClusterRerouteParameters.cs index 625d6e84eba..fbfc9fe8c56 100644 --- a/src/Nest/Cluster/ClusterReroute/ClusterRerouteParameters.cs +++ b/src/Nest/Cluster/ClusterReroute/ClusterRerouteParameters.cs @@ -5,22 +5,22 @@ namespace Nest [JsonObject] public class ClusterRerouteParameters { - [JsonProperty("index")] - public string Index { get; set; } - - [JsonProperty("shard")] - public int Shard { get; set; } + [JsonProperty("allow_primary")] + public bool? AllowPrimary { get; set; } [JsonProperty("from_node")] public string FromNode { get; set; } - [JsonProperty("to_node")] - public string ToNode { get; set; } + [JsonProperty("index")] + public string Index { get; set; } [JsonProperty("node")] public string Node { get; set; } - [JsonProperty("allow_primary")] - public bool? AllowPrimary { get; set; } + [JsonProperty("shard")] + public int Shard { get; set; } + + [JsonProperty("to_node")] + public string ToNode { get; set; } } } diff --git a/src/Nest/Cluster/ClusterReroute/ClusterRerouteRequest.cs b/src/Nest/Cluster/ClusterReroute/ClusterRerouteRequest.cs index db9a3f84db0..d7a123ad3cb 100644 --- a/src/Nest/Cluster/ClusterReroute/ClusterRerouteRequest.cs +++ b/src/Nest/Cluster/ClusterReroute/ClusterRerouteRequest.cs @@ -23,16 +23,21 @@ public partial class ClusterRerouteDescriptor public ClusterRerouteDescriptor Move(Func selector) => AddCommand(selector?.Invoke(new MoveClusterRerouteCommandDescriptor())); - public ClusterRerouteDescriptor Cancel(Func selector)=> + public ClusterRerouteDescriptor Cancel(Func selector) => AddCommand(selector?.Invoke(new CancelClusterRerouteCommandDescriptor())); - public ClusterRerouteDescriptor AllocateReplica(Func selector) => + public ClusterRerouteDescriptor AllocateReplica(Func selector + ) => AddCommand(selector?.Invoke(new AllocateReplicaClusterRerouteCommandDescriptor())); - public ClusterRerouteDescriptor AllocateEmptyPrimary(Func selector) => + public ClusterRerouteDescriptor AllocateEmptyPrimary( + Func selector + ) => AddCommand(selector?.Invoke(new AllocateEmptyPrimaryRerouteCommandDescriptor())); - public ClusterRerouteDescriptor AllocateStalePrimary(Func selector) => + public ClusterRerouteDescriptor AllocateStalePrimary( + Func selector + ) => AddCommand(selector?.Invoke(new AllocateStalePrimaryRerouteCommandDescriptor())); private ClusterRerouteDescriptor AddCommand(IClusterRerouteCommand rerouteCommand) => Assign(a => a.Commands?.AddIfNotNull(rerouteCommand)); diff --git a/src/Nest/Cluster/ClusterReroute/ClusterRerouteResponse.cs b/src/Nest/Cluster/ClusterReroute/ClusterRerouteResponse.cs index 18bc3e05b01..c950f5b1f6a 100644 --- a/src/Nest/Cluster/ClusterReroute/ClusterRerouteResponse.cs +++ b/src/Nest/Cluster/ClusterReroute/ClusterRerouteResponse.cs @@ -5,16 +5,18 @@ namespace Nest { public interface IClusterRerouteResponse : IResponse { - [JsonProperty("state")] - ClusterRerouteState State { get; } - [JsonProperty("explanations")] IReadOnlyCollection Explanations { get; } + + [JsonProperty("state")] + ClusterRerouteState State { get; } } public class ClusterRerouteResponse : ResponseBase, IClusterRerouteResponse { + public IReadOnlyCollection Explanations { get; internal set; } = + EmptyReadOnly.Collection; + public ClusterRerouteState State { get; internal set; } - public IReadOnlyCollection Explanations { get; internal set; } = EmptyReadOnly.Collection; } } diff --git a/src/Nest/Cluster/ClusterReroute/ClusterRerouteState.cs b/src/Nest/Cluster/ClusterReroute/ClusterRerouteState.cs index 39674c6333c..bbdc2b04422 100644 --- a/src/Nest/Cluster/ClusterReroute/ClusterRerouteState.cs +++ b/src/Nest/Cluster/ClusterReroute/ClusterRerouteState.cs @@ -6,23 +6,23 @@ namespace Nest [JsonObject] public class ClusterRerouteState { - [JsonProperty("version")] - public int Version { get; internal set; } + [JsonProperty("blocks")] + public BlockState Blocks { get; internal set; } [JsonProperty("master_node")] public string MasterNode { get; internal set; } - [JsonProperty("blocks")] - public BlockState Blocks { get; internal set; } - [JsonProperty("nodes")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public IReadOnlyDictionary Nodes { get; internal set; } + [JsonProperty("routing_nodes")] + public RoutingNodesState RoutingNodes { get; internal set; } + [JsonProperty("routing_table")] public RoutingTableState RoutingTable { get; internal set; } - [JsonProperty("routing_nodes")] - public RoutingNodesState RoutingNodes { get; internal set; } + [JsonProperty("version")] + public int Version { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterReroute/Commands/AllocateClusterRerouteCommandBase.cs b/src/Nest/Cluster/ClusterReroute/Commands/AllocateClusterRerouteCommandBase.cs index fd4bd7162b2..d2092636816 100644 --- a/src/Nest/Cluster/ClusterReroute/Commands/AllocateClusterRerouteCommandBase.cs +++ b/src/Nest/Cluster/ClusterReroute/Commands/AllocateClusterRerouteCommandBase.cs @@ -7,17 +7,15 @@ public interface IAllocateClusterRerouteCommand : IClusterRerouteCommand [JsonProperty("index")] IndexName Index { get; set; } - [JsonProperty("shard")] - int? Shard { get; set; } - [JsonProperty("node")] string Node { get; set; } - } - public interface IAllocateReplicaClusterRerouteCommand : IAllocateClusterRerouteCommand - { + [JsonProperty("shard")] + int? Shard { get; set; } } + public interface IAllocateReplicaClusterRerouteCommand : IAllocateClusterRerouteCommand { } + public interface IAllocateEmptyPrimaryRerouteCommand : IAllocateClusterRerouteCommand { [JsonProperty("accept_data_loss")] @@ -32,13 +30,12 @@ public interface IAllocateStalePrimaryRerouteCommand : IAllocateClusterRerouteCo public abstract class AllocateClusterRerouteCommandBase : IAllocateClusterRerouteCommand { + public IndexName Index { get; set; } public abstract string Name { get; } - public IndexName Index { get; set; } + public string Node { get; set; } public int? Shard { get; set; } - - public string Node { get; set; } } public class AllocateReplicaClusterRerouteCommand : AllocateClusterRerouteCommandBase, IAllocateReplicaClusterRerouteCommand @@ -48,16 +45,14 @@ public class AllocateReplicaClusterRerouteCommand : AllocateClusterRerouteComman public class AllocateEmptyPrimaryRerouteCommand : AllocateClusterRerouteCommandBase, IAllocateEmptyPrimaryRerouteCommand { - public override string Name => "allocate_empty_primary"; - public bool? AcceptDataLoss { get; set; } + public override string Name => "allocate_empty_primary"; } public class AllocateStalePrimaryRerouteCommand : AllocateClusterRerouteCommandBase, IAllocateStalePrimaryRerouteCommand { - public override string Name => "allocate_stale_primary"; - public bool? AcceptDataLoss { get; set; } + public override string Name => "allocate_stale_primary"; } public abstract class AllocateClusterRerouteCommandDescriptorBase @@ -65,16 +60,15 @@ public abstract class AllocateClusterRerouteCommandDescriptorBase, TInterface, IAllocateClusterRerouteCommand where TInterface : class, IAllocateClusterRerouteCommand { - string IClusterRerouteCommand.Name => Name; - public abstract string Name { get; } IndexName IAllocateClusterRerouteCommand.Index { get; set; } - - int? IAllocateClusterRerouteCommand.Shard { get; set; } + string IClusterRerouteCommand.Name => Name; string IAllocateClusterRerouteCommand.Node { get; set; } + int? IAllocateClusterRerouteCommand.Shard { get; set; } + public TDescriptor Index(IndexName index) => Assign(a => a.Index = index); public TDescriptor Index() where T : class => Assign(a => a.Index = typeof(T)); @@ -85,28 +79,33 @@ public abstract class AllocateClusterRerouteCommandDescriptorBase, IAllocateReplicaClusterRerouteCommand + : AllocateClusterRerouteCommandDescriptorBase, + IAllocateReplicaClusterRerouteCommand { public override string Name => "allocate_replica"; } public class AllocateEmptyPrimaryRerouteCommandDescriptor - : AllocateClusterRerouteCommandDescriptorBase, IAllocateEmptyPrimaryRerouteCommand + : AllocateClusterRerouteCommandDescriptorBase, + IAllocateEmptyPrimaryRerouteCommand { public override string Name => "allocate_empty_primary"; bool? IAllocateEmptyPrimaryRerouteCommand.AcceptDataLoss { get; set; } - public AllocateEmptyPrimaryRerouteCommandDescriptor AcceptDataLoss(bool? acceptDataLoss = true) => Assign(a => a.AcceptDataLoss = acceptDataLoss); + public AllocateEmptyPrimaryRerouteCommandDescriptor AcceptDataLoss(bool? acceptDataLoss = true) => + Assign(a => a.AcceptDataLoss = acceptDataLoss); } public class AllocateStalePrimaryRerouteCommandDescriptor - : AllocateClusterRerouteCommandDescriptorBase, IAllocateStalePrimaryRerouteCommand + : AllocateClusterRerouteCommandDescriptorBase, + IAllocateStalePrimaryRerouteCommand { public override string Name => "allocate_stale_primary"; bool? IAllocateStalePrimaryRerouteCommand.AcceptDataLoss { get; set; } - public AllocateStalePrimaryRerouteCommandDescriptor AcceptDataLoss(bool? acceptDataLoss = true) => Assign(a => a.AcceptDataLoss = acceptDataLoss); + public AllocateStalePrimaryRerouteCommandDescriptor AcceptDataLoss(bool? acceptDataLoss = true) => + Assign(a => a.AcceptDataLoss = acceptDataLoss); } } diff --git a/src/Nest/Cluster/ClusterReroute/Commands/CancelClusterRerouteCommand.cs b/src/Nest/Cluster/ClusterReroute/Commands/CancelClusterRerouteCommand.cs index c150a5624c7..e414c02e3b8 100644 --- a/src/Nest/Cluster/ClusterReroute/Commands/CancelClusterRerouteCommand.cs +++ b/src/Nest/Cluster/ClusterReroute/Commands/CancelClusterRerouteCommand.cs @@ -2,46 +2,44 @@ namespace Nest { - public interface ICancelClusterRerouteCommand : IClusterRerouteCommand { + [JsonProperty("allow_primary")] + bool? AllowPrimary { get; set; } + [JsonProperty("index")] IndexName Index { get; set; } - [JsonProperty("shard")] - int? Shard { get; set; } - [JsonProperty("node")] string Node { get; set; } - [JsonProperty("allow_primary")] - bool? AllowPrimary { get; set; } + [JsonProperty("shard")] + int? Shard { get; set; } } + public class CancelClusterRerouteCommand : ICancelClusterRerouteCommand { - public string Name => "cancel"; + public bool? AllowPrimary { get; set; } public IndexName Index { get; set; } - - public int? Shard { get; set; } + public string Name => "cancel"; public string Node { get; set; } - public bool? AllowPrimary { get; set; } + public int? Shard { get; set; } } public class CancelClusterRerouteCommandDescriptor : DescriptorBase, ICancelClusterRerouteCommand { - string IClusterRerouteCommand.Name => "cancel"; + bool? ICancelClusterRerouteCommand.AllowPrimary { get; set; } IndexName ICancelClusterRerouteCommand.Index { get; set; } - - int? ICancelClusterRerouteCommand.Shard { get; set; } + string IClusterRerouteCommand.Name => "cancel"; string ICancelClusterRerouteCommand.Node { get; set; } - bool? ICancelClusterRerouteCommand.AllowPrimary { get; set; } + int? ICancelClusterRerouteCommand.Shard { get; set; } public CancelClusterRerouteCommandDescriptor Index(IndexName index) => Assign(a => a.Index = index); diff --git a/src/Nest/Cluster/ClusterReroute/Commands/ClusterRerouteCommandJsonConverter.cs b/src/Nest/Cluster/ClusterReroute/Commands/ClusterRerouteCommandJsonConverter.cs index 34208ca7446..d6d88099816 100644 --- a/src/Nest/Cluster/ClusterReroute/Commands/ClusterRerouteCommandJsonConverter.cs +++ b/src/Nest/Cluster/ClusterReroute/Commands/ClusterRerouteCommandJsonConverter.cs @@ -7,8 +7,9 @@ namespace Nest { internal class ClusterRerouteCommandJsonConverter : JsonConverter { - public override bool CanWrite => true; public override bool CanRead => true; + public override bool CanWrite => true; + public override bool CanConvert(Type objectType) => true; public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) @@ -18,6 +19,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var child = o.Children().FirstOrDefault(); var v = child?.Children().FirstOrDefault(); if (v == null) return null; + switch (child.Name) { case "allocate_replica": @@ -37,8 +39,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist break; } return command; - - } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) @@ -48,14 +48,17 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s var properties = value.GetType().GetCachedObjectProperties(); if (properties.Count == 0) return; + writer.WriteStartObject(); writer.WritePropertyName(c.Name); writer.WriteStartObject(); foreach (var p in properties) { if (p.Ignored) continue; + var vv = p.ValueProvider.GetValue(value); if (vv == null) continue; + writer.WritePropertyName(p.PropertyName); serializer.Serialize(writer, vv); } diff --git a/src/Nest/Cluster/ClusterReroute/Commands/IClusterRerouteCommand.cs b/src/Nest/Cluster/ClusterReroute/Commands/IClusterRerouteCommand.cs index 37926de5f2a..bd860c943a2 100644 --- a/src/Nest/Cluster/ClusterReroute/Commands/IClusterRerouteCommand.cs +++ b/src/Nest/Cluster/ClusterReroute/Commands/IClusterRerouteCommand.cs @@ -8,4 +8,4 @@ public interface IClusterRerouteCommand [JsonIgnore] string Name { get; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cluster/ClusterReroute/Commands/MoveClusterRerouteCommand.cs b/src/Nest/Cluster/ClusterReroute/Commands/MoveClusterRerouteCommand.cs index f93d7ca3a0a..9d712e8d9c1 100644 --- a/src/Nest/Cluster/ClusterReroute/Commands/MoveClusterRerouteCommand.cs +++ b/src/Nest/Cluster/ClusterReroute/Commands/MoveClusterRerouteCommand.cs @@ -2,8 +2,7 @@ namespace Nest { - - public interface IMoveClusterRerouteCommand: IClusterRerouteCommand + public interface IMoveClusterRerouteCommand : IClusterRerouteCommand { [JsonProperty("from_node")] string FromNode { get; set; } @@ -17,30 +16,29 @@ public interface IMoveClusterRerouteCommand: IClusterRerouteCommand [JsonProperty("to_node")] string ToNode { get; set; } } + public class MoveClusterRerouteCommand : IMoveClusterRerouteCommand { - public string Name => "move"; + public string FromNode { get; set; } public IndexName Index { get; set; } + public string Name => "move"; public int? Shard { get; set; } - public string FromNode { get; set; } - public string ToNode { get; set; } } public class MoveClusterRerouteCommandDescriptor : DescriptorBase, IMoveClusterRerouteCommand { - string IClusterRerouteCommand.Name => "move"; + string IMoveClusterRerouteCommand.FromNode { get; set; } IndexName IMoveClusterRerouteCommand.Index { get; set; } + string IClusterRerouteCommand.Name => "move"; int? IMoveClusterRerouteCommand.Shard { get; set; } - string IMoveClusterRerouteCommand.FromNode { get; set; } - string IMoveClusterRerouteCommand.ToNode { get; set; } public MoveClusterRerouteCommandDescriptor Index(IndexName index) => Assign(a => a.Index = index); diff --git a/src/Nest/Cluster/ClusterReroute/ElasticClient-ClusterReroute.cs b/src/Nest/Cluster/ClusterReroute/ElasticClient-ClusterReroute.cs index 306f761547a..e3d5c107987 100644 --- a/src/Nest/Cluster/ClusterReroute/ElasticClient-ClusterReroute.cs +++ b/src/Nest/Cluster/ClusterReroute/ElasticClient-ClusterReroute.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -14,40 +14,47 @@ public partial interface IElasticClient /// IClusterRerouteResponse ClusterReroute(Func selector); - /// - Task ClusterRerouteAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterRerouteAsync(Func selector, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// IClusterRerouteResponse ClusterReroute(IClusterRerouteRequest request); - /// - Task ClusterRerouteAsync(IClusterRerouteRequest request, CancellationToken cancellationToken = default(CancellationToken)); - + /// + Task ClusterRerouteAsync(IClusterRerouteRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public IClusterRerouteResponse ClusterReroute(Func selector) => - this.ClusterReroute(selector?.Invoke(new ClusterRerouteDescriptor())); - - /// - public Task ClusterRerouteAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)) => - this.ClusterRerouteAsync(selector?.Invoke(new ClusterRerouteDescriptor()), cancellationToken); + ClusterReroute(selector?.Invoke(new ClusterRerouteDescriptor())); - /// + /// public IClusterRerouteResponse ClusterReroute(IClusterRerouteRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - this.LowLevelDispatch.ClusterRerouteDispatch + LowLevelDispatch.ClusterRerouteDispatch ); - /// - public Task ClusterRerouteAsync(IClusterRerouteRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task ClusterRerouteAsync(Func selector, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ClusterRerouteAsync(selector?.Invoke(new ClusterRerouteDescriptor()), cancellationToken); + + /// + public Task ClusterRerouteAsync(IClusterRerouteRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - this.LowLevelDispatch.ClusterRerouteDispatchAsync + LowLevelDispatch.ClusterRerouteDispatchAsync ); } } diff --git a/src/Nest/Cluster/ClusterSettings/ClusterGetSettings/ClusterGetSettingsRequest.cs b/src/Nest/Cluster/ClusterSettings/ClusterGetSettings/ClusterGetSettingsRequest.cs index d0d8913b0b9..7706c40cb5f 100644 --- a/src/Nest/Cluster/ClusterSettings/ClusterGetSettings/ClusterGetSettingsRequest.cs +++ b/src/Nest/Cluster/ClusterSettings/ClusterGetSettings/ClusterGetSettingsRequest.cs @@ -1,7 +1,7 @@ namespace Nest { public partial interface IClusterGetSettingsRequest { } - + public partial class ClusterGetSettingsRequest { } public partial class ClusterGetSettingsDescriptor { } diff --git a/src/Nest/Cluster/ClusterSettings/ClusterGetSettings/ElasticClient-ClusterGetSettings.cs b/src/Nest/Cluster/ClusterSettings/ClusterGetSettings/ElasticClient-ClusterGetSettings.cs index e40a556d1da..a8a75014342 100644 --- a/src/Nest/Cluster/ClusterSettings/ClusterGetSettings/ElasticClient-ClusterGetSettings.cs +++ b/src/Nest/Cluster/ClusterSettings/ClusterGetSettings/ElasticClient-ClusterGetSettings.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -10,43 +10,55 @@ public partial interface IElasticClient /// /// Gets cluster wide specific settings. Settings updated can either be persistent /// (applied cross restarts) or transient (will not survive a full cluster restart). - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html + /// + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html /// IClusterGetSettingsResponse ClusterGetSettings(Func selector = null); - /// - Task ClusterGetSettingsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterGetSettingsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// IClusterGetSettingsResponse ClusterGetSettings(IClusterGetSettingsRequest request); - /// - Task ClusterGetSettingsAsync(IClusterGetSettingsRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterGetSettingsAsync(IClusterGetSettingsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + /// public IClusterGetSettingsResponse ClusterGetSettings(Func selector = null) => - this.ClusterGetSettings(selector.InvokeOrDefault(new ClusterGetSettingsDescriptor())); - - /// - public Task ClusterGetSettingsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.ClusterGetSettingsAsync(selector.InvokeOrDefault(new ClusterGetSettingsDescriptor()), cancellationToken); + ClusterGetSettings(selector.InvokeOrDefault(new ClusterGetSettingsDescriptor())); - /// + /// public IClusterGetSettingsResponse ClusterGetSettings(IClusterGetSettingsRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request ?? new ClusterGetSettingsRequest(), - (p, d) => this.LowLevelDispatch.ClusterGetSettingsDispatch(p) + (p, d) => LowLevelDispatch.ClusterGetSettingsDispatch(p) ); - /// - public Task ClusterGetSettingsAsync(IClusterGetSettingsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( - request ?? new ClusterGetSettingsRequest(), - cancellationToken, - (p, d, c) => this.LowLevelDispatch.ClusterGetSettingsDispatchAsync(p, c) - ); + /// + public Task ClusterGetSettingsAsync( + Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ClusterGetSettingsAsync(selector.InvokeOrDefault(new ClusterGetSettingsDescriptor()), cancellationToken); + + /// + public Task ClusterGetSettingsAsync(IClusterGetSettingsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher + .DispatchAsync( + request ?? new ClusterGetSettingsRequest(), + cancellationToken, + (p, d, c) => LowLevelDispatch.ClusterGetSettingsDispatchAsync(p, c) + ); } } diff --git a/src/Nest/Cluster/ClusterSettings/ClusterPutSettings/ClusterPutSettingsRequest.cs b/src/Nest/Cluster/ClusterSettings/ClusterPutSettings/ClusterPutSettingsRequest.cs index 825c460ddb9..8a83d68669e 100644 --- a/src/Nest/Cluster/ClusterSettings/ClusterPutSettings/ClusterPutSettingsRequest.cs +++ b/src/Nest/Cluster/ClusterSettings/ClusterPutSettings/ClusterPutSettingsRequest.cs @@ -11,7 +11,6 @@ public partial interface IClusterPutSettingsRequest [JsonProperty("transient")] IDictionary Transient { get; set; } - } public partial class ClusterPutSettingsRequest diff --git a/src/Nest/Cluster/ClusterSettings/ClusterPutSettings/ElasticClient-ClusterPutSettings.cs b/src/Nest/Cluster/ClusterSettings/ClusterPutSettings/ElasticClient-ClusterPutSettings.cs index d401d91826c..81af835f29c 100644 --- a/src/Nest/Cluster/ClusterSettings/ClusterPutSettings/ElasticClient-ClusterPutSettings.cs +++ b/src/Nest/Cluster/ClusterSettings/ClusterPutSettings/ElasticClient-ClusterPutSettings.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -10,42 +10,54 @@ public partial interface IElasticClient /// /// Allows to update cluster wide specific settings. Settings updated can either be persistent /// (applied cross restarts) or transient (will not survive a full cluster restart). - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html + /// + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html /// IClusterPutSettingsResponse ClusterPutSettings(Func selector); - /// - Task ClusterPutSettingsAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterPutSettingsAsync(Func selector, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// IClusterPutSettingsResponse ClusterPutSettings(IClusterPutSettingsRequest request); - /// - Task ClusterPutSettingsAsync(IClusterPutSettingsRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterPutSettingsAsync(IClusterPutSettingsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } + public partial class ElasticClient { - /// + /// public IClusterPutSettingsResponse ClusterPutSettings(Func selector) => - this.ClusterPutSettings(selector.InvokeOrDefault(new ClusterPutSettingsDescriptor())); - - /// - public Task ClusterPutSettingsAsync(Func selector, CancellationToken cancellationToken = default(CancellationToken)) => - this.ClusterPutSettingsAsync(selector.InvokeOrDefault(new ClusterPutSettingsDescriptor()), cancellationToken); + ClusterPutSettings(selector.InvokeOrDefault(new ClusterPutSettingsDescriptor())); - /// + /// public IClusterPutSettingsResponse ClusterPutSettings(IClusterPutSettingsRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - this.LowLevelDispatch.ClusterPutSettingsDispatch + LowLevelDispatch.ClusterPutSettingsDispatch ); - /// - public Task ClusterPutSettingsAsync(IClusterPutSettingsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( - request, - cancellationToken, - this.LowLevelDispatch.ClusterPutSettingsDispatchAsync - ); + /// + public Task ClusterPutSettingsAsync(Func selector, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ClusterPutSettingsAsync(selector.InvokeOrDefault(new ClusterPutSettingsDescriptor()), cancellationToken); + + /// + public Task ClusterPutSettingsAsync(IClusterPutSettingsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher + .DispatchAsync( + request, + cancellationToken, + LowLevelDispatch.ClusterPutSettingsDispatchAsync + ); } } diff --git a/src/Nest/Cluster/ClusterState/AllocationId.cs b/src/Nest/Cluster/ClusterState/AllocationId.cs index dd7b7dc9fab..12d9e8b8af5 100644 --- a/src/Nest/Cluster/ClusterState/AllocationId.cs +++ b/src/Nest/Cluster/ClusterState/AllocationId.cs @@ -1,6 +1,3 @@ -using System; -using System.Linq; -using System.Collections.Generic; using Newtonsoft.Json; namespace Nest @@ -10,4 +7,4 @@ public class AllocationId [JsonProperty("id")] public string Id { get; internal set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cluster/ClusterState/BlockState.cs b/src/Nest/Cluster/ClusterState/BlockState.cs index 6157f665b0e..a7ce273c0ff 100644 --- a/src/Nest/Cluster/ClusterState/BlockState.cs +++ b/src/Nest/Cluster/ClusterState/BlockState.cs @@ -1,6 +1,3 @@ -using System; -using System.Linq; -using System.Collections.Generic; using Newtonsoft.Json; namespace Nest @@ -10,4 +7,4 @@ public class BlockState [JsonProperty("read_only")] public bool ReadOnly { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cluster/ClusterState/ClusterStateResponse.cs b/src/Nest/Cluster/ClusterState/ClusterStateResponse.cs index ea640c12623..7612334ddd5 100644 --- a/src/Nest/Cluster/ClusterState/ClusterStateResponse.cs +++ b/src/Nest/Cluster/ClusterState/ClusterStateResponse.cs @@ -5,61 +5,60 @@ namespace Nest { public interface IClusterStateResponse : IResponse { + [JsonProperty("blocks")] + BlockState Blocks { get; } + [JsonProperty("cluster_name")] string ClusterName { get; } - [JsonProperty("master_node")] - string MasterNode { get; } - - [JsonProperty("state_uuid")] - string StateUUID { get; } - /// The Universally Unique Identifier for the cluster. /// While the cluster is still forming, it is possible for the `cluster_uuid` to be `_na_`. [JsonProperty("cluster_uuid")] string ClusterUUID { get; } - [JsonProperty("version")] - long Version { get; } + [JsonProperty("master_node")] + string MasterNode { get; } + + [JsonProperty("metadata")] + MetadataState Metadata { get; } [JsonProperty("nodes")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] IReadOnlyDictionary Nodes { get; } - [JsonProperty("metadata")] - MetadataState Metadata { get; } + [JsonProperty("routing_nodes")] + RoutingNodesState RoutingNodes { get; } [JsonProperty("routing_table")] RoutingTableState RoutingTable { get; } - [JsonProperty("routing_nodes")] - RoutingNodesState RoutingNodes { get; } + [JsonProperty("state_uuid")] + string StateUUID { get; } - [JsonProperty("blocks")] - BlockState Blocks { get; } + [JsonProperty("version")] + long Version { get; } } public class ClusterStateResponse : ResponseBase, IClusterStateResponse { + public BlockState Blocks { get; internal set; } public string ClusterName { get; internal set; } - public string MasterNode { get; internal set; } - - public string StateUUID { get; internal set; } - - /// + /// public string ClusterUUID { get; internal set; } - public long Version { get; internal set; } + public string MasterNode { get; internal set; } + + public MetadataState Metadata { get; internal set; } public IReadOnlyDictionary Nodes { get; internal set; } = EmptyReadOnly.Dictionary; - public MetadataState Metadata { get; internal set; } + public RoutingNodesState RoutingNodes { get; internal set; } public RoutingTableState RoutingTable { get; internal set; } - public RoutingNodesState RoutingNodes { get; internal set; } + public string StateUUID { get; internal set; } - public BlockState Blocks { get; internal set; } + public long Version { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterState/ElasticClient-ClusterState.cs b/src/Nest/Cluster/ClusterState/ElasticClient-ClusterState.cs index 6b3016757e9..fb504457071 100644 --- a/src/Nest/Cluster/ClusterState/ElasticClient-ClusterState.cs +++ b/src/Nest/Cluster/ClusterState/ElasticClient-ClusterState.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -9,44 +9,51 @@ public partial interface IElasticClient { /// /// The cluster state API allows to get a comprehensive state information of the whole cluster. - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-state.html + /// + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-state.html /// /// A descriptor that describes the parameters for the cluster state operation IClusterStateResponse ClusterState(Func selector = null); - /// + /// IClusterStateResponse ClusterState(IClusterStateRequest request); - /// - Task ClusterStateAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterStateAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task ClusterStateAsync(IClusterStateRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public IClusterStateResponse ClusterState(Func selector = null) => - this.ClusterState(selector.InvokeOrDefault(new ClusterStateDescriptor())); + ClusterState(selector.InvokeOrDefault(new ClusterStateDescriptor())); - /// + /// public IClusterStateResponse ClusterState(IClusterStateRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.ClusterStateDispatch(p) + (p, d) => LowLevelDispatch.ClusterStateDispatch(p) ); - /// - public Task ClusterStateAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.ClusterStateAsync(selector.InvokeOrDefault(new ClusterStateDescriptor()), cancellationToken); - - /// - public Task ClusterStateAsync(IClusterStateRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task ClusterStateAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ClusterStateAsync(selector.InvokeOrDefault(new ClusterStateDescriptor()), cancellationToken); + + /// + public Task ClusterStateAsync(IClusterStateRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.ClusterStateDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.ClusterStateDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/ClusterState/MetadataIndexState.cs b/src/Nest/Cluster/ClusterState/MetadataIndexState.cs index 0b33ebcba80..8897b8f5be5 100644 --- a/src/Nest/Cluster/ClusterState/MetadataIndexState.cs +++ b/src/Nest/Cluster/ClusterState/MetadataIndexState.cs @@ -6,17 +6,17 @@ namespace Nest { public class MetadataIndexState { - [JsonProperty("state")] - public string State { get; internal set; } + [JsonProperty("aliases")] + public IEnumerable Aliases { get; internal set; } + + [JsonProperty("mappings")] + public IMappings Mappings { get; internal set; } [JsonProperty("settings")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public DynamicBody Settings { get; internal set; } - [JsonProperty("mappings")] - public IMappings Mappings { get; internal set; } - - [JsonProperty("aliases")] - public IEnumerable Aliases { get; internal set; } + [JsonProperty("state")] + public string State { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterState/MetadataState.cs b/src/Nest/Cluster/ClusterState/MetadataState.cs index 2a706e83af2..a905566fd26 100644 --- a/src/Nest/Cluster/ClusterState/MetadataState.cs +++ b/src/Nest/Cluster/ClusterState/MetadataState.cs @@ -1,5 +1,3 @@ -using System; -using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; @@ -7,15 +5,15 @@ namespace Nest { public class MetadataState { - [JsonProperty("templates")] - [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] - public IReadOnlyDictionary Templates { get; internal set; } - [JsonProperty("cluster_uuid")] public string ClusterUUID { get; internal set; } [JsonProperty("indices")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public IReadOnlyDictionary Indices { get; internal set; } + + [JsonProperty("templates")] + [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] + public IReadOnlyDictionary Templates { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterState/NodeState.cs b/src/Nest/Cluster/ClusterState/NodeState.cs index 15f6972f7d3..42e0f58ed7f 100644 --- a/src/Nest/Cluster/ClusterState/NodeState.cs +++ b/src/Nest/Cluster/ClusterState/NodeState.cs @@ -5,14 +5,14 @@ namespace Nest { public class NodeState { + [JsonProperty("attributes")] + [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] + public Dictionary Attributes { get; internal set; } + [JsonProperty("name")] public string Name { get; internal set; } [JsonProperty("transport_address")] public string TransportAddress { get; internal set; } - - [JsonProperty("attributes")] - [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] - public Dictionary Attributes { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterState/RoutingNodesState.cs b/src/Nest/Cluster/ClusterState/RoutingNodesState.cs index 46ae4b9cd0c..3c2a6d6e619 100644 --- a/src/Nest/Cluster/ClusterState/RoutingNodesState.cs +++ b/src/Nest/Cluster/ClusterState/RoutingNodesState.cs @@ -1,5 +1,3 @@ -using System; -using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; @@ -7,10 +5,10 @@ namespace Nest { public class RoutingNodesState { - [JsonProperty("unassigned")] - public IReadOnlyCollection Unassigned { get; internal set; } - [JsonProperty("nodes")] public IReadOnlyDictionary> Nodes { get; internal set; } + + [JsonProperty("unassigned")] + public IReadOnlyCollection Unassigned { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterState/RoutingShard.cs b/src/Nest/Cluster/ClusterState/RoutingShard.cs index 0e2f18a164e..11289da98b3 100644 --- a/src/Nest/Cluster/ClusterState/RoutingShard.cs +++ b/src/Nest/Cluster/ClusterState/RoutingShard.cs @@ -1,6 +1,3 @@ -using System; -using System.Linq; -using System.Collections.Generic; using Newtonsoft.Json; namespace Nest @@ -10,22 +7,22 @@ public class RoutingShard [JsonProperty("allocation_id")] public AllocationId AllocationId { get; internal set; } - [JsonProperty("state")] - public string State { get; internal set; } - - [JsonProperty("primary")] - public bool Primary { get; internal set; } + [JsonProperty("index")] + public string Index { get; internal set; } [JsonProperty("node")] public string Node { get; internal set; } + [JsonProperty("primary")] + public bool Primary { get; internal set; } + [JsonProperty("relocating_node")] public string RelocatingNode { get; internal set; } [JsonProperty("shard")] public int Shard { get; internal set; } - [JsonProperty("index")] - public string Index { get; internal set; } + [JsonProperty("state")] + public string State { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterState/RoutingTableState.cs b/src/Nest/Cluster/ClusterState/RoutingTableState.cs index 2276ab4ce49..7a321497ecb 100644 --- a/src/Nest/Cluster/ClusterState/RoutingTableState.cs +++ b/src/Nest/Cluster/ClusterState/RoutingTableState.cs @@ -1,5 +1,3 @@ -using System; -using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; diff --git a/src/Nest/Cluster/ClusterStats/ClusterIndicesStats.cs b/src/Nest/Cluster/ClusterStats/ClusterIndicesStats.cs index b5092c1dbb1..38706c8536f 100644 --- a/src/Nest/Cluster/ClusterStats/ClusterIndicesStats.cs +++ b/src/Nest/Cluster/ClusterStats/ClusterIndicesStats.cs @@ -1,5 +1,4 @@ - -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { @@ -29,14 +28,13 @@ public class ClusterIndicesStats [JsonProperty("store")] public StoreStats Store { get; internal set; } - } [JsonObject] public class ClusterIndicesShardsStats { - [JsonProperty("total")] - public double Total { get; internal set; } + [JsonProperty("index")] + public ClusterIndicesShardsIndexStats Index { get; internal set; } [JsonProperty("primaries")] public double Primaries { get; internal set; } @@ -44,33 +42,33 @@ public class ClusterIndicesShardsStats [JsonProperty("replication")] public double Replication { get; internal set; } - [JsonProperty("index")] - public ClusterIndicesShardsIndexStats Index { get; internal set; } + [JsonProperty("total")] + public double Total { get; internal set; } } [JsonObject] public class ClusterIndicesShardsIndexStats { - [JsonProperty("shards")] - public ClusterShardMetrics Shards { get; internal set; } - [JsonProperty("primaries")] public ClusterShardMetrics Primaries { get; internal set; } [JsonProperty("replication")] public ClusterShardMetrics Replication { get; internal set; } + + [JsonProperty("shards")] + public ClusterShardMetrics Shards { get; internal set; } } [JsonObject] public class ClusterShardMetrics { - [JsonProperty("min")] - public double Min { get; internal set; } + [JsonProperty("avg")] + public double Avg { get; internal set; } [JsonProperty("max")] public double Max { get; internal set; } - [JsonProperty("avg")] - public double Avg { get; internal set; } + [JsonProperty("min")] + public double Min { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterStats/ClusterNodesStats.cs b/src/Nest/Cluster/ClusterStats/ClusterNodesStats.cs index 15a77a271c5..b8cda13c4e8 100644 --- a/src/Nest/Cluster/ClusterStats/ClusterNodesStats.cs +++ b/src/Nest/Cluster/ClusterStats/ClusterNodesStats.cs @@ -9,40 +9,45 @@ public class ClusterNodesStats [JsonProperty("count")] public ClusterNodeCount Count { get; internal set; } - [JsonProperty("versions")] - public IReadOnlyCollection Versions { get; internal set; } - - [JsonProperty("os")] - public ClusterOperatingSystemStats OperatingSystem { get; internal set; } - - [JsonProperty("process")] - public ClusterProcess Process { get; internal set; } + [JsonProperty("fs")] + public ClusterFileSystem FileSystem { get; internal set; } [JsonProperty("jvm")] public ClusterJvm Jvm { get; internal set; } - [JsonProperty("fs")] - public ClusterFileSystem FileSystem { get; internal set; } + [JsonProperty("os")] + public ClusterOperatingSystemStats OperatingSystem { get; internal set; } [JsonProperty("plugins")] public IReadOnlyCollection Plugins { get; internal set; } + + [JsonProperty("process")] + public ClusterProcess Process { get; internal set; } + + [JsonProperty("versions")] + public IReadOnlyCollection Versions { get; internal set; } } [JsonObject] public class ClusterFileSystem { - [JsonProperty("total")] - public string Total { get; internal set; } - [JsonProperty("total_in_bytes")] - public long TotalInBytes { get; internal set; } - [JsonProperty("free")] - public string Free { get; internal set; } - [JsonProperty("free_in_bytes")] - public long FreeInBytes { get; internal set; } [JsonProperty("available")] public string Available { get; internal set; } + [JsonProperty("available_in_bytes")] public long AvailableInBytes { get; internal set; } + + [JsonProperty("free")] + public string Free { get; internal set; } + + [JsonProperty("free_in_bytes")] + public long FreeInBytes { get; internal set; } + + [JsonProperty("total")] + public string Total { get; internal set; } + + [JsonProperty("total_in_bytes")] + public long TotalInBytes { get; internal set; } } [JsonObject] @@ -54,49 +59,49 @@ public class ClusterJvm [JsonProperty("max_uptime_in_millis")] public long MaxUptimeInMilliseconds { get; internal set; } - [JsonProperty("versions")] - public IReadOnlyCollection Versions { get; internal set; } - [JsonProperty("mem")] public ClusterJvmMemory Memory { get; internal set; } [JsonProperty("threads")] public long Threads { get; internal set; } + + [JsonProperty("versions")] + public IReadOnlyCollection Versions { get; internal set; } } [JsonObject] public class ClusterJvmVersion { + [JsonProperty("count")] + public int Count { get; internal set; } + [JsonProperty("version")] public string Version { get; internal set; } [JsonProperty("vm_name")] public string VmName { get; internal set; } - [JsonProperty("vm_version")] - public string VmVersion { get; internal set; } - [JsonProperty("vm_vendor")] public string VmVendor { get; internal set; } - [JsonProperty("count")] - public int Count { get; internal set; } + [JsonProperty("vm_version")] + public string VmVersion { get; internal set; } } [JsonObject] public class ClusterJvmMemory { - [JsonProperty("heap_used")] - public string HeapUsed { get ;set;} - - [JsonProperty("heap_used_in_bytes")] - public long HeapUsedInBytes { get; internal set; } - [JsonProperty("heap_max")] public string HeapMax { get; internal set; } [JsonProperty("heap_max_in_bytes")] public long HeapMaxInBytes { get; internal set; } + + [JsonProperty("heap_used")] + public string HeapUsed { get; set; } + + [JsonProperty("heap_used_in_bytes")] + public long HeapUsedInBytes { get; internal set; } } [JsonObject] @@ -119,25 +124,25 @@ public class ClusterProcessCpu [JsonObject] public class ClusterProcessOpenFileDescriptors { - [JsonProperty("min")] - public long Min { get; internal set; } + [JsonProperty("avg")] + public long Avg { get; internal set; } [JsonProperty("max")] public long Max { get; internal set; } - [JsonProperty("avg")] - public long Avg { get; internal set; } + [JsonProperty("min")] + public long Min { get; internal set; } } [JsonObject] public class ClusterOperatingSystemStats { - [JsonProperty("available_processors")] - public int AvailableProcessors { get; internal set; } - [JsonProperty("allocated_processors")] public int AllocatedProcessors { get; internal set; } + [JsonProperty("available_processors")] + public int AvailableProcessors { get; internal set; } + [JsonProperty("names")] public IReadOnlyCollection Names { get; internal set; } } @@ -155,19 +160,19 @@ public class ClusterOperatingSystemName [JsonObject] public class ClusterNodeCount { - [JsonProperty("total")] - public int Total { get; internal set; } - [JsonProperty("coordinating_only")] public int CoordinatingOnly { get; internal set; } - [JsonProperty("master")] - public int Master { get; internal set; } - [JsonProperty("data")] public int Data { get; internal set; } [JsonProperty("ingest")] public int Ingest { get; internal set; } + + [JsonProperty("master")] + public int Master { get; internal set; } + + [JsonProperty("total")] + public int Total { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterStats/ClusterStatsResponse.cs b/src/Nest/Cluster/ClusterStats/ClusterStatsResponse.cs index 42453e439e8..671e7eb05d5 100644 --- a/src/Nest/Cluster/ClusterStats/ClusterStatsResponse.cs +++ b/src/Nest/Cluster/ClusterStats/ClusterStatsResponse.cs @@ -7,29 +7,29 @@ public interface IClusterStatsResponse : INodesResponse [JsonProperty("cluster_name")] string ClusterName { get; } - [JsonProperty("timestamp")] - long Timestamp { get; } - - [JsonProperty("status")] - ClusterStatus Status { get; } - [JsonProperty("indices")] ClusterIndicesStats Indices { get; } [JsonProperty("nodes")] ClusterNodesStats Nodes { get; } + + [JsonProperty("status")] + ClusterStatus Status { get; } + + [JsonProperty("timestamp")] + long Timestamp { get; } } public class ClusterStatsResponse : NodesResponseBase, IClusterStatsResponse { public string ClusterName { get; internal set; } - public long Timestamp { get; internal set; } - - public ClusterStatus Status { get; internal set; } - public ClusterIndicesStats Indices { get; internal set; } public ClusterNodesStats Nodes { get; internal set; } + + public ClusterStatus Status { get; internal set; } + + public long Timestamp { get; internal set; } } } diff --git a/src/Nest/Cluster/ClusterStats/ElasticClient-ClusterStats.cs b/src/Nest/Cluster/ClusterStats/ElasticClient-ClusterStats.cs index bb53bb096a6..3599615a4eb 100644 --- a/src/Nest/Cluster/ClusterStats/ElasticClient-ClusterStats.cs +++ b/src/Nest/Cluster/ClusterStats/ElasticClient-ClusterStats.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -12,43 +12,50 @@ public partial interface IElasticClient /// (shard numbers, store size, memory usage) and information about the current nodes that form the /// cluster (number, roles, os, jvm versions, memory usage, cpu and installed plugins). /// - /// https://www.elastic.co/guide/en/elasticsearch/guide/current/_cluster_stats.html + /// + /// https://www.elastic.co/guide/en/elasticsearch/guide/current/_cluster_stats.html /// A descriptor that describes the cluster stats operation IClusterStatsResponse ClusterStats(Func selector = null); - /// - Task ClusterStatsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ClusterStatsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// IClusterStatsResponse ClusterStats(IClusterStatsRequest request); - /// + /// Task ClusterStatsAsync(IClusterStatsRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public IClusterStatsResponse ClusterStats(Func selector = null) => - this.ClusterStats(selector.InvokeOrDefault(new ClusterStatsDescriptor())); - - /// - public Task ClusterStatsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.ClusterStatsAsync(selector.InvokeOrDefault(new ClusterStatsDescriptor()), cancellationToken); + ClusterStats(selector.InvokeOrDefault(new ClusterStatsDescriptor())); - /// + /// public IClusterStatsResponse ClusterStats(IClusterStatsRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.ClusterStatsDispatch(p) + (p, d) => LowLevelDispatch.ClusterStatsDispatch(p) ); - /// - public Task ClusterStatsAsync(IClusterStatsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task ClusterStatsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ClusterStatsAsync(selector.InvokeOrDefault(new ClusterStatsDescriptor()), cancellationToken); + + /// + public Task ClusterStatsAsync(IClusterStatsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.ClusterStatsDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.ClusterStatsDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/NodesHotThreads/ElasticClient-NodesHotThreads.cs b/src/Nest/Cluster/NodesHotThreads/ElasticClient-NodesHotThreads.cs index 0f47ba9dcf9..cdc2b4d1186 100644 --- a/src/Nest/Cluster/NodesHotThreads/ElasticClient-NodesHotThreads.cs +++ b/src/Nest/Cluster/NodesHotThreads/ElasticClient-NodesHotThreads.cs @@ -3,9 +3,9 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -20,48 +20,55 @@ public partial interface IElasticClient /// An optional descriptor to further describe the nodes hot threads operation INodesHotThreadsResponse NodesHotThreads(Func selector = null); - /// + /// INodesHotThreadsResponse NodesHotThreads(INodesHotThreadsRequest request); - /// - Task NodesHotThreadsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task NodesHotThreadsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// - Task NodesHotThreadsAsync(INodesHotThreadsRequest request, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task NodesHotThreadsAsync(INodesHotThreadsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ); } public partial class ElasticClient { - /// + //::: {Dragonfly}{lvtIV72sRIWBGik7ulbuaw}{127.0.0.1}{127.0.0.1:9300} + private static readonly Regex NodeRegex = new Regex(@"^\s\{(?.+?)\}\{(?.+?)\}(?.+)\n"); + + /// public INodesHotThreadsResponse NodesHotThreads(Func selector = null) => - this.NodesHotThreads(selector.InvokeOrDefault(new NodesHotThreadsDescriptor())); + NodesHotThreads(selector.InvokeOrDefault(new NodesHotThreadsDescriptor())); - /// + /// public INodesHotThreadsResponse NodesHotThreads(INodesHotThreadsRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, new NodesHotThreadConverter(DeserializeNodesHotThreadResponse), - (p, d) => this.LowLevelDispatch.NodesHotThreadsDispatch(p) + (p, d) => LowLevelDispatch.NodesHotThreadsDispatch(p) ); - /// - public Task NodesHotThreadsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.NodesHotThreadsAsync(selector.InvokeOrDefault(new NodesHotThreadsDescriptor()), cancellationToken); - - /// - public Task NodesHotThreadsAsync(INodesHotThreadsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task NodesHotThreadsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + NodesHotThreadsAsync(selector.InvokeOrDefault(new NodesHotThreadsDescriptor()), cancellationToken); + + /// + public Task NodesHotThreadsAsync(INodesHotThreadsRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, new NodesHotThreadConverter(DeserializeNodesHotThreadResponse), - (p, d, c) => this.LowLevelDispatch.NodesHotThreadsDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.NodesHotThreadsDispatchAsync(p, c) ); - //::: {Dragonfly}{lvtIV72sRIWBGik7ulbuaw}{127.0.0.1}{127.0.0.1:9300} - private static Regex NodeRegex = new Regex(@"^\s\{(?.+?)\}\{(?.+?)\}(?.+)\n"); - - /// /// Because the nodes.hot_threads endpoint returns plain text instead of JSON, we have to /// manually parse the response text into a typed response object. @@ -104,6 +111,5 @@ where matches.Success return new NodesHotThreadsResponse(info.ToList()); } } - } } diff --git a/src/Nest/Cluster/NodesHotThreads/NodesHotThreadsRequest.cs b/src/Nest/Cluster/NodesHotThreads/NodesHotThreadsRequest.cs index 602e0e07d4e..3bd21765196 100644 --- a/src/Nest/Cluster/NodesHotThreads/NodesHotThreadsRequest.cs +++ b/src/Nest/Cluster/NodesHotThreads/NodesHotThreadsRequest.cs @@ -1,8 +1,7 @@ - -namespace Nest +namespace Nest { public partial interface INodesHotThreadsRequest { } - + public partial class NodesHotThreadsRequest { } public partial class NodesHotThreadsDescriptor { } diff --git a/src/Nest/Cluster/NodesHotThreads/NodesHotThreadsResponse.cs b/src/Nest/Cluster/NodesHotThreads/NodesHotThreadsResponse.cs index b99b6deae4b..f1190e9b000 100644 --- a/src/Nest/Cluster/NodesHotThreads/NodesHotThreadsResponse.cs +++ b/src/Nest/Cluster/NodesHotThreads/NodesHotThreadsResponse.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; -using System.Linq; namespace Nest { public class HotThreadInformation { - public string NodeName { get; internal set; } + public IReadOnlyCollection Hosts { get; internal set; } = EmptyReadOnly.Collection; public string NodeId { get; internal set; } + public string NodeName { get; internal set; } public IReadOnlyCollection Threads { get; internal set; } = EmptyReadOnly.Collection; - public IReadOnlyCollection Hosts { get; internal set; } = EmptyReadOnly.Collection; } public interface INodesHotThreadsResponse : IResponse @@ -20,10 +19,7 @@ public class NodesHotThreadsResponse : ResponseBase, INodesHotThreadsResponse { public NodesHotThreadsResponse() { } - internal NodesHotThreadsResponse(IReadOnlyCollection threadInfo) - { - this.HotThreads = threadInfo; - } + internal NodesHotThreadsResponse(IReadOnlyCollection threadInfo) => HotThreads = threadInfo; public IReadOnlyCollection HotThreads { get; internal set; } = EmptyReadOnly.Collection; } diff --git a/src/Nest/Cluster/NodesInfo/ElasticClient-NodesInfo.cs b/src/Nest/Cluster/NodesInfo/ElasticClient-NodesInfo.cs index 07744a5b554..219ac4ee258 100644 --- a/src/Nest/Cluster/NodesInfo/ElasticClient-NodesInfo.cs +++ b/src/Nest/Cluster/NodesInfo/ElasticClient-NodesInfo.cs @@ -1,56 +1,60 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; namespace Nest { - using System.Threading; using NodesHotThreadConverter = Func; public partial interface IElasticClient { /// /// The cluster nodes info API allows to retrieve one or more (or all) of the cluster nodes information. - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-info.html + /// + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-info.html /// /// An optional descriptor to further describe the nodes info operation INodesInfoResponse NodesInfo(Func selector = null); - /// + /// INodesInfoResponse NodesInfo(INodesInfoRequest request); - /// - Task NodesInfoAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task NodesInfoAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task NodesInfoAsync(INodesInfoRequest request, CancellationToken cancellationToken = default(CancellationToken)); - } public partial class ElasticClient { - /// + /// public INodesInfoResponse NodesInfo(Func selector = null) => - this.NodesInfo(selector.InvokeOrDefault(new NodesInfoDescriptor())); + NodesInfo(selector.InvokeOrDefault(new NodesInfoDescriptor())); - /// + /// public INodesInfoResponse NodesInfo(INodesInfoRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.NodesInfoDispatch(p) + (p, d) => LowLevelDispatch.NodesInfoDispatch(p) ); - /// - public Task NodesInfoAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.NodesInfoAsync(selector.InvokeOrDefault(new NodesInfoDescriptor()), cancellationToken); + /// + public Task NodesInfoAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + NodesInfoAsync(selector.InvokeOrDefault(new NodesInfoDescriptor()), cancellationToken); - /// + /// public Task NodesInfoAsync(INodesInfoRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.NodesInfoDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.NodesInfoDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/NodesInfo/NodeInfo.cs b/src/Nest/Cluster/NodesInfo/NodeInfo.cs index afe0db5db80..d9ae3c7ae5b 100644 --- a/src/Nest/Cluster/NodesInfo/NodeInfo.cs +++ b/src/Nest/Cluster/NodesInfo/NodeInfo.cs @@ -7,23 +7,35 @@ namespace Nest [JsonObject] public class NodeInfo { - [JsonProperty("name")] - public string Name { get; internal set; } - - [JsonProperty("transport_address")] - public string TransportAddress { get; internal set; } + [JsonProperty("build_hash")] + public string BuildHash { get; internal set; } [JsonProperty("host")] public string Host { get; internal set; } + [JsonProperty("http")] + public NodeInfoHttp Http { get; internal set; } + [JsonProperty("ip")] public string Ip { get; internal set; } - [JsonProperty("version")] - public string Version { get; internal set; } + [JsonProperty("jvm")] + public NodeJvmInfo Jvm { get; internal set; } - [JsonProperty("build_hash")] - public string BuildHash { get; internal set; } + [JsonProperty("name")] + public string Name { get; internal set; } + + [JsonProperty("network")] + public NodeInfoNetwork Network { get; internal set; } + + [JsonProperty("os")] + public NodeOperatingSystemInfo OperatingSystem { get; internal set; } + + [JsonProperty("plugins")] + public List Plugins { get; internal set; } + + [JsonProperty("process")] + public NodeProcessInfo Process { get; internal set; } /// /// All of the different roles that the node fulfills. An empty @@ -37,47 +49,26 @@ public class NodeInfo [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public DynamicBody Settings { get; internal set; } - [JsonProperty("os")] - public NodeOperatingSystemInfo OperatingSystem { get; internal set; } - - [JsonProperty("process")] - public NodeProcessInfo Process { get; internal set; } - - [JsonProperty("jvm")] - public NodeJvmInfo Jvm { get; internal set; } - [JsonProperty("thread_pool")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public Dictionary ThreadPool { get; internal set; } - [JsonProperty("network")] - public NodeInfoNetwork Network { get; internal set; } - [JsonProperty("transport")] public NodeInfoTransport Transport { get; internal set; } - [JsonProperty("http")] - public NodeInfoHttp Http { get; internal set; } + [JsonProperty("transport_address")] + public string TransportAddress { get; internal set; } - [JsonProperty("plugins")] - public List Plugins { get; internal set; } + [JsonProperty("version")] + public string Version { get; internal set; } } [JsonObject] public class NodeOperatingSystemInfo { - [JsonProperty("name")] - public string Name { get; internal set; } - [JsonProperty("arch")] public string Architecture { get; internal set; } - [JsonProperty("version")] - public string Version { get; internal set; } - - [JsonProperty("refresh_interval_in_millis")] - public int RefreshInterval { get; internal set; } - [JsonProperty("available_processors")] public int AvailableProcessors { get; internal set; } @@ -87,29 +78,45 @@ public class NodeOperatingSystemInfo [JsonProperty("mem")] public NodeInfoMemory Mem { get; internal set; } + [JsonProperty("name")] + public string Name { get; internal set; } + + [JsonProperty("refresh_interval_in_millis")] + public int RefreshInterval { get; internal set; } + [JsonProperty("swap")] public NodeInfoMemory Swap { get; internal set; } + + [JsonProperty("version")] + public string Version { get; internal set; } } [JsonObject] public class NodeInfoOSCPU { - [JsonProperty("vendor")] - public string Vendor { get; internal set; } - [JsonProperty("model")] - public string Model { get; internal set; } + [JsonProperty("cache_size")] + public string CacheSize { get; internal set; } + + [JsonProperty("cache_size_in_bytes")] + public int CacheSizeInBytes { get; internal set; } + + [JsonProperty("cores_per_socket")] + public int CoresPerSocket { get; internal set; } + [JsonProperty("mhz")] public int Mhz { get; internal set; } + + [JsonProperty("model")] + public string Model { get; internal set; } + [JsonProperty("total_cores")] public int TotalCores { get; internal set; } + [JsonProperty("total_sockets")] public int TotalSockets { get; internal set; } - [JsonProperty("cores_per_socket")] - public int CoresPerSocket { get; internal set; } - [JsonProperty("cache_size")] - public string CacheSize { get; internal set; } - [JsonProperty("cache_size_in_bytes")] - public int CacheSizeInBytes { get; internal set; } + + [JsonProperty("vendor")] + public string Vendor { get; internal set; } } [JsonObject] @@ -117,6 +124,7 @@ public class NodeInfoMemory { [JsonProperty("total")] public string Total { get; internal set; } + [JsonProperty("total_in_bytes")] public long TotalInBytes { get; internal set; } } @@ -124,86 +132,108 @@ public class NodeInfoMemory [JsonObject] public class NodeProcessInfo { - [JsonProperty("refresh_interval_in_millis")] - public long RefreshIntervalInMilliseconds { get; internal set; } - [JsonProperty("id")] public long Id { get; internal set; } [JsonProperty("mlockall")] public bool MlockAll { get; internal set; } + + [JsonProperty("refresh_interval_in_millis")] + public long RefreshIntervalInMilliseconds { get; internal set; } } [JsonObject] public class NodeJvmInfo { + [JsonProperty("gc_collectors")] + public IEnumerable GCCollectors { get; internal set; } + + [JsonProperty("mem")] + public NodeInfoJVMMemory Memory { get; internal set; } + + [JsonProperty("memory_pools")] + public IEnumerable MemoryPools { get; internal set; } + [JsonProperty("pid")] public int PID { get; internal set; } + + [JsonProperty("start_time_in_millis")] + public long StartTime { get; internal set; } + [JsonProperty("version")] public string Version { get; internal set; } + [JsonProperty("vm_name")] public string VMName { get; internal set; } - [JsonProperty("vm_version")] - public string VMVersion { get; internal set; } + [JsonProperty("vm_vendor")] public string VMVendor { get; internal set; } - [JsonProperty("memory_pools")] - public IEnumerable MemoryPools { get; internal set; } - [JsonProperty("gc_collectors")] - public IEnumerable GCCollectors { get; internal set; } - [JsonProperty("start_time_in_millis")] - public long StartTime { get; internal set; } - [JsonProperty("mem")] - public NodeInfoJVMMemory Memory { get; internal set; } + + [JsonProperty("vm_version")] + public string VMVersion { get; internal set; } } [JsonObject] public class NodeInfoJVMMemory { + [JsonProperty("direct_max")] + public string DirectMax { get; internal set; } + + [JsonProperty("direct_max_in_bytes")] + public long DirectMaxInBytes { get; internal set; } + [JsonProperty("heap_init")] public string HeapInit { get; internal set; } + [JsonProperty("heap_init_in_bytes")] public long HeapInitInBytes { get; internal set; } + [JsonProperty("heap_max")] public string HeapMax { get; internal set; } + [JsonProperty("heap_max_in_bytes")] public long HeapMaxInBytes { get; internal set; } + [JsonProperty("non_heap_init")] public string NonHeapInit { get; internal set; } + [JsonProperty("non_heap_init_in_bytes")] public long NonHeapInitInBytes { get; internal set; } + [JsonProperty("non_heap_max")] public string NonHeapMax { get; internal set; } + [JsonProperty("non_heap_max_in_bytes")] public long NonHeapMaxInBytes { get; internal set; } - [JsonProperty("direct_max")] - public string DirectMax { get; internal set; } - [JsonProperty("direct_max_in_bytes")] - public long DirectMaxInBytes { get; internal set; } } [JsonObject] public class NodeThreadPoolInfo { - [JsonProperty("type")] - public string Type { get; internal set; } - [JsonProperty("min")] - public int? Min { get; internal set; } + [JsonProperty("keep_alive")] + public string KeepAlive { get; internal set; } + [JsonProperty("max")] public int? Max { get; internal set; } + + [JsonProperty("min")] + public int? Min { get; internal set; } + [JsonProperty("queue_size")] public int? QueueSize { get; internal set; } - [JsonProperty("keep_alive")] - public string KeepAlive { get; internal set; } + + [JsonProperty("type")] + public string Type { get; internal set; } } [JsonObject] public class NodeInfoNetwork { - [JsonProperty("refresh_interval")] - public int RefreshInterval { get; internal set; } [JsonProperty("primary_interface")] public NodeInfoNetworkInterface PrimaryInterface { get; internal set; } + + [JsonProperty("refresh_interval")] + public int RefreshInterval { get; internal set; } } [JsonObject] @@ -211,10 +241,12 @@ public class NodeInfoNetworkInterface { [JsonProperty("address")] public string Address { get; internal set; } - [JsonProperty("name")] - public string Name { get; internal set; } + [JsonProperty("mac_address")] public string MacAddress { get; internal set; } + + [JsonProperty("name")] + public string Name { get; internal set; } } [JsonObject] @@ -222,6 +254,7 @@ public class NodeInfoTransport { [JsonProperty("bound_address")] public IEnumerable BoundAddress { get; internal set; } + [JsonProperty("publish_address")] public string PublishAddress { get; internal set; } } @@ -231,11 +264,14 @@ public class NodeInfoHttp { [JsonProperty("bound_address")] public IEnumerable BoundAddress { get; internal set; } - [JsonProperty("publish_address")] - public string PublishAddress { get; internal set; } + [JsonProperty("max_content_length")] public string MaxContentLength { get; internal set; } + [JsonProperty("max_content_length_in_bytes")] public long MaxContentLengthInBytes { get; internal set; } + + [JsonProperty("publish_address")] + public string PublishAddress { get; internal set; } } } diff --git a/src/Nest/Cluster/NodesInfo/NodeRole.cs b/src/Nest/Cluster/NodesInfo/NodeRole.cs index f97fcd4e2b6..78055a39d91 100644 --- a/src/Nest/Cluster/NodesInfo/NodeRole.cs +++ b/src/Nest/Cluster/NodesInfo/NodeRole.cs @@ -1,11 +1,6 @@ -using Newtonsoft.Json; +using System.Runtime.Serialization; +using Newtonsoft.Json; using Newtonsoft.Json.Converters; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; namespace Nest { @@ -14,10 +9,13 @@ public enum NodeRole { [EnumMember(Value = "master")] Master, + [EnumMember(Value = "data")] Data, + [EnumMember(Value = "client")] Client, + [EnumMember(Value = "ingest")] Ingest } diff --git a/src/Nest/Cluster/NodesInfo/NodesInfoResponse.cs b/src/Nest/Cluster/NodesInfo/NodesInfoResponse.cs index 501a6ace95c..a199f187431 100644 --- a/src/Nest/Cluster/NodesInfo/NodesInfoResponse.cs +++ b/src/Nest/Cluster/NodesInfo/NodesInfoResponse.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Elasticsearch.Net; using Newtonsoft.Json; namespace Nest @@ -20,6 +19,4 @@ public class NodesInfoResponse : NodesResponseBase, INodesInfoResponse [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public IReadOnlyDictionary Nodes { get; internal set; } = EmptyReadOnly.Dictionary; } - - } diff --git a/src/Nest/Cluster/NodesResponseBase.cs b/src/Nest/Cluster/NodesResponseBase.cs index 89450aaa74c..c52a27454c1 100644 --- a/src/Nest/Cluster/NodesResponseBase.cs +++ b/src/Nest/Cluster/NodesResponseBase.cs @@ -6,6 +6,7 @@ public abstract class NodesResponseBase : ResponseBase, INodesResponse { public NodeStatistics NodeStatistics { get; internal set; } } + public interface INodesResponse : IResponse { [JsonProperty("_nodes")] @@ -16,15 +17,14 @@ public interface INodesResponse : IResponse public class NodeStatistics { [JsonProperty] - public int Total { get; internal set; } + public int Failed { get; internal set; } [JsonProperty] public int Successful { get; internal set; } [JsonProperty] - public int Failed { get; internal set; } + public int Total { get; internal set; } //TODO map failures - } } diff --git a/src/Nest/Cluster/NodesStats/AdaptiveSelectionStats.cs b/src/Nest/Cluster/NodesStats/AdaptiveSelectionStats.cs index 20bd34133d4..67bfa972826 100644 --- a/src/Nest/Cluster/NodesStats/AdaptiveSelectionStats.cs +++ b/src/Nest/Cluster/NodesStats/AdaptiveSelectionStats.cs @@ -5,18 +5,25 @@ namespace Nest [JsonObject] public class AdaptiveSelectionStats { - /// - /// The number of outstanding search requests from the node these stats are for to the keyed node. - /// - [JsonProperty("outgoing_searches")] - public long OutgoingSearches { get; internal set; } - /// /// The exponentially weighted moving average queue size of search requests on the keyed node. /// [JsonProperty("avg_queue_size")] public long AverageQueueSize { get; internal set; } + /// + /// The exponentially weighted moving average response time of search requests on the keyed node. + /// + /// only set when requesting human readable response + [JsonProperty("avg_response_time")] + public long AverageResponseTime { get; internal set; } + + /// + /// The exponentially weighted moving average response time of search requests on the keyed node. + /// + [JsonProperty("avg_response_time_ns")] + public long AverageResponseTimeInNanoseconds { get; internal set; } + /// /// The exponentially weighted moving average service time of search requests on the keyed node. /// @@ -31,17 +38,10 @@ public class AdaptiveSelectionStats public long AverageServiceTimeInNanoseconds { get; internal set; } /// - /// The exponentially weighted moving average response time of search requests on the keyed node. - /// - /// only set when requesting human readable response - [JsonProperty("avg_response_time")] - public long AverageResponseTime { get; internal set; } - - /// - /// The exponentially weighted moving average response time of search requests on the keyed node. + /// The number of outstanding search requests from the node these stats are for to the keyed node. /// - [JsonProperty("avg_response_time_ns")] - public long AverageResponseTimeInNanoseconds { get; internal set; } + [JsonProperty("outgoing_searches")] + public long OutgoingSearches { get; internal set; } /// /// The rank of this node; used for shard selection when routing search requests. @@ -49,4 +49,4 @@ public class AdaptiveSelectionStats [JsonProperty("rank")] public string Rank { get; internal set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cluster/NodesStats/ElasticClient-NodesStats.cs b/src/Nest/Cluster/NodesStats/ElasticClient-NodesStats.cs index 439782f631f..90bbb961b38 100644 --- a/src/Nest/Cluster/NodesStats/ElasticClient-NodesStats.cs +++ b/src/Nest/Cluster/NodesStats/ElasticClient-NodesStats.cs @@ -1,55 +1,61 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; namespace Nest { - using System.Threading; using NodesHotThreadConverter = Func; public partial interface IElasticClient { /// /// The cluster nodes stats API allows to retrieve one or more (or all) of the cluster nodes statistics. - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html + /// + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html /// /// An optional descriptor to further describe the nodes stats operation INodesStatsResponse NodesStats(Func selector = null); - /// + /// INodesStatsResponse NodesStats(INodesStatsRequest request); - /// - Task NodesStatsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task NodesStatsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task NodesStatsAsync(INodesStatsRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public INodesStatsResponse NodesStats(Func selector = null) => - this.NodesStats(selector.InvokeOrDefault(new NodesStatsDescriptor())); + NodesStats(selector.InvokeOrDefault(new NodesStatsDescriptor())); - /// + /// public INodesStatsResponse NodesStats(INodesStatsRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.NodesStatsDispatch(p) + (p, d) => LowLevelDispatch.NodesStatsDispatch(p) ); - /// - public Task NodesStatsAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.NodesStatsAsync(selector.InvokeOrDefault(new NodesStatsDescriptor()), cancellationToken); + /// + public Task NodesStatsAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + NodesStatsAsync(selector.InvokeOrDefault(new NodesStatsDescriptor()), cancellationToken); - /// - public Task NodesStatsAsync(INodesStatsRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task NodesStatsAsync(INodesStatsRequest request, CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.NodesStatsDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.NodesStatsDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/NodesStats/NodeStats.cs b/src/Nest/Cluster/NodesStats/NodeStats.cs index c3155ab06a5..9c505954cf8 100644 --- a/src/Nest/Cluster/NodesStats/NodeStats.cs +++ b/src/Nest/Cluster/NodesStats/NodeStats.cs @@ -6,31 +6,39 @@ namespace Nest [JsonObject] public class NodeStats { - [JsonProperty("timestamp")] - public long Timestamp { get; internal set; } + [JsonProperty("adaptive_selection")] + [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] + public IReadOnlyDictionary AdaptiveSelection { get; internal set; } + = EmptyReadOnly.Dictionary; - [JsonProperty("name")] - public string Name { get; internal set; } + [JsonProperty("breakers")] + [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] + public Dictionary Breakers { get; internal set; } - [JsonProperty("transport_address")] - public string TransportAddress { get; internal set; } + [JsonProperty("fs")] + public FileSystemStats FileSystem { get; internal set; } [JsonProperty("host")] public string Host { get; internal set; } + [JsonProperty("http")] + public HttpStats Http { get; internal set; } + + [JsonProperty("indices")] + public IndexStats Indices { get; internal set; } + + [JsonProperty("ingest")] + public NodeIngestStats Ingest { get; internal set; } + [JsonProperty("ip")] [JsonConverter(typeof(ReadSingleOrEnumerableJsonConverter))] public IEnumerable Ip { get; internal set; } - /// - /// All of the different roles that the node fulfills. An empty - /// collection means that the node is a coordinating only node. - /// - [JsonProperty("roles")] - public IEnumerable Roles { get; internal set; } + [JsonProperty("jvm")] + public NodeJvmStats Jvm { get; internal set; } - [JsonProperty("indices")] - public IndexStats Indices { get; internal set; } + [JsonProperty("name")] + public string Name { get; internal set; } [JsonProperty("os")] public OperatingSystemStats OperatingSystem { get; internal set; } @@ -38,36 +46,28 @@ public class NodeStats [JsonProperty("process")] public ProcessStats Process { get; internal set; } + /// + /// All of the different roles that the node fulfills. An empty + /// collection means that the node is a coordinating only node. + /// + [JsonProperty("roles")] + public IEnumerable Roles { get; internal set; } + [JsonProperty("script")] public ScriptStats Script { get; internal set; } - [JsonProperty("jvm")] - public NodeJvmStats Jvm { get; internal set; } - [JsonProperty("thread_pool")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public Dictionary ThreadPool { get; internal set; } - [JsonProperty("breakers")] - [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] - public Dictionary Breakers { get; internal set; } - - [JsonProperty("fs")] - public FileSystemStats FileSystem { get; internal set; } + [JsonProperty("timestamp")] + public long Timestamp { get; internal set; } [JsonProperty("transport")] public TransportStats Transport { get; internal set; } - [JsonProperty("http")] - public HttpStats Http { get; internal set; } - - [JsonProperty("ingest")] - public NodeIngestStats Ingest { get; internal set; } - - [JsonProperty("adaptive_selection")] - [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] - public IReadOnlyDictionary AdaptiveSelection { get; internal set; } - = EmptyReadOnly.Dictionary; + [JsonProperty("transport_address")] + public string TransportAddress { get; internal set; } } @@ -76,6 +76,7 @@ public class ScriptStats { [JsonProperty("cache_evictions")] public long CacheEvictions { get; internal set; } + [JsonProperty("compilations")] public long Compilations { get; internal set; } } @@ -85,14 +86,19 @@ public class BreakerStats { [JsonProperty("estimated_size")] public string EstimatedSize { get; internal set; } + [JsonProperty("estimated_size_in_bytes")] public long EstimatedSizeInBytes { get; internal set; } + [JsonProperty("limit_size")] public string LimitSize { get; internal set; } + [JsonProperty("limit_size_in_bytes")] public long LimitSizeInBytes { get; internal set; } + [JsonProperty("overhead")] public float Overhead { get; internal set; } + [JsonProperty("tripped")] public float Tripped { get; internal set; } } @@ -100,16 +106,17 @@ public class BreakerStats [JsonObject] public class OperatingSystemStats { - [JsonProperty("timestamp")] - public long Timestamp { get; internal set; } + [JsonProperty("cpu")] + public CPUStats Cpu { get; internal set; } [JsonProperty("mem")] public ExtendedMemoryStats Memory { get; internal set; } + [JsonProperty("swap")] public MemoryStats Swap { get; internal set; } - [JsonProperty("cpu")] - public CPUStats Cpu { get; internal set; } + [JsonProperty("timestamp")] + public long Timestamp { get; internal set; } [JsonObject] public class CPUStats @@ -123,32 +130,32 @@ public class CPUStats [JsonObject] public class LoadAverageStats { - [JsonProperty("1m")] - public float? OneMinute { get; internal set; } + [JsonProperty("15m")] + public float? FifteenMinute { get; internal set; } [JsonProperty("5m")] public float? FiveMinute { get; internal set; } - [JsonProperty("15m")] - public float? FifteenMinute { get; internal set; } + [JsonProperty("1m")] + public float? OneMinute { get; internal set; } } } [JsonObject] public class MemoryStats { - [JsonProperty("total")] - public string Total { get; internal set; } - - [JsonProperty("total_in_bytes")] - public long TotalInBytes { get; internal set; } - [JsonProperty("free")] public string Free { get; internal set; } [JsonProperty("free_in_bytes")] public long FreeInBytes { get; internal set; } + [JsonProperty("total")] + public string Total { get; internal set; } + + [JsonProperty("total_in_bytes")] + public long TotalInBytes { get; internal set; } + [JsonProperty("used")] public string Used { get; internal set; } @@ -161,6 +168,7 @@ public class ExtendedMemoryStats : MemoryStats { [JsonProperty("free_percent")] public int FreePercent { get; internal set; } + [JsonProperty("used_percent")] public int UsedPercent { get; internal set; } } @@ -169,33 +177,41 @@ public class ExtendedMemoryStats : MemoryStats [JsonObject] public class ProcessStats { - [JsonProperty("timestamp")] - public long Timestamp { get; internal set; } - [JsonProperty("open_file_descriptors")] - public int OpenFileDescriptors { get; internal set; } - [JsonProperty("cpu")] public CPUStats CPU { get; internal set; } + [JsonProperty("mem")] public MemoryStats Memory { get; internal set; } + [JsonProperty("open_file_descriptors")] + public int OpenFileDescriptors { get; internal set; } + + [JsonProperty("timestamp")] + public long Timestamp { get; internal set; } + [JsonObject] public class CPUStats { [JsonProperty("percent")] public int Percent { get; internal set; } + [JsonProperty("sys")] public string System { get; internal set; } + [JsonProperty("sys_in_millis")] public long SystemInMilliseconds { get; internal set; } - [JsonProperty("user")] - public string User { get; internal set; } - [JsonProperty("user_in_millis")] - public long UserInMilliseconds { get; internal set; } + [JsonProperty("total")] public string Total { get; internal set; } + [JsonProperty("total_in_millis")] public long TotalInMilliseconds { get; internal set; } + + [JsonProperty("user")] + public string User { get; internal set; } + + [JsonProperty("user_in_millis")] + public long UserInMilliseconds { get; internal set; } } [JsonObject] @@ -203,14 +219,19 @@ public class MemoryStats { [JsonProperty("resident")] public string Resident { get; internal set; } + [JsonProperty("resident_in_bytes")] public long ResidentInBytes { get; internal set; } + [JsonProperty("share")] public string Share { get; internal set; } + [JsonProperty("share_in_bytes")] public long ShareInBytes { get; internal set; } + [JsonProperty("total_virtual")] public string TotalVirtual { get; internal set; } + [JsonProperty("total_virtual_in_bytes")] public long TotalVirtualInBytes { get; internal set; } } @@ -219,19 +240,6 @@ public class MemoryStats [JsonObject] public class NodeJvmStats { - [JsonProperty("timestamp")] - public long Timestamp { get; internal set; } - [JsonProperty("uptime")] - public string Uptime { get; internal set; } - [JsonProperty("uptime_in_millis")] - public long UptimeInMilliseconds { get; internal set; } - [JsonProperty("mem")] - public MemoryStats Memory { get; internal set; } - [JsonProperty("threads")] - public ThreadStats Threads { get; internal set; } - [JsonProperty("gc")] - public GarbageCollectionStats GarbageCollection { get; internal set; } - [JsonProperty("buffer_pools")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public Dictionary BufferPools { get; internal set; } @@ -239,13 +247,33 @@ public class NodeJvmStats [JsonProperty("classes")] public JvmClassesStats Classes { get; internal set; } + [JsonProperty("gc")] + public GarbageCollectionStats GarbageCollection { get; internal set; } + + [JsonProperty("mem")] + public MemoryStats Memory { get; internal set; } + + [JsonProperty("threads")] + public ThreadStats Threads { get; internal set; } + + [JsonProperty("timestamp")] + public long Timestamp { get; internal set; } + + [JsonProperty("uptime")] + public string Uptime { get; internal set; } + + [JsonProperty("uptime_in_millis")] + public long UptimeInMilliseconds { get; internal set; } + [JsonObject] public class JvmClassesStats { [JsonProperty("current_loaded_count")] public long CurrentLoadedCount { get; internal set; } + [JsonProperty("total_loaded_count")] public long TotalLoadedCount { get; internal set; } + [JsonProperty("total_unloaded_count")] public long TotalUnloadedCount { get; internal set; } } @@ -253,28 +281,39 @@ public class JvmClassesStats [JsonObject] public class MemoryStats { - [JsonProperty("heap_used")] - public string HeapUsed { get; internal set; } - [JsonProperty("heap_used_in_bytes")] - public long HeapUsedInBytes { get; internal set; } - [JsonProperty("heap_used_percent")] - public long HeapUsedPercent { get; internal set; } [JsonProperty("heap_committed")] public string HeapCommitted { get; internal set; } + [JsonProperty("heap_committed_in_bytes")] public long HeapCommittedInBytes { get; internal set; } + [JsonProperty("heap_max")] public string HeapMax { get; internal set; } + [JsonProperty("heap_max_in_bytes")] public long HeapMaxInBytes { get; internal set; } - [JsonProperty("non_heap_used")] - public string NonHeapUsed { get; internal set; } - [JsonProperty("non_heap_used_in_bytes")] - public long NonHeapUsedInBytes { get; internal set; } + + [JsonProperty("heap_used")] + public string HeapUsed { get; internal set; } + + [JsonProperty("heap_used_in_bytes")] + public long HeapUsedInBytes { get; internal set; } + + [JsonProperty("heap_used_percent")] + public long HeapUsedPercent { get; internal set; } + [JsonProperty("non_heap_committed")] public string NonHeapCommitted { get; internal set; } + [JsonProperty("non_heap_committed_in_bytes")] public long NonHeapCommittedInBytes { get; internal set; } + + [JsonProperty("non_heap_used")] + public string NonHeapUsed { get; internal set; } + + [JsonProperty("non_heap_used_in_bytes")] + public long NonHeapUsedInBytes { get; internal set; } + [JsonProperty("pools")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public Dictionary Pools { get; internal set; } @@ -282,22 +321,29 @@ public class MemoryStats [JsonObject] public class JVMPool { - [JsonProperty("used")] - public string Used { get; internal set; } - [JsonProperty("used_in_bytes")] - public long UsedInBytes { get; internal set; } [JsonProperty("max")] public string Max { get; internal set; } + [JsonProperty("max_in_bytes")] public long MaxInBytes { get; internal set; } - [JsonProperty("peak_used")] - public string PeakUsed { get; internal set; } - [JsonProperty("peak_used_in_bytes")] - public long PeakUsedInBytes { get; internal set; } + [JsonProperty("peak_max")] public string PeakMax { get; internal set; } + [JsonProperty("peak_max_in_bytes")] public long PeakMaxInBytes { get; internal set; } + + [JsonProperty("peak_used")] + public string PeakUsed { get; internal set; } + + [JsonProperty("peak_used_in_bytes")] + public long PeakUsedInBytes { get; internal set; } + + [JsonProperty("used")] + public string Used { get; internal set; } + + [JsonProperty("used_in_bytes")] + public long UsedInBytes { get; internal set; } } } @@ -306,6 +352,7 @@ public class ThreadStats { [JsonProperty("count")] public long Count { get; internal set; } + [JsonProperty("peak_count")] public long PeakCount { get; internal set; } } @@ -323,8 +370,10 @@ public class GarbageCollectionGenerationStats { [JsonProperty("collection_count")] public long CollectionCount { get; internal set; } + [JsonProperty("collection_time")] public string CollectionTime { get; internal set; } + [JsonProperty("collection_time_in_millis")] public long CollectionTimeInMilliseconds { get; internal set; } } @@ -334,58 +383,72 @@ public class NodeBufferPool { [JsonProperty("count")] public long Count { get; internal set; } - [JsonProperty("used")] - public string Used { get; internal set; } - [JsonProperty("used_in_bytes")] - public long UsedInBytes { get; internal set; } + [JsonProperty("total_capacity")] public string TotalCapacity { get; internal set; } + [JsonProperty("total_capacity_in_bytes")] public long TotalCapacityInBytes { get; internal set; } + + [JsonProperty("used")] + public string Used { get; internal set; } + + [JsonProperty("used_in_bytes")] + public long UsedInBytes { get; internal set; } } } [JsonObject] public class ThreadCountStats { - [JsonProperty("threads")] - public long Threads { get; internal set; } - [JsonProperty("queue")] - public long Queue { get; internal set; } [JsonProperty("active")] public long Active { get; internal set; } - [JsonProperty("rejected")] - public long Rejected { get; internal set; } - [JsonProperty("largest")] - public long Largest { get; internal set; } + [JsonProperty("completed")] public long Completed { get; internal set; } + + [JsonProperty("largest")] + public long Largest { get; internal set; } + + [JsonProperty("queue")] + public long Queue { get; internal set; } + + [JsonProperty("rejected")] + public long Rejected { get; internal set; } + + [JsonProperty("threads")] + public long Threads { get; internal set; } } [JsonObject] public class FileSystemStats { + [JsonProperty("data")] + public IEnumerable Data { get; internal set; } + [JsonProperty("timestamp")] public long Timestamp { get; internal set; } + [JsonProperty("total")] public TotalFileSystemStats Total { get; internal set; } - [JsonProperty("data")] - public IEnumerable Data { get; internal set; } public class TotalFileSystemStats { [JsonProperty("available")] public string Available { get; internal set; } + [JsonProperty("available_in_bytes")] public long AvailableInBytes { get; internal set; } [JsonProperty("free")] public string Free { get; internal set; } + [JsonProperty("free_in_bytes")] public long FreeInBytes { get; internal set; } [JsonProperty("total")] public string Total { get; internal set; } + [JsonProperty("total_in_bytes")] public long TotalInBytes { get; internal set; } } @@ -393,56 +456,77 @@ public class TotalFileSystemStats [JsonObject] public class DataPathStats { - [JsonProperty("path")] - public string Path { get; internal set; } - [JsonProperty("mount")] - public string Mount { get; internal set; } - [JsonProperty("type")] - public string Type { get; internal set; } - [JsonProperty("total")] - public string Total { get; internal set; } - [JsonProperty("total_in_bytes")] - public long TotalInBytes { get; internal set; } - [JsonProperty("free")] - public string Free { get; internal set; } - [JsonProperty("free_in_bytes")] - public long FreeInBytes { get; internal set; } [JsonProperty("available")] public string Available { get; internal set; } + [JsonProperty("available_in_bytes")] public long AvailableInBytes { get; internal set; } + + [JsonProperty("disk_queue")] + public string DiskQueue { get; internal set; } + [JsonProperty("disk_reads")] public long DiskReads { get; internal set; } - [JsonProperty("disk_writes")] - public long DiskWrites { get; internal set; } + [JsonProperty("disk_read_size")] public string DiskReadSize { get; internal set; } + [JsonProperty("disk_read_size_in_bytes")] public long DiskReadSizeInBytes { get; internal set; } + + [JsonProperty("disk_writes")] + public long DiskWrites { get; internal set; } + [JsonProperty("disk_write_size")] public string DiskWriteSize { get; internal set; } + [JsonProperty("disk_write_size_in_bytes")] public long DiskWriteSizeInBytes { get; internal set; } - [JsonProperty("disk_queue")] - public string DiskQueue { get; internal set; } + + [JsonProperty("free")] + public string Free { get; internal set; } + + [JsonProperty("free_in_bytes")] + public long FreeInBytes { get; internal set; } + + [JsonProperty("mount")] + public string Mount { get; internal set; } + + [JsonProperty("path")] + public string Path { get; internal set; } + + [JsonProperty("total")] + public string Total { get; internal set; } + + [JsonProperty("total_in_bytes")] + public long TotalInBytes { get; internal set; } + + [JsonProperty("type")] + public string Type { get; internal set; } } } [JsonObject] public class TransportStats { - [JsonProperty("server_open")] - public int ServerOpen { get; internal set; } [JsonProperty("rx_count")] public long RXCount { get; internal set; } + [JsonProperty("rx_size")] public string RXSize { get; internal set; } + [JsonProperty("rx_size_in_bytes")] public long RXSizeInBytes { get; internal set; } + + [JsonProperty("server_open")] + public int ServerOpen { get; internal set; } + [JsonProperty("tx_count")] public long TXCount { get; internal set; } + [JsonProperty("tx_size")] public string TXSize { get; internal set; } + [JsonProperty("tx_size_in_bytes")] public long TXSizeInBytes { get; internal set; } } @@ -452,6 +536,7 @@ public class HttpStats { [JsonProperty("current_open")] public int CurrentOpen { get; internal set; } + [JsonProperty("total_opened")] public long TotalOpened { get; internal set; } } diff --git a/src/Nest/Cluster/NodesStats/NodeStatsResponse.cs b/src/Nest/Cluster/NodesStats/NodeStatsResponse.cs index d934a39c0b4..38b62fe687d 100644 --- a/src/Nest/Cluster/NodesStats/NodeStatsResponse.cs +++ b/src/Nest/Cluster/NodesStats/NodeStatsResponse.cs @@ -18,6 +18,5 @@ public class NodesStatsResponse : NodesResponseBase, INodesStatsResponse public string ClusterName { get; internal set; } public IReadOnlyDictionary Nodes { get; internal set; } = EmptyReadOnly.Dictionary; - } } diff --git a/src/Nest/Cluster/NodesStats/Statistics/IngestStats.cs b/src/Nest/Cluster/NodesStats/Statistics/IngestStats.cs index 30683ca9ce2..46afb481de6 100644 --- a/src/Nest/Cluster/NodesStats/Statistics/IngestStats.cs +++ b/src/Nest/Cluster/NodesStats/Statistics/IngestStats.cs @@ -11,12 +11,6 @@ public class IngestStats [JsonProperty("count")] public long Count { get; set; } - /// - /// The total time spent on ingest preprocessing documents during the lifetime of this node - /// - [JsonProperty("time_in_millis")] - public long TimeInMilliseconds { get; set; } - /// /// The total number of documents currently being ingested. /// @@ -28,5 +22,11 @@ public class IngestStats /// [JsonProperty("failed")] public long Failed { get; set; } + + /// + /// The total time spent on ingest preprocessing documents during the lifetime of this node + /// + [JsonProperty("time_in_millis")] + public long TimeInMilliseconds { get; set; } } } diff --git a/src/Nest/Cluster/NodesStats/Statistics/NodeIngestStats.cs b/src/Nest/Cluster/NodesStats/Statistics/NodeIngestStats.cs index 3fac482f7dd..ac076625019 100644 --- a/src/Nest/Cluster/NodesStats/Statistics/NodeIngestStats.cs +++ b/src/Nest/Cluster/NodesStats/Statistics/NodeIngestStats.cs @@ -5,14 +5,14 @@ namespace Nest { public class NodeIngestStats { - /// Overal global ingest statistics - [JsonProperty("total")] - public IngestStats Total { get; set; } - /// Per pipeline ingest statistics [JsonProperty("pipelines")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public IReadOnlyDictionary Pipelines { get; internal set; } = EmptyReadOnly.Dictionary; + + /// Overal global ingest statistics + [JsonProperty("total")] + public IngestStats Total { get; set; } } } diff --git a/src/Nest/Cluster/NodesUsage/ElasticClient-NodesUsage.cs b/src/Nest/Cluster/NodesUsage/ElasticClient-NodesUsage.cs index 8c75b05cf8f..b51741e15f7 100644 --- a/src/Nest/Cluster/NodesUsage/ElasticClient-NodesUsage.cs +++ b/src/Nest/Cluster/NodesUsage/ElasticClient-NodesUsage.cs @@ -1,55 +1,61 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; namespace Nest { - using System.Threading; using NodesHotThreadConverter = Func; public partial interface IElasticClient { /// /// The cluster nodes usage API allows to retrieve information on the usage of features for each node. - /// https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-usage.html + /// + /// https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-usage.html /// /// An optional descriptor to further describe the nodes usage operation INodesUsageResponse NodesUsage(Func selector = null); - /// + /// INodesUsageResponse NodesUsage(INodesUsageRequest request); - /// - Task NodesUsageAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task NodesUsageAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task NodesUsageAsync(INodesUsageRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public INodesUsageResponse NodesUsage(Func selector = null) => - this.NodesUsage(selector.InvokeOrDefault(new NodesUsageDescriptor())); + NodesUsage(selector.InvokeOrDefault(new NodesUsageDescriptor())); - /// + /// public INodesUsageResponse NodesUsage(INodesUsageRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.NodesUsageDispatch(p) + (p, d) => LowLevelDispatch.NodesUsageDispatch(p) ); - /// - public Task NodesUsageAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.NodesUsageAsync(selector.InvokeOrDefault(new NodesUsageDescriptor()), cancellationToken); + /// + public Task NodesUsageAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + NodesUsageAsync(selector.InvokeOrDefault(new NodesUsageDescriptor()), cancellationToken); - /// - public Task NodesUsageAsync(INodesUsageRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task NodesUsageAsync(INodesUsageRequest request, CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.NodesUsageDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.NodesUsageDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs b/src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs index 4fc69e47dda..0c8da6e12df 100644 --- a/src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs +++ b/src/Nest/Cluster/NodesUsage/NodeUsageInformation.cs @@ -6,15 +6,15 @@ namespace Nest { public class NodeUsageInformation { - [JsonProperty("timestamp")] - [JsonConverter(typeof(EpochMillisecondsDateTimeJsonConverter))] - public DateTimeOffset Timestamp { get; internal set; } + [JsonProperty("rest_actions")] + public IReadOnlyDictionary RestActions { get; internal set; } [JsonProperty("since")] [JsonConverter(typeof(EpochMillisecondsDateTimeJsonConverter))] - public DateTimeOffset Since { get; internal set; } + public DateTimeOffset Since { get; internal set; } - [JsonProperty("rest_actions")] - public IReadOnlyDictionary RestActions { get; internal set; } + [JsonProperty("timestamp")] + [JsonConverter(typeof(EpochMillisecondsDateTimeJsonConverter))] + public DateTimeOffset Timestamp { get; internal set; } } -} \ No newline at end of file +} diff --git a/src/Nest/Cluster/NodesUsage/NodeUsageResponse.cs b/src/Nest/Cluster/NodesUsage/NodeUsageResponse.cs index 0684bbc9487..0ca6dfdd9b4 100644 --- a/src/Nest/Cluster/NodesUsage/NodeUsageResponse.cs +++ b/src/Nest/Cluster/NodesUsage/NodeUsageResponse.cs @@ -16,6 +16,7 @@ public class NodesUsageResponse : NodesResponseBase, INodesUsageResponse public string ClusterName { get; internal set; } [JsonProperty("nodes")] - public IReadOnlyDictionary Nodes { get; internal set; } = EmptyReadOnly.Dictionary; + public IReadOnlyDictionary Nodes { get; internal set; } = + EmptyReadOnly.Dictionary; } } diff --git a/src/Nest/Cluster/Ping/ElasticClient-Ping.cs b/src/Nest/Cluster/Ping/ElasticClient-Ping.cs index 18112bcf3d0..42bdefb4f2c 100644 --- a/src/Nest/Cluster/Ping/ElasticClient-Ping.cs +++ b/src/Nest/Cluster/Ping/ElasticClient-Ping.cs @@ -1,11 +1,11 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; namespace Nest { - using System.Threading; using PingConverter = Func; public partial interface IElasticClient @@ -15,45 +15,50 @@ public partial interface IElasticClient /// IPingResponse Ping(Func selector = null); - /// - Task PingAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task PingAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// IPingResponse Ping(IPingRequest request); - /// + /// Task PingAsync(IPingRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public IPingResponse Ping(Func selector = null) => - this.Ping(selector.InvokeOrDefault(new PingDescriptor())); + Ping(selector.InvokeOrDefault(new PingDescriptor())); - /// - public Task PingAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.PingAsync(selector.InvokeOrDefault(new PingDescriptor()), cancellationToken); - - /// + /// public IPingResponse Ping(IPingRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( SetPingTimeout(request), - (p, d) => this.LowLevelDispatch.PingDispatch(p) + (p, d) => LowLevelDispatch.PingDispatch(p) ); - /// + /// + public Task PingAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + PingAsync(selector.InvokeOrDefault(new PingDescriptor()), cancellationToken); + + /// public Task PingAsync(IPingRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + Dispatcher.DispatchAsync( SetPingTimeout(request), cancellationToken, - (p, d, c) => this.LowLevelDispatch.PingDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.PingDispatchAsync(p, c) ); private IPingRequest SetPingTimeout(IPingRequest pingRequest) { - if (!this.ConnectionSettings.PingTimeout.HasValue) return pingRequest; - var timeout = this.ConnectionSettings.PingTimeout.Value; + if (!ConnectionSettings.PingTimeout.HasValue) return pingRequest; + + var timeout = ConnectionSettings.PingTimeout.Value; return ForceConfiguration(pingRequest, r => r.RequestTimeout = timeout); } } diff --git a/src/Nest/Cluster/Ping/PingResponse.cs b/src/Nest/Cluster/Ping/PingResponse.cs index dc8c58b67d6..dd19ae33854 100644 --- a/src/Nest/Cluster/Ping/PingResponse.cs +++ b/src/Nest/Cluster/Ping/PingResponse.cs @@ -2,12 +2,8 @@ namespace Nest { - public interface IPingResponse : IResponse - { - } + public interface IPingResponse : IResponse { } [JsonObject] - public class PingResponse : ResponseBase, IPingResponse - { - } + public class PingResponse : ResponseBase, IPingResponse { } } diff --git a/src/Nest/Cluster/RemoteInfo/ElasticClient-RemoteInfo.cs b/src/Nest/Cluster/RemoteInfo/ElasticClient-RemoteInfo.cs index cb85115088e..4c938e7addd 100644 --- a/src/Nest/Cluster/RemoteInfo/ElasticClient-RemoteInfo.cs +++ b/src/Nest/Cluster/RemoteInfo/ElasticClient-RemoteInfo.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -9,44 +9,50 @@ public partial interface IElasticClient { /// /// The cluster remote info API allows to retrieve all of the configured remote cluster information. - /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/remote-info.html + /// + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/remote-info.html /// /// An optional descriptor to further describe the remote info operation IRemoteInfoResponse RemoteInfo(Func selector = null); - /// + /// IRemoteInfoResponse RemoteInfo(IRemoteInfoRequest request); - /// - Task RemoteInfoAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task RemoteInfoAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task RemoteInfoAsync(IRemoteInfoRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public IRemoteInfoResponse RemoteInfo(Func selector = null) => - this.RemoteInfo(selector.InvokeOrDefault(new RemoteInfoDescriptor())); + RemoteInfo(selector.InvokeOrDefault(new RemoteInfoDescriptor())); - /// + /// public IRemoteInfoResponse RemoteInfo(IRemoteInfoRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.ClusterRemoteInfoDispatch(p) + (p, d) => LowLevelDispatch.ClusterRemoteInfoDispatch(p) ); - /// - public Task RemoteInfoAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.RemoteInfoAsync(selector.InvokeOrDefault(new RemoteInfoDescriptor()), cancellationToken); + /// + public Task RemoteInfoAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + RemoteInfoAsync(selector.InvokeOrDefault(new RemoteInfoDescriptor()), cancellationToken); - /// - public Task RemoteInfoAsync(IRemoteInfoRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task RemoteInfoAsync(IRemoteInfoRequest request, CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.ClusterRemoteInfoDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.ClusterRemoteInfoDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/RemoteInfo/RemoteInfoResponse.cs b/src/Nest/Cluster/RemoteInfo/RemoteInfoResponse.cs index 66acf43a99b..156859e6f67 100644 --- a/src/Nest/Cluster/RemoteInfo/RemoteInfoResponse.cs +++ b/src/Nest/Cluster/RemoteInfo/RemoteInfoResponse.cs @@ -5,7 +5,7 @@ namespace Nest { public interface IRemoteInfoResponse : IResponse { - IReadOnlyDictionary Remotes { get; } + IReadOnlyDictionary Remotes { get; } } [JsonObject] @@ -20,17 +20,20 @@ public class RemoteInfo { [JsonProperty("connected")] public bool Connected { get; internal set; } - [JsonProperty("num_nodes_connected")] - public long NumNodesConnected { get; internal set; } - [JsonProperty("max_connections_per_cluster")] - public int MaxConnectionsPerCluster { get; internal set; } + + [JsonProperty("http_addresses")] + public IReadOnlyCollection HttpAddresses { get; internal set; } = EmptyReadOnly.Collection; + [JsonProperty("initial_connect_timeout")] public Time InitialConnectTimeout { get; internal set; } - [JsonProperty("seeds")] - public IReadOnlyCollection Seeds { get; internal set; }= EmptyReadOnly.Collection; + [JsonProperty("max_connections_per_cluster")] + public int MaxConnectionsPerCluster { get; internal set; } - [JsonProperty("http_addresses")] - public IReadOnlyCollection HttpAddresses { get; internal set; }= EmptyReadOnly.Collection; + [JsonProperty("num_nodes_connected")] + public long NumNodesConnected { get; internal set; } + + [JsonProperty("seeds")] + public IReadOnlyCollection Seeds { get; internal set; } = EmptyReadOnly.Collection; } } diff --git a/src/Nest/Cluster/RootNodeInfo/ElasticClient-RootNodeInfo.cs b/src/Nest/Cluster/RootNodeInfo/ElasticClient-RootNodeInfo.cs index b0409717f47..d27d9a238d7 100644 --- a/src/Nest/Cluster/RootNodeInfo/ElasticClient-RootNodeInfo.cs +++ b/src/Nest/Cluster/RootNodeInfo/ElasticClient-RootNodeInfo.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -13,39 +13,45 @@ public partial interface IElasticClient /// A descriptor to further describe the root operation IRootNodeInfoResponse RootNodeInfo(Func selector = null); - /// + /// IRootNodeInfoResponse RootNodeInfo(IRootNodeInfoRequest request); - /// - Task RootNodeInfoAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task RootNodeInfoAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task RootNodeInfoAsync(IRootNodeInfoRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public IRootNodeInfoResponse RootNodeInfo(Func selector = null) => - this.RootNodeInfo(selector.InvokeOrDefault(new RootNodeInfoDescriptor())); + RootNodeInfo(selector.InvokeOrDefault(new RootNodeInfoDescriptor())); - /// + /// public IRootNodeInfoResponse RootNodeInfo(IRootNodeInfoRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.InfoDispatch(p) + (p, d) => LowLevelDispatch.InfoDispatch(p) ); - /// - public Task RootNodeInfoAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.RootNodeInfoAsync(selector.InvokeOrDefault(new RootNodeInfoDescriptor()), cancellationToken); - - /// - public Task RootNodeInfoAsync(IRootNodeInfoRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task RootNodeInfoAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + RootNodeInfoAsync(selector.InvokeOrDefault(new RootNodeInfoDescriptor()), cancellationToken); + + /// + public Task RootNodeInfoAsync(IRootNodeInfoRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.InfoDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.InfoDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/RootNodeInfo/RootVersionInfoResponse.cs b/src/Nest/Cluster/RootNodeInfo/RootVersionInfoResponse.cs index c0999df2f05..3b7de83a6f9 100644 --- a/src/Nest/Cluster/RootNodeInfo/RootVersionInfoResponse.cs +++ b/src/Nest/Cluster/RootNodeInfo/RootVersionInfoResponse.cs @@ -5,8 +5,8 @@ namespace Nest public interface IRootNodeInfoResponse : IResponse { string Name { get; } - string Tagline { get; } - ElasticsearchVersionInfo Version { get; } + string Tagline { get; } + ElasticsearchVersionInfo Version { get; } } [JsonObject] @@ -20,6 +20,5 @@ public class RootNodeInfoResponse : ResponseBase, IRootNodeInfoResponse [JsonProperty("version")] public ElasticsearchVersionInfo Version { get; internal set; } - } } diff --git a/src/Nest/Cluster/TaskManagement/CancelTasks/CancelTasksResponse.cs b/src/Nest/Cluster/TaskManagement/CancelTasks/CancelTasksResponse.cs index a90075fe38b..2dbce5b2758 100644 --- a/src/Nest/Cluster/TaskManagement/CancelTasks/CancelTasksResponse.cs +++ b/src/Nest/Cluster/TaskManagement/CancelTasks/CancelTasksResponse.cs @@ -1,27 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using Newtonsoft.Json; -using System.Linq; +using System.Collections.Generic; using Elasticsearch.Net; +using Newtonsoft.Json; namespace Nest { [JsonObject(MemberSerialization.OptIn)] - public interface ICancelTasksResponse: IResponse + public interface ICancelTasksResponse : IResponse { - [JsonProperty("nodes")] - IReadOnlyDictionary Nodes { get; } - [JsonProperty("node_failures")] IReadOnlyCollection NodeFailures { get; } + + [JsonProperty("nodes")] + IReadOnlyDictionary Nodes { get; } } public class CancelTasksResponse : ResponseBase, ICancelTasksResponse { - public override bool IsValid => base.IsValid && !this.NodeFailures.HasAny(); + public override bool IsValid => base.IsValid && !NodeFailures.HasAny(); + public IReadOnlyCollection NodeFailures { get; internal set; } = EmptyReadOnly.Collection; public IReadOnlyDictionary Nodes { get; internal set; } = EmptyReadOnly.Dictionary; - public IReadOnlyCollection NodeFailures { get; internal set; } = EmptyReadOnly.Collection; } } diff --git a/src/Nest/Cluster/TaskManagement/CancelTasks/ElasticClient-CancelTasks.cs b/src/Nest/Cluster/TaskManagement/CancelTasks/ElasticClient-CancelTasks.cs index 0e975cc4376..755421f135a 100644 --- a/src/Nest/Cluster/TaskManagement/CancelTasks/ElasticClient-CancelTasks.cs +++ b/src/Nest/Cluster/TaskManagement/CancelTasks/ElasticClient-CancelTasks.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -13,39 +13,45 @@ public partial interface IElasticClient /// A descriptor to further describe the root operation ICancelTasksResponse CancelTasks(Func selector = null); - /// + /// ICancelTasksResponse CancelTasks(ICancelTasksRequest request); - /// - Task CancelTasksAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task CancelTasksAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task CancelTasksAsync(ICancelTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public ICancelTasksResponse CancelTasks(Func selector = null) => - this.CancelTasks(selector.InvokeOrDefault(new CancelTasksDescriptor())); + CancelTasks(selector.InvokeOrDefault(new CancelTasksDescriptor())); - /// + /// public ICancelTasksResponse CancelTasks(ICancelTasksRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.TasksCancelDispatch(p) + (p, d) => LowLevelDispatch.TasksCancelDispatch(p) ); - /// - public Task CancelTasksAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.CancelTasksAsync(selector.InvokeOrDefault(new CancelTasksDescriptor()), cancellationToken); - - /// - public Task CancelTasksAsync(ICancelTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + /// + public Task CancelTasksAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + CancelTasksAsync(selector.InvokeOrDefault(new CancelTasksDescriptor()), cancellationToken); + + /// + public Task CancelTasksAsync(ICancelTasksRequest request, + CancellationToken cancellationToken = default(CancellationToken) + ) => + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.TasksCancelDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.TasksCancelDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/TaskManagement/GetTask/ElasticClient-GetTask.cs b/src/Nest/Cluster/TaskManagement/GetTask/ElasticClient-GetTask.cs index 2e67a117148..4e5346b0482 100644 --- a/src/Nest/Cluster/TaskManagement/GetTask/ElasticClient-GetTask.cs +++ b/src/Nest/Cluster/TaskManagement/GetTask/ElasticClient-GetTask.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -11,7 +11,9 @@ public partial interface IElasticClient IGetTaskResponse GetTask(IGetTaskRequest request); - Task GetTaskAsync(TaskId id, Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + Task GetTaskAsync(TaskId id, Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); Task GetTaskAsync(IGetTaskRequest request, CancellationToken cancellationToken = default(CancellationToken)); } @@ -19,22 +21,24 @@ public partial interface IElasticClient public partial class ElasticClient { public IGetTaskResponse GetTask(TaskId id, Func selector = null) => - this.GetTask(selector.InvokeOrDefault(new GetTaskDescriptor(id))); + GetTask(selector.InvokeOrDefault(new GetTaskDescriptor(id))); public IGetTaskResponse GetTask(IGetTaskRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.TasksGetDispatch(p) + (p, d) => LowLevelDispatch.TasksGetDispatch(p) ); - public Task GetTaskAsync(TaskId id, Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.GetTaskAsync(selector.InvokeOrDefault(new GetTaskDescriptor(id)), cancellationToken); + public Task GetTaskAsync(TaskId id, Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + GetTaskAsync(selector.InvokeOrDefault(new GetTaskDescriptor(id)), cancellationToken); public Task GetTaskAsync(IGetTaskRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.TasksGetDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.TasksGetDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/TaskManagement/GetTask/GetTaskRequest.cs b/src/Nest/Cluster/TaskManagement/GetTask/GetTaskRequest.cs index ba7d5d089f0..098da689d9b 100644 --- a/src/Nest/Cluster/TaskManagement/GetTask/GetTaskRequest.cs +++ b/src/Nest/Cluster/TaskManagement/GetTask/GetTaskRequest.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Nest { @@ -17,6 +13,6 @@ public partial class GetTaskDescriptor public GetTaskDescriptor() { } [Obsolete("Maintained for binary compatibility. Use the constructor that accepts a task id. Will be removed in 7.0")] - public GetTaskDescriptor TaskId(TaskId taskId) => this.Assign(a => a.RouteValues.Required("task_id", taskId)); + public GetTaskDescriptor TaskId(TaskId taskId) => Assign(a => a.RouteValues.Required("task_id", taskId)); } } diff --git a/src/Nest/Cluster/TaskManagement/GetTask/GetTaskResponse.cs b/src/Nest/Cluster/TaskManagement/GetTask/GetTaskResponse.cs index 88ff856e120..e16c6efe2e2 100644 --- a/src/Nest/Cluster/TaskManagement/GetTask/GetTaskResponse.cs +++ b/src/Nest/Cluster/TaskManagement/GetTask/GetTaskResponse.cs @@ -1,9 +1,4 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Nest { diff --git a/src/Nest/Cluster/TaskManagement/GetTask/TaskInfo.cs b/src/Nest/Cluster/TaskManagement/GetTask/TaskInfo.cs index d400c7618bd..6b7fa92ed8c 100644 --- a/src/Nest/Cluster/TaskManagement/GetTask/TaskInfo.cs +++ b/src/Nest/Cluster/TaskManagement/GetTask/TaskInfo.cs @@ -1,46 +1,42 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Nest { [JsonObject(MemberSerialization.OptIn)] public class TaskInfo { - [JsonProperty("node")] - public string Node { get; internal set; } - - [JsonProperty("id")] - public long Id { get; internal set; } - - [JsonProperty("type")] - public string Type { get; internal set; } - [JsonProperty("action")] public string Action { get; internal set; } - [JsonProperty("status")] - public TaskStatus Status { get; internal set; } + [JsonProperty("cancellable")] + public bool Cancellable { get; internal set; } + + [JsonProperty("children")] + public IReadOnlyCollection Children { get; internal set; } = EmptyReadOnly.Collection; [JsonProperty("description")] public string Description { get; internal set; } - [JsonProperty("start_time_in_millis")] - public long StartTimeInMilliseconds { get; internal set; } + [JsonProperty("headers")] + public IReadOnlyDictionary Headers { get; internal set; } = EmptyReadOnly.Dictionary; + + [JsonProperty("id")] + public long Id { get; internal set; } + + [JsonProperty("node")] + public string Node { get; internal set; } [JsonProperty("running_time_in_nanos")] public long RunningTimeInNanoseconds { get; internal set; } - [JsonProperty("cancellable")] - public bool Cancellable { get; internal set; } + [JsonProperty("start_time_in_millis")] + public long StartTimeInMilliseconds { get; internal set; } - [JsonProperty("headers")] - public IReadOnlyDictionary Headers { get; internal set; } = EmptyReadOnly.Dictionary; + [JsonProperty("status")] + public TaskStatus Status { get; internal set; } - [JsonProperty("children")] - public IReadOnlyCollection Children { get; internal set; } = EmptyReadOnly.Collection; + [JsonProperty("type")] + public string Type { get; internal set; } } } diff --git a/src/Nest/Cluster/TaskManagement/ListTasks/ElasticClient-ListTasks.cs b/src/Nest/Cluster/TaskManagement/ListTasks/ElasticClient-ListTasks.cs index fa221324674..1d6bd726807 100644 --- a/src/Nest/Cluster/TaskManagement/ListTasks/ElasticClient-ListTasks.cs +++ b/src/Nest/Cluster/TaskManagement/ListTasks/ElasticClient-ListTasks.cs @@ -1,7 +1,7 @@ using System; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -13,39 +13,43 @@ public partial interface IElasticClient /// A descriptor to further describe the tasks to retrieve information for IListTasksResponse ListTasks(Func selector = null); - /// + /// IListTasksResponse ListTasks(IListTasksRequest request); - /// - Task ListTasksAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + Task ListTasksAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ); - /// + /// Task ListTasksAsync(IListTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)); } public partial class ElasticClient { - /// + /// public IListTasksResponse ListTasks(Func selector = null) => - this.ListTasks(selector.InvokeOrDefault(new ListTasksDescriptor())); + ListTasks(selector.InvokeOrDefault(new ListTasksDescriptor())); - /// + /// public IListTasksResponse ListTasks(IListTasksRequest request) => - this.Dispatcher.Dispatch( + Dispatcher.Dispatch( request, - (p, d) => this.LowLevelDispatch.TasksListDispatch(p) + (p, d) => LowLevelDispatch.TasksListDispatch(p) ); - /// - public Task ListTasksAsync(Func selector = null, CancellationToken cancellationToken = default(CancellationToken)) => - this.ListTasksAsync(selector.InvokeOrDefault(new ListTasksDescriptor()), cancellationToken); + /// + public Task ListTasksAsync(Func selector = null, + CancellationToken cancellationToken = default(CancellationToken) + ) => + ListTasksAsync(selector.InvokeOrDefault(new ListTasksDescriptor()), cancellationToken); - /// + /// public Task ListTasksAsync(IListTasksRequest request, CancellationToken cancellationToken = default(CancellationToken)) => - this.Dispatcher.DispatchAsync( + Dispatcher.DispatchAsync( request, cancellationToken, - (p, d, c) => this.LowLevelDispatch.TasksListDispatchAsync(p, c) + (p, d, c) => LowLevelDispatch.TasksListDispatchAsync(p, c) ); } } diff --git a/src/Nest/Cluster/TaskManagement/ListTasks/ListTasksResponse.cs b/src/Nest/Cluster/TaskManagement/ListTasks/ListTasksResponse.cs index bf5b8ff7e6b..4cfd59c7e94 100644 --- a/src/Nest/Cluster/TaskManagement/ListTasks/ListTasksResponse.cs +++ b/src/Nest/Cluster/TaskManagement/ListTasks/ListTasksResponse.cs @@ -1,93 +1,85 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using Newtonsoft.Json; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; using Elasticsearch.Net; +using Newtonsoft.Json; namespace Nest { [JsonObject(MemberSerialization.OptIn)] - public interface IListTasksResponse: IResponse + public interface IListTasksResponse : IResponse { - [JsonProperty("nodes")] - IReadOnlyDictionary Nodes { get; } - [JsonProperty("node_failures")] IReadOnlyCollection NodeFailures { get; } + [JsonProperty("nodes")] + IReadOnlyDictionary Nodes { get; } } public class ListTasksResponse : ResponseBase, IListTasksResponse { - public override bool IsValid => base.IsValid && !this.NodeFailures.HasAny(); + public override bool IsValid => base.IsValid && !NodeFailures.HasAny(); + public IReadOnlyCollection NodeFailures { get; internal set; } = EmptyReadOnly.Collection; public IReadOnlyDictionary Nodes { get; internal set; } = EmptyReadOnly.Dictionary; - public IReadOnlyCollection NodeFailures { get; internal set; } = EmptyReadOnly.Collection; } public class TaskExecutingNode { - [JsonProperty("name")] - public string Name { get; internal set; } - - [JsonProperty("transport_address")] - public string TransportAddress { get; internal set; } - [JsonProperty("host")] public string Host { get; internal set; } [JsonProperty("ip")] public string Ip { get; internal set; } + [JsonProperty("name")] + public string Name { get; internal set; } + [JsonProperty("tasks")] public IReadOnlyDictionary Tasks { get; internal set; } = EmptyReadOnly.Dictionary; + + [JsonProperty("transport_address")] + public string TransportAddress { get; internal set; } } public class TaskState { - [JsonProperty("node")] - public string Node { get; internal set; } - - [JsonProperty("id")] - public long Id { get; internal set; } - - [JsonProperty("type")] - public string Type { get; internal set; } - [JsonProperty("action")] public string Action { get; internal set; } - [JsonProperty("status")] - public TaskStatus Status { get; internal set; } + [JsonProperty("cancellable")] + public bool Cancellable { get; internal set; } [JsonProperty("description")] public string Description { get; internal set; } - [JsonProperty("start_time_in_millis")] - public long StartTimeInMilliseconds { get; internal set; } + [JsonProperty("headers")] + public IReadOnlyDictionary Headers { get; internal set; } = EmptyReadOnly.Dictionary; - [JsonProperty("running_time_in_nanos")] - public long RunningTimeInNanoSeconds { get; internal set; } + [JsonProperty("id")] + public long Id { get; internal set; } + + [JsonProperty("node")] + public string Node { get; internal set; } [JsonProperty("parent_task_id")] public TaskId ParentTaskId { get; internal set; } - [JsonProperty("cancellable")] - public bool Cancellable { get; internal set; } + [JsonProperty("running_time_in_nanos")] + public long RunningTimeInNanoSeconds { get; internal set; } - [JsonProperty("headers")] - public IReadOnlyDictionary Headers { get; internal set; } = EmptyReadOnly.Dictionary; + [JsonProperty("start_time_in_millis")] + public long StartTimeInMilliseconds { get; internal set; } + + [JsonProperty("status")] + public TaskStatus Status { get; internal set; } + + [JsonProperty("type")] + public string Type { get; internal set; } } public class TaskStatus { - [JsonProperty("total")] - public long Total { get; internal set; } - - [JsonProperty("updated")] - public long Updated { get; internal set; } + [JsonProperty("batches")] + public long Batches { get; internal set; } [JsonProperty("created")] public long Created { get; internal set; } @@ -95,26 +87,29 @@ public class TaskStatus [JsonProperty("deleted")] public long Deleted { get; internal set; } - [JsonProperty("batches")] - public long Batches { get; internal set; } - - [JsonProperty("version_conflicts")] - public long VersionConflicts { get; internal set; } - [JsonProperty("noops")] public long Noops { get; internal set; } + [JsonProperty("requests_per_second")] + public long RequestsPerSecond { get; internal set; } + [JsonProperty("retries")] public TaskRetries Retries { get; internal set; } [JsonProperty("throttled_millis")] public long ThrottledMilliseconds { get; internal set; } - [JsonProperty("requests_per_second")] - public long RequestsPerSecond { get; internal set; } - [JsonProperty("throttled_until_millis")] public long ThrottledUntilMilliseconds { get; internal set; } + + [JsonProperty("total")] + public long Total { get; internal set; } + + [JsonProperty("updated")] + public long Updated { get; internal set; } + + [JsonProperty("version_conflicts")] + public long VersionConflicts { get; internal set; } } public class TaskRetries diff --git a/src/Nest/CommonAbstractions/ConnectionSettings/ClrPropertyMapping.cs b/src/Nest/CommonAbstractions/ConnectionSettings/ClrPropertyMapping.cs index 4db5de2a669..2296428db60 100644 --- a/src/Nest/CommonAbstractions/ConnectionSettings/ClrPropertyMapping.cs +++ b/src/Nest/CommonAbstractions/ConnectionSettings/ClrPropertyMapping.cs @@ -6,24 +6,24 @@ namespace Nest public abstract class ClrPropertyMappingBase : IClrPropertyMapping where TDocument : class { - Expression> IClrPropertyMapping.Property { get; set; } - bool IClrPropertyMapping.Ignore { get; set; } - string IClrPropertyMapping.NewName { get; set; } + protected ClrPropertyMappingBase(Expression> property) => Self.Property = property; protected IClrPropertyMapping Self => this; - - protected ClrPropertyMappingBase(Expression> property) => Self.Property = property; + bool IClrPropertyMapping.Ignore { get; set; } + string IClrPropertyMapping.NewName { get; set; } + Expression> IClrPropertyMapping.Property { get; set; } IPropertyMapping IClrPropertyMapping.ToPropertyMapping() => Self.Ignore ? PropertyMapping.Ignored - : new PropertyMapping {Name = Self.NewName}; + : new PropertyMapping { Name = Self.NewName }; } public interface IClrPropertyMapping where TDocument : class { - Expression> Property { get; set; } bool Ignore { get; set; } string NewName { get; set; } + Expression> Property { get; set; } + IPropertyMapping ToPropertyMapping(); } diff --git a/src/Nest/CommonAbstractions/ConnectionSettings/ClrTypeDefaults.cs b/src/Nest/CommonAbstractions/ConnectionSettings/ClrTypeDefaults.cs index e0d72d786fe..52af7481964 100644 --- a/src/Nest/CommonAbstractions/ConnectionSettings/ClrTypeDefaults.cs +++ b/src/Nest/CommonAbstractions/ConnectionSettings/ClrTypeDefaults.cs @@ -12,25 +12,24 @@ public interface IClrTypeMapping Type ClrType { get; } /// - /// The default Elasticsearch index name for + /// The property for to resolve ids from. /// - string IndexName { get; set; } + string IdPropertyName { get; set; } /// - /// The default Elasticsearch type name for + /// The default Elasticsearch index name for /// - string TypeName { get; set; } + string IndexName { get; set; } /// - /// The relation name for to resolve to. + /// The relation name for to resolve to. /// string RelationName { get; set; } /// - /// The property for to resolve ids from. + /// The default Elasticsearch type name for /// - string IdPropertyName { get; set; } - + string TypeName { get; set; } } public interface IClrTypeMapping : IClrTypeMapping where TDocument : class @@ -38,19 +37,19 @@ public interface IClrTypeMapping : IClrTypeMapping where TDocument : /// Set a default Id property on CLR type that NEST will evaluate Expression> IdProperty { get; set; } - /// Provide a default routing parameter lookup based on - Expression> RoutingProperty { get; set; } - /// /// Ignore or rename certain properties of CLR type /// IList> Properties { get; set; } + + /// Provide a default routing parameter lookup based on + Expression> RoutingProperty { get; set; } } public class ClrTypeMapping : IClrTypeMapping { /// - /// Initializes a new instance of + /// Initializes a new instance of /// public ClrTypeMapping(Type type) => ClrType = type; @@ -58,17 +57,18 @@ public class ClrTypeMapping : IClrTypeMapping public Type ClrType { get; } /// - public string IndexName { get; set; } + public string IdPropertyName { get; set; } /// - public string TypeName { get; set; } + public string IndexName { get; set; } /// public string RelationName { get; set; } /// - public string IdPropertyName { get; set; } + public string TypeName { get; set; } } + public class ClrTypeMapping : ClrTypeMapping, IClrTypeMapping where TDocument : class { public ClrTypeMapping() : base(typeof(TDocument)) { } @@ -77,27 +77,27 @@ public ClrTypeMapping() : base(typeof(TDocument)) { } public Expression> IdProperty { get; set; } /// - public Expression> RoutingProperty { get; set; } + public IList> Properties { get; set; } /// - public IList> Properties { get; set; } + public Expression> RoutingProperty { get; set; } } - public class ClrTypeMappingDescriptor : DescriptorBase , IClrTypeMapping + public class ClrTypeMappingDescriptor : DescriptorBase, IClrTypeMapping { private readonly Type _type; /// - /// Instantiates a new instance of + /// Instantiates a new instance of /// /// The CLR type to map public ClrTypeMappingDescriptor(Type type) => _type = type; Type IClrTypeMapping.ClrType => _type; + string IClrTypeMapping.IdPropertyName { get; set; } string IClrTypeMapping.IndexName { get; set; } - string IClrTypeMapping.TypeName { get; set; } string IClrTypeMapping.RelationName { get; set; } - string IClrTypeMapping.IdPropertyName { get; set; } + string IClrTypeMapping.TypeName { get; set; } /// /// The default Elasticsearch index name for the CLR type @@ -121,20 +121,20 @@ public class ClrTypeMappingDescriptor : DescriptorBase - : DescriptorBase,IClrTypeMapping>, IClrTypeMapping + : DescriptorBase, IClrTypeMapping>, IClrTypeMapping where TDocument : class { - Type IClrTypeMapping.ClrType { get; } = typeof (TDocument); + Type IClrTypeMapping.ClrType { get; } = typeof(TDocument); + Expression> IClrTypeMapping.IdProperty { get; set; } + string IClrTypeMapping.IdPropertyName { get; set; } string IClrTypeMapping.IndexName { get; set; } - string IClrTypeMapping.TypeName { get; set; } + IList> IClrTypeMapping.Properties { get; set; } = new List>(); string IClrTypeMapping.RelationName { get; set; } - string IClrTypeMapping.IdPropertyName { get; set; } - Expression> IClrTypeMapping.IdProperty { get; set; } Expression> IClrTypeMapping.RoutingProperty { get; set; } - IList> IClrTypeMapping.Properties { get; set; } = new List>(); + string IClrTypeMapping.TypeName { get; set; } /// - /// The default Elasticsearch index name for + /// The default Elasticsearch index name for /// public ClrTypeMappingDescriptor IndexName(string indexName) => Assign(a => a.IndexName = indexName); @@ -159,7 +159,8 @@ public class ClrTypeMappingDescriptor public ClrTypeMappingDescriptor IdProperty(string property) => Assign(a => a.IdPropertyName = property); /// Provide a default routing parameter lookup based on - public ClrTypeMappingDescriptor RoutingProperty(Expression> property) => Assign(a => a.RoutingProperty = property); + public ClrTypeMappingDescriptor RoutingProperty(Expression> property) => + Assign(a => a.RoutingProperty = property); /// /// Ignore on CLR type @@ -172,6 +173,5 @@ public ClrTypeMappingDescriptor Ignore(Expression public ClrTypeMappingDescriptor PropertyName(Expression> property, string newName) => Assign(a => a.Properties.Add(new RenameClrPropertyMapping(property, newName))); - } } diff --git a/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsBase.cs b/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsBase.cs index 212a52299ab..0925d70993f 100644 --- a/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsBase.cs +++ b/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsBase.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Linq.Expressions; @@ -10,7 +9,7 @@ namespace Nest { /// - /// Provides the connection settings for NEST's + /// Provides the connection settings for NEST's /// public class ConnectionSettings : ConnectionSettingsBase { @@ -20,8 +19,8 @@ public ConnectionSettings(Uri uri = null) : this(new SingleNodeConnectionPool(uri ?? new Uri("http://localhost:9200"))) { } /// - /// Instantiate connection settings using a using the provided - /// that never uses any IO. + /// Instantiate connection settings using a using the provided + /// that never uses any IO. /// public ConnectionSettings(InMemoryConnection connection) : this(new SingleNodeConnectionPool(new Uri("http://localhost:9200")), connection) { } @@ -40,56 +39,43 @@ public ConnectionSettings( IConnectionPool connectionPool, IConnection connection, SourceSerializerFactory sourceSerializer, - IPropertyMappingProvider propertyMappingProvider) + IPropertyMappingProvider propertyMappingProvider + ) : base(connectionPool, connection, sourceSerializer, propertyMappingProvider) { } } /// - /// Provides the connection settings for NEST's + /// Provides the connection settings for NEST's /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public abstract class ConnectionSettingsBase : ConnectionConfiguration, IConnectionSettingsValues where TConnectionSettings : ConnectionSettingsBase, IConnectionSettingsValues { - private string _defaultIndex; - string IConnectionSettingsValues.DefaultIndex => this._defaultIndex; - - private string _defaultTypeName; - string IConnectionSettingsValues.DefaultTypeName => this._defaultTypeName; - - private readonly Inferrer _inferrer; - Inferrer IConnectionSettingsValues.Inferrer => _inferrer; - - private Func _defaultTypeNameInferrer; - Func IConnectionSettingsValues.DefaultTypeNameInferrer => _defaultTypeNameInferrer; - private readonly FluentDictionary _defaultIndices; - FluentDictionary IConnectionSettingsValues.DefaultIndices => _defaultIndices; - - private readonly FluentDictionary _defaultTypeNames; - FluentDictionary IConnectionSettingsValues.DefaultTypeNames => _defaultTypeNames; private readonly FluentDictionary _defaultRelationNames; - FluentDictionary IConnectionSettingsValues.DefaultRelationNames => _defaultRelationNames; - private Func _defaultFieldNameInferrer; - Func IConnectionSettingsValues.DefaultFieldNameInferrer => _defaultFieldNameInferrer; + private readonly FluentDictionary _defaultTypeNames; private readonly FluentDictionary _idProperties = new FluentDictionary(); - FluentDictionary IConnectionSettingsValues.IdProperties => _idProperties; - private readonly FluentDictionary _routeProperties = new FluentDictionary(); - FluentDictionary IConnectionSettingsValues.RouteProperties => _routeProperties; + private readonly Inferrer _inferrer; + + private readonly IPropertyMappingProvider _propertyMappingProvider; private readonly FluentDictionary _propertyMappings = new FluentDictionary(); - FluentDictionary IConnectionSettingsValues.PropertyMappings => _propertyMappings; + + private readonly FluentDictionary _routeProperties = new FluentDictionary(); private readonly IElasticsearchSerializer _sourceSerializer; - IElasticsearchSerializer IConnectionSettingsValues.SourceSerializer => _sourceSerializer; - private readonly IPropertyMappingProvider _propertyMappingProvider; - IPropertyMappingProvider IConnectionSettingsValues.PropertyMappingProvider => _propertyMappingProvider; + private Func _defaultFieldNameInferrer; + private string _defaultIndex; + + private string _defaultTypeName; + + private Func _defaultTypeNameInferrer; protected ConnectionSettingsBase( IConnectionPool connectionPool, @@ -100,40 +86,55 @@ IPropertyMappingProvider propertyMappingProvider : base(connectionPool, connection, null) { var defaultSerializer = new InternalSerializer(this); - this._sourceSerializer = sourceSerializerFactory?.Invoke(defaultSerializer, this) ?? defaultSerializer; - this.UseThisRequestResponseSerializer = defaultSerializer; - this._propertyMappingProvider = propertyMappingProvider ?? new PropertyMappingProvider(); + _sourceSerializer = sourceSerializerFactory?.Invoke(defaultSerializer, this) ?? defaultSerializer; + UseThisRequestResponseSerializer = defaultSerializer; + _propertyMappingProvider = propertyMappingProvider ?? new PropertyMappingProvider(); - this._defaultTypeNameInferrer = (t => !this._defaultTypeName.IsNullOrEmpty() ? this._defaultTypeName : t.Name.ToLowerInvariant()); - this._defaultFieldNameInferrer = (p => p.ToCamelCase()); - this._defaultIndices = new FluentDictionary(); - this._defaultTypeNames = new FluentDictionary(); - this._defaultRelationNames = new FluentDictionary(); + _defaultTypeNameInferrer = t => !_defaultTypeName.IsNullOrEmpty() ? _defaultTypeName : t.Name.ToLowerInvariant(); + _defaultFieldNameInferrer = p => p.ToCamelCase(); + _defaultIndices = new FluentDictionary(); + _defaultTypeNames = new FluentDictionary(); + _defaultRelationNames = new FluentDictionary(); - this._inferrer = new Inferrer(this); + _inferrer = new Inferrer(this); } + Func IConnectionSettingsValues.DefaultFieldNameInferrer => _defaultFieldNameInferrer; + string IConnectionSettingsValues.DefaultIndex => _defaultIndex; + FluentDictionary IConnectionSettingsValues.DefaultIndices => _defaultIndices; + FluentDictionary IConnectionSettingsValues.DefaultRelationNames => _defaultRelationNames; + string IConnectionSettingsValues.DefaultTypeName => _defaultTypeName; + Func IConnectionSettingsValues.DefaultTypeNameInferrer => _defaultTypeNameInferrer; + FluentDictionary IConnectionSettingsValues.DefaultTypeNames => _defaultTypeNames; + FluentDictionary IConnectionSettingsValues.IdProperties => _idProperties; + Inferrer IConnectionSettingsValues.Inferrer => _inferrer; + IPropertyMappingProvider IConnectionSettingsValues.PropertyMappingProvider => _propertyMappingProvider; + FluentDictionary IConnectionSettingsValues.PropertyMappings => _propertyMappings; + FluentDictionary IConnectionSettingsValues.RouteProperties => _routeProperties; + IElasticsearchSerializer IConnectionSettingsValues.SourceSerializer => _sourceSerializer; + /// /// The default index to use when no index is specified. /// - /// When null/empty/not set might throw - /// later on when not specifying index explicitly while indexing. + /// + /// When null/empty/not set might throw + /// later on when not specifying index explicitly while indexing. /// public TConnectionSettings DefaultIndex(string defaultIndex) { - this._defaultIndex = defaultIndex; - return (TConnectionSettings) this; + _defaultIndex = defaultIndex; + return (TConnectionSettings)this; } /// - /// Sets a default type name to use within Elasticsearch for all CLR types. If is also set, a configured - /// default type name will only be used when returns null or empty. If unset, the default type + /// Sets a default type name to use within Elasticsearch for all CLR types. If is also set, a configured + /// default type name will only be used when returns null or empty. If unset, the default type /// name for types will be the lowercased CLR type name. /// public TConnectionSettings DefaultTypeName(string defaultTypeName) { - this._defaultTypeName = defaultTypeName; - return (TConnectionSettings) this; + _defaultTypeName = defaultTypeName; + return (TConnectionSettings)this; } /// @@ -144,20 +145,20 @@ public TConnectionSettings DefaultTypeName(string defaultTypeName) /// public TConnectionSettings DefaultFieldNameInferrer(Func fieldNameInferrer) { - this._defaultFieldNameInferrer = fieldNameInferrer; - return (TConnectionSettings) this; + _defaultFieldNameInferrer = fieldNameInferrer; + return (TConnectionSettings)this; } /// /// Specify how type names are inferred from POCO types. - /// By default, type names are inferred by calling - /// on the type's name. + /// By default, type names are inferred by calling + /// on the type's name. /// public TConnectionSettings DefaultTypeNameInferrer(Func typeNameInferrer) { typeNameInferrer.ThrowIfNull(nameof(typeNameInferrer)); - this._defaultTypeNameInferrer = typeNameInferrer; - return (TConnectionSettings) this; + _defaultTypeNameInferrer = typeNameInferrer; + return (TConnectionSettings)this; } /// @@ -171,15 +172,15 @@ private void MapIdPropertyFor(Expression> obj var memberInfo = new MemberInfoResolver(objectPath); var fieldName = memberInfo.Members.Single().Name; - if (this._idProperties.ContainsKey(typeof(TDocument))) + if (_idProperties.ContainsKey(typeof(TDocument))) { - if (this._idProperties[typeof(TDocument)].Equals(fieldName)) return; + if (_idProperties[typeof(TDocument)].Equals(fieldName)) return; throw new ArgumentException( - $"Cannot map '{fieldName}' as the id property for type '{typeof(TDocument).Name}': it already has '{this._idProperties[typeof(TDocument)]}' mapped."); + $"Cannot map '{fieldName}' as the id property for type '{typeof(TDocument).Name}': it already has '{_idProperties[typeof(TDocument)]}' mapped."); } - this._idProperties.Add(typeof(TDocument), fieldName); + _idProperties.Add(typeof(TDocument), fieldName); } private void MapRoutePropertyFor(Expression> objectPath) @@ -189,15 +190,15 @@ private void MapRoutePropertyFor(Expression> var memberInfo = new MemberInfoResolver(objectPath); var fieldName = memberInfo.Members.Single().Name; - if (this._routeProperties.ContainsKey(typeof(TDocument))) + if (_routeProperties.ContainsKey(typeof(TDocument))) { - if (this._routeProperties[typeof(TDocument)].Equals(fieldName)) return; + if (_routeProperties[typeof(TDocument)].Equals(fieldName)) return; throw new ArgumentException( - $"Cannot map '{fieldName}' as the route property for type '{typeof(TDocument).Name}': it already has '{this._routeProperties[typeof(TDocument)]}' mapped."); + $"Cannot map '{fieldName}' as the route property for type '{typeof(TDocument).Name}': it already has '{_routeProperties[typeof(TDocument)]}' mapped."); } - this._routeProperties.Add(typeof(TDocument), fieldName); + _routeProperties.Add(typeof(TDocument), fieldName); } private void ApplyPropertyMappings(IList> mappings) @@ -225,7 +226,9 @@ private void ApplyPropertyMappings(IList(Func()); if (!inferMapping.IndexName.IsNullOrEmpty()) - this._defaultIndices.Add(inferMapping.ClrType, inferMapping.IndexName); + _defaultIndices.Add(inferMapping.ClrType, inferMapping.IndexName); if (!inferMapping.TypeName.IsNullOrEmpty()) - this._defaultTypeNames.Add(inferMapping.ClrType, inferMapping.TypeName); + _defaultTypeNames.Add(inferMapping.ClrType, inferMapping.TypeName); if (!inferMapping.RelationName.IsNullOrEmpty()) - this._defaultRelationNames.Add(inferMapping.ClrType, inferMapping.RelationName); + _defaultRelationNames.Add(inferMapping.ClrType, inferMapping.RelationName); if (!string.IsNullOrWhiteSpace(inferMapping.IdPropertyName)) - this._idProperties[inferMapping.ClrType] = inferMapping.IdPropertyName; + _idProperties[inferMapping.ClrType] = inferMapping.IdPropertyName; if (inferMapping.IdProperty != null) - this.MapIdPropertyFor(inferMapping.IdProperty); + MapIdPropertyFor(inferMapping.IdProperty); if (inferMapping.RoutingProperty != null) - this.MapRoutePropertyFor(inferMapping.RoutingProperty); + MapRoutePropertyFor(inferMapping.RoutingProperty); if (inferMapping.Properties != null) - this.ApplyPropertyMappings(inferMapping.Properties); + ApplyPropertyMappings(inferMapping.Properties); - return (TConnectionSettings) this; + return (TConnectionSettings)this; } /// @@ -281,18 +284,18 @@ public TConnectionSettings DefaultMappingFor(Type documentType, Func @@ -301,20 +304,21 @@ public TConnectionSettings DefaultMappingFor(Type documentType, FuncThe mappings for the POCO types you wish to configure public TConnectionSettings DefaultMappingFor(IEnumerable typeMappings) { - if (typeMappings == null) return (TConnectionSettings) this; + if (typeMappings == null) return (TConnectionSettings)this; + foreach (var inferMapping in typeMappings) { if (!inferMapping.IndexName.IsNullOrEmpty()) - this._defaultIndices.Add(inferMapping.ClrType, inferMapping.IndexName); + _defaultIndices.Add(inferMapping.ClrType, inferMapping.IndexName); if (!inferMapping.TypeName.IsNullOrEmpty()) - this._defaultTypeNames.Add(inferMapping.ClrType, inferMapping.TypeName); + _defaultTypeNames.Add(inferMapping.ClrType, inferMapping.TypeName); if (!inferMapping.RelationName.IsNullOrEmpty()) - this._defaultRelationNames.Add(inferMapping.ClrType, inferMapping.RelationName); + _defaultRelationNames.Add(inferMapping.ClrType, inferMapping.RelationName); } - return (TConnectionSettings) this; + return (TConnectionSettings)this; } } } diff --git a/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsValuesExtensions.cs b/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsValuesExtensions.cs index a23677b2458..9124f846253 100644 --- a/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsValuesExtensions.cs +++ b/src/Nest/CommonAbstractions/ConnectionSettings/ConnectionSettingsValuesExtensions.cs @@ -1,5 +1,4 @@ using System; -using Elasticsearch.Net; using Newtonsoft.Json; namespace Nest @@ -8,8 +7,9 @@ internal static class ConnectionSettingsValuesExtensions { public static InternalSerializer CreateStateful(this IConnectionSettingsValues settings, JsonConverter converter) { - var s = (settings as ConnectionSettings) - ?? throw new NullReferenceException($"Stateful serializer expected {nameof(IConnectionSettingsValues)} to be {nameof(ConnectionSettings)}"); + var s = settings as ConnectionSettings + ?? throw new NullReferenceException( + $"Stateful serializer expected {nameof(IConnectionSettingsValues)} to be {nameof(ConnectionSettings)}"); return StatefulSerializerFactory.CreateStateful(s, converter); } diff --git a/src/Nest/CommonAbstractions/ConnectionSettings/IConnectionSettingsValues.cs b/src/Nest/CommonAbstractions/ConnectionSettings/IConnectionSettingsValues.cs index 454ce57cd59..f1fbb261a6b 100644 --- a/src/Nest/CommonAbstractions/ConnectionSettings/IConnectionSettingsValues.cs +++ b/src/Nest/CommonAbstractions/ConnectionSettings/IConnectionSettingsValues.cs @@ -1,28 +1,26 @@ using System; -using System.Collections.ObjectModel; using System.Reflection; using Elasticsearch.Net; -using Newtonsoft.Json; namespace Nest { public interface IConnectionSettingsValues : IConnectionConfigurationValues { - Inferrer Inferrer { get; } - FluentDictionary DefaultIndices { get; } - FluentDictionary DefaultTypeNames { get; } - FluentDictionary DefaultRelationNames { get; } - FluentDictionary IdProperties { get; } - FluentDictionary RouteProperties { get; } - FluentDictionary PropertyMappings { get; } + Func DefaultFieldNameInferrer { get; } string DefaultIndex { get; } + FluentDictionary DefaultIndices { get; } + FluentDictionary DefaultRelationNames { get; } string DefaultTypeName { get; } Func DefaultTypeNameInferrer { get; } - Func DefaultFieldNameInferrer { get; } + FluentDictionary DefaultTypeNames { get; } + FluentDictionary IdProperties { get; } + Inferrer Inferrer { get; } + IPropertyMappingProvider PropertyMappingProvider { get; } + FluentDictionary PropertyMappings { get; } + FluentDictionary RouteProperties { get; } IElasticsearchSerializer SourceSerializer { get; } - IPropertyMappingProvider PropertyMappingProvider { get; } } } diff --git a/src/Nest/CommonAbstractions/ConnectionSettings/MemberInfoResolver.cs b/src/Nest/CommonAbstractions/ConnectionSettings/MemberInfoResolver.cs index 54bd1d60406..51ef47da4b8 100644 --- a/src/Nest/CommonAbstractions/ConnectionSettings/MemberInfoResolver.cs +++ b/src/Nest/CommonAbstractions/ConnectionSettings/MemberInfoResolver.cs @@ -9,18 +9,14 @@ namespace Nest /// public class MemberInfoResolver : ExpressionVisitor { - private readonly IList _members = new List(); - public IList Members { get { return _members; } } + public MemberInfoResolver(Expression expression) => Visit(expression); - public MemberInfoResolver(Expression expression) - { - base.Visit(expression); - } + public IList Members { get; } = new List(); protected override Expression VisitMember(MemberExpression expression) { - this._members.Add(expression.Member); + Members.Add(expression.Member); return base.VisitMember(expression); } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IIsADictionary.cs b/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IIsADictionary.cs index de9424ae5ae..c0856b15774 100644 --- a/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IIsADictionary.cs +++ b/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IIsADictionary.cs @@ -2,7 +2,7 @@ namespace Nest { - public interface IIsADictionary {} - public interface IIsADictionary : IDictionary, IIsADictionary {} + public interface IIsADictionary { } + public interface IIsADictionary : IDictionary, IIsADictionary { } } diff --git a/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IsADictionaryBase.cs b/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IsADictionaryBase.cs index 75e77f23cf4..9c3154ac0f3 100644 --- a/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IsADictionaryBase.cs +++ b/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IsADictionaryBase.cs @@ -1,66 +1,74 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; -using System.Linq; namespace Nest { public abstract class IsADictionaryBase : IIsADictionary { - protected Dictionary BackingDictionary { get; } - private ICollection> Self => BackingDictionary; - - protected IsADictionaryBase() => this.BackingDictionary = new Dictionary(); + protected IsADictionaryBase() => BackingDictionary = new Dictionary(); protected IsADictionaryBase(IDictionary backingDictionary) { if (backingDictionary != null) - foreach (var key in backingDictionary.Keys) ValidateKey(Sanitize(key)); + foreach (var key in backingDictionary.Keys) + ValidateKey(Sanitize(key)); - this.BackingDictionary = backingDictionary != null + BackingDictionary = backingDictionary != null ? new Dictionary(backingDictionary) : new Dictionary(); } - IEnumerator IEnumerable.GetEnumerator() => this.BackingDictionary.GetEnumerator(); - - IEnumerator> IEnumerable>.GetEnumerator() => this.BackingDictionary.GetEnumerator(); + public TValue this[TKey key] + { + get => BackingDictionary[Sanitize(key)]; + set => BackingDictionary[ValidateKey(Sanitize(key))] = value; + } - void ICollection>.Clear() => this.BackingDictionary.Clear(); - [EditorBrowsable(EditorBrowsableState.Never)] - bool ICollection>.Contains(KeyValuePair item) => Self.Contains(item); - void ICollection>.CopyTo( KeyValuePair[] array, int arrayIndex) => Self.CopyTo(array, arrayIndex); - int ICollection>.Count => this.BackingDictionary.Count; + protected Dictionary BackingDictionary { get; } + int ICollection>.Count => BackingDictionary.Count; bool ICollection>.IsReadOnly => Self.IsReadOnly; - bool ICollection>.Remove(KeyValuePair item) => Self.Remove(item); + + TValue IDictionary.this[TKey key] + { + get => BackingDictionary[Sanitize(key)]; + set => BackingDictionary[ValidateKey(Sanitize(key))] = value; + } + + ICollection IDictionary.Keys => BackingDictionary.Keys; + private ICollection> Self => BackingDictionary; + ICollection IDictionary.Values => BackingDictionary.Values; + void ICollection>.Add(KeyValuePair item) { ValidateKey(Sanitize(item.Key)); Self.Add(item); } - ICollection IDictionary.Keys => this.BackingDictionary.Keys; - ICollection IDictionary.Values => this.BackingDictionary.Values; + void ICollection>.Clear() => BackingDictionary.Clear(); + + [EditorBrowsable(EditorBrowsableState.Never)] + bool ICollection>.Contains(KeyValuePair item) => Self.Contains(item); + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) => Self.CopyTo(array, arrayIndex); + + bool ICollection>.Remove(KeyValuePair item) => Self.Remove(item); + + void IDictionary.Add(TKey key, TValue value) => BackingDictionary.Add(ValidateKey(Sanitize(key)), value); [EditorBrowsable(EditorBrowsableState.Never)] - bool IDictionary.ContainsKey(TKey key) => this.BackingDictionary.ContainsKey(Sanitize(key)); - void IDictionary.Add(TKey key, TValue value) => this.BackingDictionary.Add(ValidateKey(Sanitize(key)), value); - bool IDictionary.Remove(TKey key) => this.BackingDictionary.Remove(Sanitize(key)); - bool IDictionary.TryGetValue(TKey key, out TValue value) => this.BackingDictionary.TryGetValue(Sanitize(key), out value); + bool IDictionary.ContainsKey(TKey key) => BackingDictionary.ContainsKey(Sanitize(key)); - protected virtual TKey ValidateKey(TKey key) => key; - protected virtual TKey Sanitize(TKey key) => key; + bool IDictionary.Remove(TKey key) => BackingDictionary.Remove(Sanitize(key)); - TValue IDictionary.this[TKey key] - { - get => this.BackingDictionary[Sanitize(key)]; - set => this.BackingDictionary[ValidateKey(Sanitize(key))] = value; - } + bool IDictionary.TryGetValue(TKey key, out TValue value) => BackingDictionary.TryGetValue(Sanitize(key), out value); - public TValue this[TKey key] - { - get => this.BackingDictionary[Sanitize(key)]; - set => this.BackingDictionary[ValidateKey(Sanitize(key))] = value; - } + IEnumerator IEnumerable.GetEnumerator() => BackingDictionary.GetEnumerator(); + + IEnumerator> IEnumerable>.GetEnumerator() => BackingDictionary.GetEnumerator(); + + protected virtual TKey ValidateKey(TKey key) => key; + + protected virtual TKey Sanitize(TKey key) => key; } } diff --git a/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IsADictionaryDescriptorBase.cs b/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IsADictionaryDescriptorBase.cs index f750420010e..f245cc7a0fc 100644 --- a/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IsADictionaryDescriptorBase.cs +++ b/src/Nest/CommonAbstractions/DictionaryLike/IsADictionary/IsADictionaryDescriptorBase.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Nest { public abstract class IsADictionaryDescriptorBase @@ -7,7 +5,7 @@ public abstract class IsADictionaryDescriptorBase where TInterface : class, IIsADictionary { - protected IsADictionaryDescriptorBase(TInterface instance) : base(instance) {} + protected IsADictionaryDescriptorBase(TInterface instance) : base(instance) { } protected TDescriptor Assign(TKey key, TValue value) => Assign(a => a.Add(key, value)); } diff --git a/src/Nest/CommonAbstractions/DictionaryLike/IsAReadOnlyDictionary/IIsAReadOnlyDictionary.cs b/src/Nest/CommonAbstractions/DictionaryLike/IsAReadOnlyDictionary/IIsAReadOnlyDictionary.cs index 7bd3d87be96..02828760442 100644 --- a/src/Nest/CommonAbstractions/DictionaryLike/IsAReadOnlyDictionary/IIsAReadOnlyDictionary.cs +++ b/src/Nest/CommonAbstractions/DictionaryLike/IsAReadOnlyDictionary/IIsAReadOnlyDictionary.cs @@ -2,7 +2,7 @@ namespace Nest { - public interface IIsAReadOnlyDictionary {} - public interface IIsAReadOnlyDictionary : IReadOnlyDictionary, IIsAReadOnlyDictionary {} + public interface IIsAReadOnlyDictionary { } + public interface IIsAReadOnlyDictionary : IReadOnlyDictionary, IIsAReadOnlyDictionary { } } diff --git a/src/Nest/CommonAbstractions/DictionaryLike/IsAReadOnlyDictionary/IsADictionaryBase.cs b/src/Nest/CommonAbstractions/DictionaryLike/IsAReadOnlyDictionary/IsADictionaryBase.cs index 9f41d61a755..f8b79653ade 100644 --- a/src/Nest/CommonAbstractions/DictionaryLike/IsAReadOnlyDictionary/IsADictionaryBase.cs +++ b/src/Nest/CommonAbstractions/DictionaryLike/IsAReadOnlyDictionary/IsADictionaryBase.cs @@ -1,13 +1,10 @@ using System.Collections; using System.Collections.Generic; -using System.Collections.ObjectModel; namespace Nest { public abstract class IsAReadOnlyDictionaryBase : IIsAReadOnlyDictionary { - protected internal IReadOnlyDictionary BackingDictionary { get; } = EmptyReadOnly.Dictionary; - protected IsAReadOnlyDictionaryBase(IReadOnlyDictionary backingDictionary) { if (backingDictionary == null) return; @@ -18,27 +15,28 @@ protected IsAReadOnlyDictionaryBase(IReadOnlyDictionary backingDic // expect all implementations of Sanitize to be pure dictionary[Sanitize(key)] = backingDictionary[key]; - this.BackingDictionary = dictionary; + BackingDictionary = dictionary; } - protected virtual TKey Sanitize(TKey key) => key; + public int Count => BackingDictionary.Count; - IEnumerator> IEnumerable>.GetEnumerator() => - this.BackingDictionary.GetEnumerator(); + public TValue this[TKey key] => BackingDictionary[key]; - IEnumerator IEnumerable.GetEnumerator() => this.BackingDictionary.GetEnumerator(); + public IEnumerable Keys => BackingDictionary.Keys; - public int Count => this.BackingDictionary.Count; + public IEnumerable Values => BackingDictionary.Values; + protected internal IReadOnlyDictionary BackingDictionary { get; } = EmptyReadOnly.Dictionary; - public bool ContainsKey(TKey key) => this.BackingDictionary.ContainsKey(key); + IEnumerator IEnumerable.GetEnumerator() => BackingDictionary.GetEnumerator(); - public bool TryGetValue(TKey key, out TValue value) => - this.BackingDictionary.TryGetValue(key, out value); + IEnumerator> IEnumerable>.GetEnumerator() => + BackingDictionary.GetEnumerator(); - public TValue this[TKey key] => this.BackingDictionary[key]; + public bool ContainsKey(TKey key) => BackingDictionary.ContainsKey(key); - public IEnumerable Keys => this.BackingDictionary.Keys; + public bool TryGetValue(TKey key, out TValue value) => + BackingDictionary.TryGetValue(key, out value); - public IEnumerable Values => this.BackingDictionary.Values; + protected virtual TKey Sanitize(TKey key) => key; } } diff --git a/src/Nest/CommonAbstractions/DictionaryLike/PerFieldAnalyzer/PerFieldAnalyzer.cs b/src/Nest/CommonAbstractions/DictionaryLike/PerFieldAnalyzer/PerFieldAnalyzer.cs index 197667e0425..c260f3e78d5 100644 --- a/src/Nest/CommonAbstractions/DictionaryLike/PerFieldAnalyzer/PerFieldAnalyzer.cs +++ b/src/Nest/CommonAbstractions/DictionaryLike/PerFieldAnalyzer/PerFieldAnalyzer.cs @@ -11,18 +11,19 @@ public interface IPerFieldAnalyzer : IIsADictionary { } public class PerFieldAnalyzer : IsADictionaryBase, IPerFieldAnalyzer { - public PerFieldAnalyzer() {} + public PerFieldAnalyzer() { } + public PerFieldAnalyzer(IDictionary container) : base(container) { } + public PerFieldAnalyzer(Dictionary container) - : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) - {} + : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) { } public void Add(Field field, string analyzer) => BackingDictionary.Add(field, analyzer); } public class PerFieldAnalyzer : PerFieldAnalyzer where T : class { - public void Add(Expression> field, string analyzer) => BackingDictionary.Add(field, analyzer); + public void Add(Expression> field, string analyzer) => BackingDictionary.Add(field, analyzer); } public class PerFieldAnalyzerDescriptor : IsADictionaryDescriptorBase, IPerFieldAnalyzer, Field, string> diff --git a/src/Nest/CommonAbstractions/Extensions/ExceptionExtensions.cs b/src/Nest/CommonAbstractions/Extensions/ExceptionExtensions.cs index 7dafef7de39..5e08562c9b2 100644 --- a/src/Nest/CommonAbstractions/Extensions/ExceptionExtensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/ExceptionExtensions.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.Runtime.ExceptionServices; @@ -27,6 +25,5 @@ internal static T ThrowWhen(this T @object, Func predicate, string e return @object; } - } } diff --git a/src/Nest/CommonAbstractions/Extensions/ExpressionExtensions.cs b/src/Nest/CommonAbstractions/Extensions/ExpressionExtensions.cs index bead4b1151e..f1b3be2e511 100644 --- a/src/Nest/CommonAbstractions/Extensions/ExpressionExtensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/ExpressionExtensions.cs @@ -7,8 +7,11 @@ namespace Nest { public static class ExpressionExtensions { + private static readonly Regex ExpressionRegex = new Regex(@"^\s*(.*)\s*\=\>\s*\1\."); + private static readonly Regex MemberExpressionRegex = new Regex(@"^[^\.]*\."); + /// - /// Appends to the path separating it with a dot. + /// Appends to the path separating it with a dot. /// This is especially useful with multi fields. /// /// the expression to which the suffix should be applied @@ -19,34 +22,6 @@ public static Expression> AppendSuffix(this Expression>(newBody, expression.Parameters[0]); } - /// - /// Calls on a member expression. - /// - private class SuffixExpressionVisitor : ExpressionVisitor - { - private readonly string _suffix; - - public SuffixExpressionVisitor(string suffix) - { - this._suffix = suffix; - } - - public override Expression Visit(Expression node) - { - return Expression.Call( - typeof(SuffixExtensions), - nameof(SuffixExtensions.Suffix), - null, - node, - Expression.Constant(_suffix)); - } - - protected override Expression VisitUnary(UnaryExpression node) => node; - } - - private static readonly Regex ExpressionRegex = new Regex(@"^\s*(.*)\s*\=\>\s*\1\."); - private static readonly Regex MemberExpressionRegex = new Regex(@"^[^\.]*\."); - internal static object ComparisonValueFromExpression(this Expression expression, out Type type) { type = null; @@ -62,5 +37,24 @@ internal static object ComparisonValueFromExpression(this Expression expression, ? MemberExpressionRegex.Replace(memberExpression.ToString(), string.Empty) : ExpressionRegex.Replace(expression.ToString(), string.Empty); } + + /// + /// Calls on a member expression. + /// + private class SuffixExpressionVisitor : ExpressionVisitor + { + private readonly string _suffix; + + public SuffixExpressionVisitor(string suffix) => _suffix = suffix; + + public override Expression Visit(Expression node) => Expression.Call( + typeof(SuffixExtensions), + nameof(SuffixExtensions.Suffix), + null, + node, + Expression.Constant(_suffix)); + + protected override Expression VisitUnary(UnaryExpression node) => node; + } } } diff --git a/src/Nest/CommonAbstractions/Extensions/Extensions.cs b/src/Nest/CommonAbstractions/Extensions/Extensions.cs index 7a71c60f316..2489f946771 100644 --- a/src/Nest/CommonAbstractions/Extensions/Extensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/Extensions.cs @@ -7,12 +7,11 @@ using System.Reflection; using System.Runtime.Serialization; using System.Text; -using Elasticsearch.Net; +using System.Threading; +using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; -using System.Threading.Tasks; -using System.Threading; namespace Nest { @@ -20,6 +19,7 @@ internal static class EmptyReadOnly { public static readonly IReadOnlyCollection Collection = new ReadOnlyCollection(new TElement[0]); } + internal static class EmptyReadOnly { public static readonly IReadOnlyDictionary Dictionary = new ReadOnlyDictionary(new Dictionary(0)); @@ -41,6 +41,7 @@ internal static TReturn InvokeOrDefault(this Func DistinctBy(this IEnumerable items, Func property) - { - return items.GroupBy(property).Select(x => x.First()); - } + internal static IEnumerable DistinctBy(this IEnumerable items, Func property) => + items.GroupBy(property).Select(x => x.First()); internal static ConcurrentDictionary _enumCache = new ConcurrentDictionary(); @@ -95,7 +94,7 @@ internal static string ToEnumValue(this T enumValue) where T : struct var enumMemberAttribute = enumFieldInfo.GetCustomAttribute(); if (enumMemberAttribute?.Value.Equals(str, comparison) ?? false) { - var v = (T) Enum.Parse(enumType, name); + var v = (T)Enum.Parse(enumType, name); _enumCache.TryAdd(key, v); return v; } @@ -103,7 +102,7 @@ internal static string ToEnumValue(this T enumValue) where T : struct var alternativeEnumMemberAttribute = enumFieldInfo.GetCustomAttribute(); if (alternativeEnumMemberAttribute?.Value.Equals(str, comparison) ?? false) { - var v = (T) Enum.Parse(enumType, name); + var v = (T)Enum.Parse(enumType, name); _enumCache.TryAdd(key, v); return v; } @@ -118,19 +117,12 @@ internal static string ToEnumValue(this T enumValue) where T : struct internal static string Utf8String(this byte[] bytes) => bytes == null ? null : Encoding.UTF8.GetString(bytes, 0, bytes.Length); #endif - internal static byte[] Utf8Bytes(this string s) - { - return s.IsNullOrEmpty() ? null : Encoding.UTF8.GetBytes(s); - } + internal static byte[] Utf8Bytes(this string s) => s.IsNullOrEmpty() ? null : Encoding.UTF8.GetBytes(s); + + internal static bool IsNullOrEmpty(this TypeName value) => value == null || value.GetHashCode() == 0; + + internal static bool IsNullOrEmpty(this IndexName value) => value == null || value.GetHashCode() == 0; - internal static bool IsNullOrEmpty(this TypeName value) - { - return value == null || value.GetHashCode() == 0; - } - internal static bool IsNullOrEmpty(this IndexName value) - { - return value == null || value.GetHashCode() == 0; - } internal static bool IsValueType(this Type type) { #if DOTNETCORE @@ -154,46 +146,39 @@ internal static void ThrowIfEmpty(this IEnumerable @object, string paramet throw new ArgumentException("Argument can not be an empty collection", parameterName); } - internal static List AsInstanceOrToListOrDefault(this IEnumerable list) - { - return list as List ?? list?.ToList() ?? new List(); - } - internal static List AsInstanceOrToListOrNull(this IEnumerable list) - { - return list as List ?? list?.ToList(); - } + internal static List AsInstanceOrToListOrDefault(this IEnumerable list) => list as List ?? list?.ToList() ?? new List(); + + internal static List AsInstanceOrToListOrNull(this IEnumerable list) => list as List ?? list?.ToList(); internal static List EagerConcat(this IEnumerable list, IEnumerable other) { var first = list.AsInstanceOrToListOrDefault(); if (other == null) return first; + var second = other.AsInstanceOrToListOrDefault(); var newList = new List(first.Count + second.Count); newList.AddRange(first); newList.AddRange(second); return newList; } + internal static IEnumerable AddIfNotNull(this IEnumerable list, T other) { if (other == null) return list; + var l = list.AsInstanceOrToListOrDefault(); l.Add(other); return l; } - internal static bool HasAny(this IEnumerable list, Func predicate) - { - return list != null && list.Any(predicate); - } + internal static bool HasAny(this IEnumerable list, Func predicate) => list != null && list.Any(predicate); - internal static bool HasAny(this IEnumerable list) - { - return list != null && list.Any(); - } + internal static bool HasAny(this IEnumerable list) => list != null && list.Any(); internal static bool IsEmpty(this IEnumerable list) { if (list == null) return true; + var enumerable = list as T[] ?? list.ToArray(); return !enumerable.Any() || enumerable.All(t => t == null); } @@ -204,24 +189,23 @@ internal static void ThrowIfNull(this T value, string name, string message = else if (value == null) throw new ArgumentNullException(name, "Argument can not be null when " + message); } - internal static bool IsNullOrEmpty(this string value) - { - return string.IsNullOrWhiteSpace(value); - } + internal static bool IsNullOrEmpty(this string value) => string.IsNullOrWhiteSpace(value); + internal static bool IsNullOrEmptyCommaSeparatedList(this string value, out string[] split) { split = null; if (string.IsNullOrWhiteSpace(value)) return true; - split = value.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries) - .Where(t=>!t.IsNullOrEmpty()) - .Select(t=>t.Trim()) + + split = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) + .Where(t => !t.IsNullOrEmpty()) + .Select(t => t.Trim()) .ToArray(); return split.Length == 0; } internal static void ForEach(this IEnumerable enumerable, Action handler) { - foreach (T item in enumerable) handler(item); + foreach (var item in enumerable) handler(item); } internal static List ToListOrNullIfEmpty(this IEnumerable enumerable) @@ -233,12 +217,15 @@ internal static List ToListOrNullIfEmpty(this IEnumerable enumerable) internal static void AddIfNotNull(this IList list, T item) where T : class { if (item == null) return; + list.Add(item); } + internal static void AddRangeIfNotNull(this List list, IEnumerable item) where T : class { if (item == null) return; - list.AddRange(item.Where(x=>x!=null)); + + list.AddRange(item.Where(x => x != null)); } internal static Dictionary NullIfNoKeys(this Dictionary dictionary) @@ -258,13 +245,13 @@ internal static async Task ForEachAsync( SemaphoreSlim additionalRateLimitter = null ) { - var semaphore = new SemaphoreSlim(initialCount: maxDegreeOfParallelism, maxCount: maxDegreeOfParallelism); + var semaphore = new SemaphoreSlim(maxDegreeOfParallelism, maxDegreeOfParallelism); long page = 0; try { var tasks = new List(maxDegreeOfParallelism); - int i = 0; + var i = 0; foreach (var item in lazyList) { tasks.Add(ProcessAsync(item, taskSelector, resultProcessor, semaphore, additionalRateLimitter, page++)); @@ -292,7 +279,8 @@ private static async Task ProcessAsync( Action resultProcessor, SemaphoreSlim localRateLimiter, SemaphoreSlim additionalRateLimiter, - long page) + long page + ) { if (localRateLimiter != null) await localRateLimiter.WaitAsync().ConfigureAwait(false); if (additionalRateLimiter != null) await additionalRateLimiter.WaitAsync().ConfigureAwait(false); @@ -312,8 +300,8 @@ internal static bool NullOrEquals(this T o, T other) { if (o == null && other == null) return true; if (o == null || other == null) return false; + return o.Equals(other); } - } } diff --git a/src/Nest/CommonAbstractions/Extensions/JsonExtensions.cs b/src/Nest/CommonAbstractions/Extensions/JsonExtensions.cs index e80e310f5e8..21a2801b2a9 100644 --- a/src/Nest/CommonAbstractions/Extensions/JsonExtensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/JsonExtensions.cs @@ -1,10 +1,5 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Elasticsearch.Net; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Nest { @@ -15,6 +10,7 @@ public static IConnectionSettingsValues GetConnectionSettings(this JsonSerialize var contract = serializer.ContractResolver as ElasticContractResolver; if (contract?.ConnectionSettings == null) throw new Exception("If you use a custom contract resolver be sure to subclass from " + nameof(ElasticContractResolver)); + return contract.ConnectionSettings; } @@ -29,6 +25,7 @@ public static TConverter GetStatefulConverter(this JsonSerializer se public static void WriteProperty(this JsonWriter writer, JsonSerializer serializer, string propertyName, object value) { if (value == null) return; + writer.WritePropertyName(propertyName); serializer.Serialize(writer, value); } diff --git a/src/Nest/CommonAbstractions/Extensions/StringExtensions.cs b/src/Nest/CommonAbstractions/Extensions/StringExtensions.cs index 489c798ea98..9e7d749e159 100644 --- a/src/Nest/CommonAbstractions/Extensions/StringExtensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/StringExtensions.cs @@ -1,5 +1,4 @@ using System.Collections.Specialized; -using System.Globalization; namespace Nest { @@ -26,6 +25,7 @@ internal static NameValueCollection ToNameValueCollection(this string queryStrin return queryParameters; } + internal static string ToCamelCase(this string s) { if (string.IsNullOrEmpty(s)) @@ -34,13 +34,11 @@ internal static string ToCamelCase(this string s) if (!char.IsUpper(s[0])) return s; - string camelCase = char.ToLowerInvariant(s[0]).ToString(); + var camelCase = char.ToLowerInvariant(s[0]).ToString(); if (s.Length > 1) camelCase += s.Substring(1); return camelCase; } - - } } diff --git a/src/Nest/CommonAbstractions/Extensions/SuffixExtensions.cs b/src/Nest/CommonAbstractions/Extensions/SuffixExtensions.cs index b39b95a2a18..cd34959b9d1 100644 --- a/src/Nest/CommonAbstractions/Extensions/SuffixExtensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/SuffixExtensions.cs @@ -4,12 +4,9 @@ public static class SuffixExtensions { /// /// This extension method should only be used in expressions which are analysed by Nest. - /// When analysed it will append to the path separating it with a dot. + /// When analysed it will append to the path separating it with a dot. /// This is especially useful with multi fields. /// - public static object Suffix(this object @object, string suffix) - { - return @object; - } + public static object Suffix(this object @object, string suffix) => @object; } } diff --git a/src/Nest/CommonAbstractions/Extensions/TypeExtensions.cs b/src/Nest/CommonAbstractions/Extensions/TypeExtensions.cs index 1a96cb82f1f..23861f68120 100644 --- a/src/Nest/CommonAbstractions/Extensions/TypeExtensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/TypeExtensions.cs @@ -15,12 +15,12 @@ internal static class TypeExtensions private static readonly MethodInfo GetActivatorMethodInfo = typeof(TypeExtensions).GetMethod(nameof(GetActivator), BindingFlags.Static | BindingFlags.NonPublic); - private static readonly ConcurrentDictionary> CachedDefaultValues = - new ConcurrentDictionary>(); - private static readonly ConcurrentDictionary> CachedActivators = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> CachedDefaultValues = + new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary CachedGenericClosedTypes = new ConcurrentDictionary(); @@ -30,10 +30,13 @@ internal static class TypeExtensions private static readonly ConcurrentDictionary> CachedTypePropertyInfos = new ConcurrentDictionary>(); - private delegate T ObjectActivator(params object[] args); + + //this contract is only used to resolve properties in class WE OWN. + //these are not subject to change depending on what the user passes as connectionsettings + private static readonly ElasticContractResolver JsonContract = new ElasticContractResolver(new ConnectionSettings()); internal static object CreateGenericInstance(this Type t, Type closeOver, params object[] args) => - t.CreateGenericInstance(new[] {closeOver}, args); + t.CreateGenericInstance(new[] { closeOver }, args); internal static object CreateGenericInstance(this Type t, Type[] closeOver, params object[] args) { @@ -47,7 +50,7 @@ internal static object CreateGenericInstance(this Type t, Type[] closeOver, para return closedType.CreateInstance(args); } - internal static T CreateInstance(this Type t, params object[] args) => (T) t.CreateInstance(args); + internal static T CreateInstance(this Type t, params object[] args) => (T)t.CreateInstance(args); internal static object CreateInstance(this Type t, params object[] args) { @@ -58,15 +61,16 @@ internal static object CreateInstance(this Type t, params object[] args) var generic = GetActivatorMethodInfo.MakeGenericMethod(t); var constructors = from c in t.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) - let p = c.GetParameters() - let k = string.Join(",", p.Select(a => a.ParameterType.Name)) - where p.Length == args.Length - select c; + let p = c.GetParameters() + let k = string.Join(",", p.Select(a => a.ParameterType.Name)) + where p.Length == args.Length + select c; var ctor = constructors.FirstOrDefault(); if (ctor == null) throw new Exception($"Cannot create an instance of {t.FullName} because it has no constructor taking {args.Length} arguments"); - activator = (ObjectActivator) generic.Invoke(null, new object[] {ctor}); + + activator = (ObjectActivator)generic.Invoke(null, new object[] { ctor }); CachedActivators.TryAdd(key, activator); return activator(args); } @@ -74,10 +78,12 @@ internal static object CreateInstance(this Type t, params object[] args) internal static object DefaultValue(this Type type) => type.IsValueType() ? CachedDefaultValues.GetOrAdd(type, t => - Expression.Lambda>( - Expression.Convert(Expression.Default(type), typeof(object)) - ).Compile() - ).Invoke() + Expression.Lambda>( + Expression.Convert(Expression.Default(type), typeof(object)) + ) + .Compile() + ) + .Invoke() : null; //do not remove this is referenced through GetActivatorMethod @@ -111,19 +117,17 @@ private static ObjectActivator GetActivator(ConstructorInfo ctor) var lambda = Expression.Lambda(typeof(ObjectActivator), newExp, param); //compile it - var compiled = (ObjectActivator) lambda.Compile(); + var compiled = (ObjectActivator)lambda.Compile(); return compiled; } - //this contract is only used to resolve properties in class WE OWN. - //these are not subject to change depending on what the user passes as connectionsettings - private static readonly ElasticContractResolver JsonContract = new ElasticContractResolver(new ConnectionSettings()); - internal static IList GetCachedObjectProperties(this Type t, - MemberSerialization memberSerialization = MemberSerialization.OptIn) + MemberSerialization memberSerialization = MemberSerialization.OptIn + ) { if (CachedTypeProperties.TryGetValue(t, out var propertyDictionary)) return propertyDictionary; + propertyDictionary = JsonContract.PropertiesOfAll(t, memberSerialization); CachedTypeProperties.TryAdd(t, propertyDictionary); return propertyDictionary; @@ -133,6 +137,7 @@ internal static IList AllPropertiesCached(this Type t) { if (CachedTypePropertyInfos.TryGetValue(t, out var propertyInfos)) return propertyInfos; + propertyInfos = t.AllPropertiesNotCached().ToList(); CachedTypePropertyInfos.TryAdd(t, propertyInfos); return propertyInfos; @@ -150,15 +155,10 @@ private static IEnumerable AllPropertiesNotCached(this Type type) { if (propertiesByName.ContainsKey(propertyInfo.Name)) { - if (IsHidingMember(propertyInfo)) - { - propertiesByName[propertyInfo.Name] = propertyInfo; - } + if (IsHidingMember(propertyInfo)) propertiesByName[propertyInfo.Name] = propertyInfo; } else - { propertiesByName.Add(propertyInfo.Name, propertyInfo); - } } #if DOTNETCORE type = type.GetTypeInfo()?.BaseType; @@ -182,9 +182,11 @@ private static bool IsHidingMember(PropertyInfo propertyInfo) #endif var baseProperty = baseType?.GetProperty(propertyInfo.Name); if (baseProperty == null) return false; + var derivedGetMethod = propertyInfo.GetGetMethod().GetBaseDefinition(); return derivedGetMethod?.ReturnType != propertyInfo.PropertyType; } + + private delegate T ObjectActivator(params object[] args); } } - diff --git a/src/Nest/CommonAbstractions/Fields/FieldValues.cs b/src/Nest/CommonAbstractions/Fields/FieldValues.cs index c8de281d885..4f88f8a8554 100644 --- a/src/Nest/CommonAbstractions/Fields/FieldValues.cs +++ b/src/Nest/CommonAbstractions/Fields/FieldValues.cs @@ -1,11 +1,8 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Linq.Expressions; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Nest { @@ -14,15 +11,20 @@ public class FieldValues : IsADictionaryBase { public static readonly FieldValues Empty = new FieldValues(); + private static readonly HashSet NumericTypes = new HashSet + { + typeof(int), typeof(double), typeof(decimal), + typeof(long), typeof(short), typeof(sbyte), + typeof(byte), typeof(ulong), typeof(ushort), + typeof(uint), typeof(float) + }; + private readonly Inferrer _inferrer; protected FieldValues() : base() { } internal FieldValues(Inferrer inferrer, IDictionary container) - : base(container) - { - _inferrer = inferrer; - } + : base(container) => _inferrer = inferrer; public TValue Value(Field field) { @@ -43,34 +45,29 @@ public TValue ValueOf(Expression> objectPath) public TValue[] ValuesOf(Field field) { - if (this._inferrer == null) return new TValue[0]; - var path = this._inferrer.Field(field); - return this.FieldArray(path); + if (_inferrer == null) return new TValue[0]; + + var path = _inferrer.Field(field); + return FieldArray(path); } public TValue[] Values(Expression> objectPath) where T : class { - if (this._inferrer == null) return new TValue[0]; - var field = this._inferrer.Field(objectPath); - return this.FieldArray(field); - } + if (_inferrer == null) return new TValue[0]; - private static readonly HashSet NumericTypes = new HashSet - { - typeof(int), typeof(double), typeof(decimal), - typeof(long), typeof(short), typeof(sbyte), - typeof(byte), typeof(ulong), typeof(ushort), - typeof(uint), typeof(float) - }; + var field = _inferrer.Field(objectPath); + return FieldArray(field); + } public static bool IsNumeric(Type myType) => NumericTypes.Contains(Nullable.GetUnderlyingType(myType) ?? myType); + public static bool IsNullable(Type type) => type.IsGeneric() && type.GetGenericTypeDefinition() == typeof(Nullable<>); private TValue[] FieldArray(string field) { //unknown field - if (this.BackingDictionary == null || !this.BackingDictionary.TryGetValue(field, out var o)) + if (BackingDictionary == null || !BackingDictionary.TryGetValue(field, out var o)) return null; //numerics are always returned as doubles by elasticsearch. @@ -79,15 +76,17 @@ private TValue[] FieldArray(string field) //here we support casting to the desired numeric type whether its nullable or not. if (!IsNullable(typeof(TValue))) - return o.As().Select(d => (TValue) Convert.ChangeType(d, typeof(TValue))).ToArray(); + return o.As().Select(d => (TValue)Convert.ChangeType(d, typeof(TValue))).ToArray(); var underlyingType = Nullable.GetUnderlyingType(typeof(TValue)); - return o.As().Select(d=> - { - if (d == null) return default(TValue); - return (TValue) Convert.ChangeType(d, underlyingType); - }).ToArray(); + return o.As() + .Select(d => + { + if (d == null) return default(TValue); + return (TValue)Convert.ChangeType(d, underlyingType); + }) + .ToArray(); } } } diff --git a/src/Nest/CommonAbstractions/Fields/FieldValuesJsonConverter.cs b/src/Nest/CommonAbstractions/Fields/FieldValuesJsonConverter.cs index 262b5ec8e6c..faf28b96d06 100644 --- a/src/Nest/CommonAbstractions/Fields/FieldValuesJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Fields/FieldValuesJsonConverter.cs @@ -1,10 +1,7 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; +using System; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace Nest { @@ -12,10 +9,7 @@ internal class FieldValuesJsonConverter : JsonConverter { public override bool CanWrite => false; - public override bool CanConvert(Type objectType) - { - throw new NotSupportedException(); - } + public override bool CanConvert(Type objectType) => throw new NotSupportedException(); public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { @@ -27,9 +21,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return fieldValues; } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotSupportedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); } } diff --git a/src/Nest/CommonAbstractions/Fluent/DescriptorBase.cs b/src/Nest/CommonAbstractions/Fluent/DescriptorBase.cs index 86b717f5dae..d55a0646182 100644 --- a/src/Nest/CommonAbstractions/Fluent/DescriptorBase.cs +++ b/src/Nest/CommonAbstractions/Fluent/DescriptorBase.cs @@ -11,17 +11,14 @@ public abstract class DescriptorBase : IDescriptor { private readonly TDescriptor _self; - protected DescriptorBase() - { - _self = (TDescriptor)this; - } + protected DescriptorBase() => _self = (TDescriptor)this; protected TInterface Self => _self; protected TDescriptor Assign(Action assigner) => Fluent.Assign(_self, assigner); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -30,7 +27,7 @@ protected DescriptorBase() public override bool Equals(object obj) => base.Equals(obj); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -39,7 +36,7 @@ protected DescriptorBase() public override int GetHashCode() => base.GetHashCode(); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Nest/CommonAbstractions/Fluent/Fluent.cs b/src/Nest/CommonAbstractions/Fluent/Fluent.cs index 77006c555a5..2b58e0783b2 100644 --- a/src/Nest/CommonAbstractions/Fluent/Fluent.cs +++ b/src/Nest/CommonAbstractions/Fluent/Fluent.cs @@ -11,5 +11,4 @@ internal static TDescriptor Assign(TDescriptor self, Ac return self; } } - -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/Fluent/FluentDictionary.cs b/src/Nest/CommonAbstractions/Fluent/FluentDictionary.cs index 01a52b6dbf1..fe6ec9099ab 100644 --- a/src/Nest/CommonAbstractions/Fluent/FluentDictionary.cs +++ b/src/Nest/CommonAbstractions/Fluent/FluentDictionary.cs @@ -4,9 +4,7 @@ namespace Nest { public class FluentDictionary : Dictionary { - public FluentDictionary() - { - } + public FluentDictionary() { } public FluentDictionary(IDictionary copy) { @@ -29,4 +27,4 @@ public FluentDictionary(IDictionary copy) return this; } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/Fluent/Promise/DescriptorPromiseBase.cs b/src/Nest/CommonAbstractions/Fluent/Promise/DescriptorPromiseBase.cs index f8364d1c024..276bf801d77 100644 --- a/src/Nest/CommonAbstractions/Fluent/Promise/DescriptorPromiseBase.cs +++ b/src/Nest/CommonAbstractions/Fluent/Promise/DescriptorPromiseBase.cs @@ -8,40 +8,41 @@ public interface IPromise where TValue : class TValue Value { get; } } - public abstract class DescriptorPromiseBase : IDescriptor, IPromise + public abstract class DescriptorPromiseBase : IDescriptor, IPromise where TDescriptor : DescriptorPromiseBase where TValue : class { internal readonly TValue PromisedValue; - TValue IPromise.Value => PromisedValue; - protected DescriptorPromiseBase(TValue instance) { this.PromisedValue = instance; } + protected DescriptorPromiseBase(TValue instance) => PromisedValue = instance; + + TValue IPromise.Value => PromisedValue; protected TDescriptor Assign(Action assigner) { - assigner(this.PromisedValue); - return (TDescriptor) this; + assigner(PromisedValue); + return (TDescriptor)this; } /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) => base.Equals(obj); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => base.GetHashCode(); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string ToString() => base.ToString(); } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/Fluent/SelectorBase.cs b/src/Nest/CommonAbstractions/Fluent/SelectorBase.cs index f3357b270f7..f645e920f96 100644 --- a/src/Nest/CommonAbstractions/Fluent/SelectorBase.cs +++ b/src/Nest/CommonAbstractions/Fluent/SelectorBase.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel; +using System.ComponentModel; namespace Nest { @@ -8,7 +7,7 @@ public interface ISelector { } public abstract class SelectorBase : ISelector where TInterface : class { /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -17,7 +16,7 @@ public abstract class SelectorBase : ISelector where TInterface : cl public override bool Equals(object obj) => base.Equals(obj); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -26,7 +25,7 @@ public abstract class SelectorBase : ISelector where TInterface : cl public override int GetHashCode() => base.GetHashCode(); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Nest/CommonAbstractions/ForAttribute.cs b/src/Nest/CommonAbstractions/ForAttribute.cs index eca5770260b..184f81876b0 100644 --- a/src/Nest/CommonAbstractions/ForAttribute.cs +++ b/src/Nest/CommonAbstractions/ForAttribute.cs @@ -7,25 +7,22 @@ namespace Nest /// This is used by the code generator and is only meant for internal use to map our more aptly named requests to /// the original elasticsearch rest spec /// - [AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] internal class DescriptorForAttribute : Attribute { - // ReSharper disable once UnusedParameter.Local - public DescriptorForAttribute (string operation) { } - + public DescriptorForAttribute(string operation) { } } + /// /// DescriptorFor is a marker to rename unintuitive generated elasticsearch operation names /// This is used by the code generator and is only meant for internal use to map our more aptly named requests to /// the original elasticsearch rest spec /// - [AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Interface, AllowMultiple = false)] internal class MapsApiAttribute : Attribute { - // ReSharper disable once UnusedParameter.Local - public MapsApiAttribute (string restSpecName) { } - + public MapsApiAttribute(string restSpecName) { } } } diff --git a/src/Nest/CommonAbstractions/Infer/ActionIds/ActionIds.cs b/src/Nest/CommonAbstractions/Infer/ActionIds/ActionIds.cs index 72a8489068a..478ad5a865e 100644 --- a/src/Nest/CommonAbstractions/Infer/ActionIds/ActionIds.cs +++ b/src/Nest/CommonAbstractions/Infer/ActionIds/ActionIds.cs @@ -10,40 +10,37 @@ namespace Nest public class ActionIds : IUrlParameter, IEquatable { private readonly List _actionIds; - internal IReadOnlyList Ids => _actionIds; - - public ActionIds(IEnumerable actionIds) - { - this._actionIds = actionIds?.ToList() ?? new List(); - } - - public ActionIds(string actionIds) - { - this._actionIds = actionIds.IsNullOrEmpty() - ? new List() - : actionIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) - .Select(s => s.Trim()) - .ToList(); - } - private string DebugDisplay => ((IUrlParameter)this).GetString(null); + public ActionIds(IEnumerable actionIds) => _actionIds = actionIds?.ToList() ?? new List(); - string IUrlParameter.GetString(IConnectionConfigurationValues settings) => string.Join(",", this._actionIds); + public ActionIds(string actionIds) => _actionIds = actionIds.IsNullOrEmpty() + ? new List() + : actionIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) + .Select(s => s.Trim()) + .ToList(); - public static implicit operator ActionIds(string actionIds) => actionIds.IsNullOrEmptyCommaSeparatedList(out var list) ? null : new ActionIds(list); + internal IReadOnlyList Ids => _actionIds; - public static implicit operator ActionIds(string[] actionIds) => actionIds.IsEmpty() ? null : new ActionIds(actionIds); + private string DebugDisplay => ((IUrlParameter)this).GetString(null); public bool Equals(ActionIds other) { - if (this.Ids == null && other.Ids == null) return true; - if (this.Ids == null || other.Ids == null) return false; - return this.Ids.Count == other.Ids.Count && !this.Ids.Except(other.Ids).Any(); + if (Ids == null && other.Ids == null) return true; + if (Ids == null || other.Ids == null) return false; + + return Ids.Count == other.Ids.Count && !Ids.Except(other.Ids).Any(); } + string IUrlParameter.GetString(IConnectionConfigurationValues settings) => string.Join(",", _actionIds); + + public static implicit operator ActionIds(string actionIds) => + actionIds.IsNullOrEmptyCommaSeparatedList(out var list) ? null : new ActionIds(list); + + public static implicit operator ActionIds(string[] actionIds) => actionIds.IsEmpty() ? null : new ActionIds(actionIds); + public override bool Equals(object obj) => obj is ActionIds other && Equals(other); - public override int GetHashCode() => this._actionIds.GetHashCode(); + public override int GetHashCode() => _actionIds.GetHashCode(); public static bool operator ==(ActionIds left, ActionIds right) => Equals(left, right); diff --git a/src/Nest/CommonAbstractions/Infer/CategoryId/CategoryId.cs b/src/Nest/CommonAbstractions/Infer/CategoryId/CategoryId.cs index df4e1801e22..f00a8437140 100644 --- a/src/Nest/CommonAbstractions/Infer/CategoryId/CategoryId.cs +++ b/src/Nest/CommonAbstractions/Infer/CategoryId/CategoryId.cs @@ -10,26 +10,27 @@ public class CategoryId : IUrlParameter, IEquatable public CategoryId(long value) => Value = value; - public static implicit operator CategoryId(long categoryId) => new CategoryId(categoryId); - public static implicit operator long(CategoryId categoryId) => categoryId.Value; + public bool Equals(CategoryId other) => Value == other.Value; // ReSharper disable once ImpureMethodCallOnReadonlyValueField public string GetString(IConnectionConfigurationValues settings) => Value.ToString(CultureInfo.InvariantCulture); - public bool Equals(CategoryId other) => this.Value == other.Value; + public static implicit operator CategoryId(long categoryId) => new CategoryId(categoryId); + + public static implicit operator long(CategoryId categoryId) => categoryId.Value; public override bool Equals(object obj) { switch (obj) { - case int l: return this.Value == l; - case long l: return this.Value == l; - case CategoryId i: return this.Value == i.Value; + case int l: return Value == l; + case long l: return Value == l; + case CategoryId i: return Value == i.Value; default: return false; } } - public override int GetHashCode() => this.Value.GetHashCode(); + public override int GetHashCode() => Value.GetHashCode(); public static bool operator ==(CategoryId left, CategoryId right) => Equals(left, right); diff --git a/src/Nest/CommonAbstractions/Infer/DocumentPath/DocumentPath.cs b/src/Nest/CommonAbstractions/Infer/DocumentPath/DocumentPath.cs index cf49fdb5c86..5297dda181b 100644 --- a/src/Nest/CommonAbstractions/Infer/DocumentPath/DocumentPath.cs +++ b/src/Nest/CommonAbstractions/Infer/DocumentPath/DocumentPath.cs @@ -11,13 +11,8 @@ public interface IDocumentPath public class DocumentPath : IEquatable>, IDocumentPath where T : class { - internal IDocumentPath Self => this; - internal T Document { get; set; } - Id IDocumentPath.Id { get; set; } - IndexName IDocumentPath.Index { get; set; } - TypeName IDocumentPath.Type { get; set; } + public DocumentPath(T document) : this(Nest.Id.From(document)) => Document = document; - public DocumentPath(T document) : this(Nest.Id.From(document)) { this.Document = document; } public DocumentPath(Id id) { Self.Id = id; @@ -25,24 +20,45 @@ public DocumentPath(Id id) Self.Type = typeof(T); } + internal T Document { get; set; } + internal IDocumentPath Self => this; + Id IDocumentPath.Id { get; set; } + IndexName IDocumentPath.Index { get; set; } + TypeName IDocumentPath.Type { get; set; } + + public bool Equals(DocumentPath other) + { + IDocumentPath o = other, s = Self; + return s.Index.NullOrEquals(o.Index) && s.Type.NullOrEquals(o.Type) && s.Id.NullOrEquals(o.Id) + && (Document?.Equals(other.Document) ?? true); + } + public static DocumentPath Id(Id id) => new DocumentPath(id); + public static DocumentPath Id(T @object) => new DocumentPath(@object); public static implicit operator DocumentPath(T @object) => @object == null ? null : new DocumentPath(@object); + public static implicit operator DocumentPath(Id id) => id == null ? null : new DocumentPath(id); + public static implicit operator DocumentPath(long id) => new DocumentPath(id); + public static implicit operator DocumentPath(string id) => id.IsNullOrEmpty() ? null : new DocumentPath(id); + public static implicit operator DocumentPath(Guid id) => new DocumentPath(id); public DocumentPath Index(IndexName index) { if (index == null) return this; + Self.Index = index; return this; } + public DocumentPath Type(TypeName type) { if (type == null) return this; + Self.Type = type; return this; } @@ -58,24 +74,17 @@ public override int GetHashCode() } } - public bool Equals(DocumentPath other) - { - IDocumentPath o = other, s = Self; - return s.Index.NullOrEquals(o.Index) && s.Type.NullOrEquals(o.Type) && s.Id.NullOrEquals(o.Id) - && (this.Document?.Equals(other.Document) ?? true); - } - public override bool Equals(object obj) { switch (obj) { - case DocumentPath d: return this.Equals(d); + case DocumentPath d: return Equals(d); default: return false; } } public static bool operator ==(DocumentPath x, DocumentPath y) => Equals(x, y); - public static bool operator !=(DocumentPath x, DocumentPath y)=> !Equals(x, y); + public static bool operator !=(DocumentPath x, DocumentPath y) => !Equals(x, y); } } diff --git a/src/Nest/CommonAbstractions/Infer/Field/Field.cs b/src/Nest/CommonAbstractions/Infer/Field/Field.cs index a2e1715dc8c..5018be3bb51 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/Field.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/Field.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.Globalization; -using System.Linq; using System.Linq.Expressions; using System.Reflection; using Elasticsearch.Net; @@ -15,30 +14,6 @@ public class Field : IEquatable, IUrlParameter private readonly object _comparisonValue; private readonly Type _type; - public string Name { get; } - - public Expression Expression { get; } - - public PropertyInfo Property { get; } - - public double? Boost { get; set; } - - public bool CachableExpression { get; } - - internal string DebugDisplay => - $"{Expression?.ToString() ?? PropertyDebug ?? Name}{(Boost.HasValue ? "^" + Boost.Value: "")}{(_type == null ? "" : " typeof: " + _type.Name)}"; - - private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}"; - - public Fields And(Field field) => new Fields(new [] { this, field }); - - public Fields And(Expression> field, double? boost = null) where T : class => - new Fields(new [] { this, new Field(field, boost) }); - - public Fields And(string field, double? boost = null) => new Fields(new [] { this, new Field(field, boost) }); - - public Fields And(PropertyInfo property, double? boost = null) => new Fields(new [] { this, new Field(property, boost) }); - public Field(string name, double? boost = null) { name.ThrowIfNullOrEmpty(nameof(name)); @@ -65,13 +40,51 @@ public Field(PropertyInfo property, double? boost = null) _type = property.DeclaringType; } + public double? Boost { get; set; } + + public bool CachableExpression { get; } + + public Expression Expression { get; } + + public string Name { get; } + + public PropertyInfo Property { get; } + + internal string DebugDisplay => + $"{Expression?.ToString() ?? PropertyDebug ?? Name}{(Boost.HasValue ? "^" + Boost.Value : "")}{(_type == null ? "" : " typeof: " + _type.Name)}"; + + private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}"; + + public bool Equals(Field other) => _type != null + ? other != null && _type == other._type && _comparisonValue.Equals(other._comparisonValue) + : other != null && _comparisonValue.Equals(other._comparisonValue); + + string IUrlParameter.GetString(IConnectionConfigurationValues settings) + { + if (!(settings is IConnectionSettingsValues nestSettings)) + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(Field)} if no {nameof(IConnectionSettingsValues)} is provided"); + + return nestSettings.Inferrer.Field(this); + } + + public Fields And(Field field) => new Fields(new[] { this, field }); + + public Fields And(Expression> field, double? boost = null) where T : class => + new Fields(new[] { this, new Field(field, boost) }); + + public Fields And(string field, double? boost = null) => new Fields(new[] { this, new Field(field, boost) }); + + public Fields And(PropertyInfo property, double? boost = null) => new Fields(new[] { this, new Field(property, boost) }); + private static string ParseFieldName(string name, out double? boost) { boost = null; if (name == null) return null; - var parts = name.Split(new [] { '^' }, StringSplitOptions.RemoveEmptyEntries); + var parts = name.Split(new[] { '^' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length <= 1) return name; + name = parts[0]; boost = double.Parse(parts[1], CultureInfo.InvariantCulture); return name; @@ -93,35 +106,19 @@ public override int GetHashCode() } } - public bool Equals(Field other) - { - return _type != null - ? other != null && _type == other._type && _comparisonValue.Equals(other._comparisonValue) - : other != null && _comparisonValue.Equals(other._comparisonValue); - } - public override bool Equals(object obj) { switch (obj) { - case string s: return this.Equals(s); - case PropertyInfo p: return this.Equals(p); - case Field f: return this.Equals(f); + case string s: return Equals(s); + case PropertyInfo p: return Equals(p); + case Field f: return Equals(f); default: return false; } } public static bool operator ==(Field x, Field y) => Equals(x, y); - public static bool operator !=(Field x, Field y)=> !Equals(x, y); - - string IUrlParameter.GetString(IConnectionConfigurationValues settings) - { - if (!(settings is IConnectionSettingsValues nestSettings)) - throw new ArgumentNullException(nameof(settings), $"Can not resolve {nameof(Field)} if no {nameof(IConnectionSettingsValues)} is provided"); - - return nestSettings.Inferrer.Field(this); - } - + public static bool operator !=(Field x, Field y) => !Equals(x, y); } } diff --git a/src/Nest/CommonAbstractions/Infer/Field/FieldExpressionVisitor.cs b/src/Nest/CommonAbstractions/Infer/Field/FieldExpressionVisitor.cs index e937d5115ba..72c0e241367 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/FieldExpressionVisitor.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/FieldExpressionVisitor.cs @@ -1,6 +1,4 @@ -using Elasticsearch.Net; -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -8,29 +6,30 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Text; -using System.Threading.Tasks; namespace Nest { internal class HasVariableExpressionVisitor : ExpressionVisitor { private bool _found; + + public HasVariableExpressionVisitor(Expression e) => Visit(e); + public bool Found { get => _found; // This is only set to true once to prevent clobbering from subsequent node visits - private set { if (!_found) _found = value; } - } - - public HasVariableExpressionVisitor(Expression e) - { - this.Visit(e); + private set + { + if (!_found) _found = value; + } } public override Expression Visit(Expression node) { - if (!this.Found) + if (!Found) return base.Visit(node); + return node; } @@ -39,7 +38,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) if (node.Method.Name == nameof(SuffixExtensions.Suffix) && node.Arguments.Any()) { var lastArg = node.Arguments.Last(); - this.Found = !(lastArg is ConstantExpression); + Found = !(lastArg is ConstantExpression); } else if (node.Method.Name == "get_Item" && node.Arguments.Any()) { @@ -47,12 +46,13 @@ protected override Expression VisitMethodCall(MethodCallExpression node) var isDict = typeof(IDictionary).IsAssignableFrom(t) || typeof(IDictionary<,>).IsAssignableFrom(t) - || (t.IsGeneric() && t.GetGenericTypeDefinition() == typeof(IDictionary<,>)); + || t.IsGeneric() && t.GetGenericTypeDefinition() == typeof(IDictionary<,>); if (!isDict) return base.VisitMethodCall(node); + var lastArg = node.Arguments.Last(); - this.Found = !(lastArg is ConstantExpression); + Found = !(lastArg is ConstantExpression); } return base.VisitMethodCall(node); } @@ -60,24 +60,21 @@ protected override Expression VisitMethodCall(MethodCallExpression node) internal class FieldExpressionVisitor : ExpressionVisitor { - private readonly Stack _stack = new Stack(); - private readonly IConnectionSettingsValues _settings; + private readonly Stack _stack = new Stack(); - public FieldExpressionVisitor(IConnectionSettingsValues settings) - { - _settings = settings; - } + public FieldExpressionVisitor(IConnectionSettingsValues settings) => _settings = settings; public string Resolve(Expression expression, bool toLastToken = false) { Visit(expression); if (toLastToken) return _stack.Last(); + return _stack .Aggregate( new StringBuilder(), (sb, name) => - (sb.Length > 0 ? sb.Append(".") : sb).Append(name)) + (sb.Length > 0 ? sb.Append(".") : sb).Append(name)) .ToString(); } @@ -88,7 +85,7 @@ public string Resolve(MemberInfo info) var name = info.Name; - if (this._settings.PropertyMappings.TryGetValue(info, out var propertyMapping)) + if (_settings.PropertyMappings.TryGetValue(info, out var propertyMapping)) return propertyMapping.Name; var att = ElasticsearchPropertyAttributeBase.From(info); @@ -101,7 +98,8 @@ public string Resolve(MemberInfo info) protected override Expression VisitMember(MemberExpression expression) { if (_stack == null) return base.VisitMember(expression); - var name = this.Resolve(expression.Member); + + var name = Resolve(expression.Member); _stack.Push(name); return base.VisitMember(expression); } @@ -114,7 +112,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall) var callingMember = new ReadOnlyCollection( new List { { methodCall.Arguments.First() } } ); - base.Visit(callingMember); + Visit(callingMember); return methodCall; } else if (methodCall.Method.Name == "get_Item" && methodCall.Arguments.Any()) @@ -123,22 +121,17 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall) var isDict = typeof(IDictionary).IsAssignableFrom(t) || typeof(IDictionary<,>).IsAssignableFrom(t) - || (t.IsGeneric() && t.GetGenericTypeDefinition() == typeof(IDictionary<,>)); + || t.IsGeneric() && t.GetGenericTypeDefinition() == typeof(IDictionary<,>); + + if (!isDict) return base.VisitMethodCall(methodCall); - if (!isDict) - { - return base.VisitMethodCall(methodCall); - } VisitConstantOrVariable(methodCall, _stack); Visit(methodCall.Object); return methodCall; } else if (IsLinqOperator(methodCall.Method)) { - for (int i = 1; i < methodCall.Arguments.Count; i++) - { - Visit(methodCall.Arguments[i]); - } + for (var i = 1; i < methodCall.Arguments.Count; i++) Visit(methodCall.Arguments[i]); Visit(methodCall.Arguments[0]); return methodCall; } diff --git a/src/Nest/CommonAbstractions/Infer/Field/FieldExtensions.cs b/src/Nest/CommonAbstractions/Infer/Field/FieldExtensions.cs index ae58e6e36cd..cec777345fb 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/FieldExtensions.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/FieldExtensions.cs @@ -4,10 +4,9 @@ namespace Nest { internal static class FieldExtensions { - internal static bool IsConditionless(this Field field) - { - return field == null || (field.Name.IsNullOrEmpty() && field.Expression == null && field.Property == null); - } + internal static bool IsConditionless(this Field field) => + field == null || field.Name.IsNullOrEmpty() && field.Expression == null && field.Property == null; + internal static bool IsConditionless(this Fields field) => field?.ListOfFields == null || field.ListOfFields.All(l => l.IsConditionless()); } } diff --git a/src/Nest/CommonAbstractions/Infer/Field/FieldJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/Field/FieldJsonConverter.cs index dee9b6291c1..1cdfdc8da47 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/FieldJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/FieldJsonConverter.cs @@ -22,12 +22,13 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s var settings = serializer.GetConnectionSettings(); writer.WriteValue(settings.Inferrer.Field(field)); } + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.String) return null; + var field = reader.Value.ToString(); return (Field)field; } } } - diff --git a/src/Nest/CommonAbstractions/Infer/Field/FieldResolver.cs b/src/Nest/CommonAbstractions/Infer/Field/FieldResolver.cs index b258d5fb31c..3e70e01dc83 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/FieldResolver.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/FieldResolver.cs @@ -1,29 +1,21 @@ using System; -using System.Collections; using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Globalization; -using System.Linq; using System.Linq.Expressions; using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using Elasticsearch.Net; namespace Nest { public class FieldResolver { - private readonly IConnectionSettingsValues _settings; - protected readonly ConcurrentDictionary Fields = new ConcurrentDictionary(); protected readonly ConcurrentDictionary Properties = new ConcurrentDictionary(); + private readonly IConnectionSettingsValues _settings; public FieldResolver(IConnectionSettingsValues settings) { settings.ThrowIfNull(nameof(settings)); - this._settings = settings; + _settings = settings; } public string Resolve(Field field) @@ -37,16 +29,13 @@ private string ResolveFieldName(Field field) { if (field.IsConditionless()) return null; if (!field.Name.IsNullOrEmpty()) return field.Name; - if (field.Expression != null && !field.CachableExpression) - { - return this.Resolve(field.Expression, field.Property); - } + if (field.Expression != null && !field.CachableExpression) return Resolve(field.Expression, field.Property); - if (this.Fields.TryGetValue(field, out var fieldName)) + if (Fields.TryGetValue(field, out var fieldName)) return fieldName; - fieldName = this.Resolve(field.Expression, field.Property); - this.Fields.TryAdd(field, fieldName); + fieldName = Resolve(field.Expression, field.Property); + Fields.TryAdd(field, fieldName); return fieldName; } @@ -55,16 +44,13 @@ public string Resolve(PropertyName property) if (property.IsConditionless()) return null; if (!property.Name.IsNullOrEmpty()) return property.Name; - if (property.Expression != null && !property.CacheableExpression) - { - return this.Resolve(property.Expression, property.Property); - } + if (property.Expression != null && !property.CacheableExpression) return Resolve(property.Expression, property.Property); - if (this.Properties.TryGetValue(property, out var propertyName)) + if (Properties.TryGetValue(property, out var propertyName)) return propertyName; - propertyName = this.Resolve(property.Expression, property.Property, true); - this.Properties.TryAdd(property, propertyName); + propertyName = Resolve(property.Expression, property.Property, true); + Properties.TryAdd(property, propertyName); return propertyName; } diff --git a/src/Nest/CommonAbstractions/Infer/Fields/Fields.cs b/src/Nest/CommonAbstractions/Infer/Fields/Fields.cs index e25d80bdccd..357a819e756 100644 --- a/src/Nest/CommonAbstractions/Infer/Fields/Fields.cs +++ b/src/Nest/CommonAbstractions/Infer/Fields/Fields.cs @@ -15,89 +15,92 @@ public class Fields : IUrlParameter, IEnumerable, IEquatable { internal readonly List ListOfFields; + internal Fields() => ListOfFields = new List(); + + internal Fields(IEnumerable fieldNames) => ListOfFields = fieldNames.ToList(); + + private string DebugDisplay => + $"Count: {ListOfFields.Count} [" + string.Join(",", ListOfFields.Select((t, i) => $"({i + 1}: {t?.DebugDisplay ?? "NULL"})")) + "]"; + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public IEnumerator GetEnumerator() => ListOfFields.GetEnumerator(); + + public bool Equals(Fields other) => EqualsAllFields(ListOfFields, other.ListOfFields); + string IUrlParameter.GetString(IConnectionConfigurationValues settings) { if (!(settings is IConnectionSettingsValues nestSettings)) - throw new ArgumentNullException(nameof(settings), $"Can not resolve {nameof(Fields)} if no {nameof(IConnectionSettingsValues)} is provided"); + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(Fields)} if no {nameof(IConnectionSettingsValues)} is provided"); return string.Join(",", ListOfFields.Where(f => f != null).Select(f => ((IUrlParameter)f).GetString(nestSettings))); } - private string DebugDisplay => - $"Count: {ListOfFields.Count} [" + string.Join(",", ListOfFields.Select((t, i) => $"({i + 1}: {t?.DebugDisplay ?? "NULL"})")) + "]"; - - internal Fields() { this.ListOfFields = new List(); } - internal Fields(IEnumerable fieldNames) { this.ListOfFields = fieldNames.ToList(); } - public static implicit operator Fields(string[] fields) => fields.IsEmpty() ? null : new Fields(fields.Select(f => (Field)f)); public static implicit operator Fields(string field) => field.IsNullOrEmptyCommaSeparatedList(out var split) - ? null : new Fields(split.Select(f=>(Field)f)); + ? null + : new Fields(split.Select(f => (Field)f)); public static implicit operator Fields(Expression[] fields) => fields.IsEmpty() ? null : new Fields(fields.Select(f => (Field)f)); - public static implicit operator Fields(Expression field) => field == null ? null : new Fields(new [] { (Field)field }); + public static implicit operator Fields(Expression field) => field == null ? null : new Fields(new[] { (Field)field }); public static implicit operator Fields(Field field) => field == null ? null : new Fields(new[] { field }); public static implicit operator Fields(PropertyInfo field) => field == null ? null : new Fields(new Field[] { field }); - public static implicit operator Fields(PropertyInfo[] fields) => fields.IsEmpty() ? null : new Fields(fields.Select(f=>(Field)f)); + public static implicit operator Fields(PropertyInfo[] fields) => fields.IsEmpty() ? null : new Fields(fields.Select(f => (Field)f)); public static implicit operator Fields(Field[] fields) => fields.IsEmpty() ? null : new Fields(fields); public Fields And(Expression> field, double? boost = null) where T : class { - this.ListOfFields.Add(new Field(field, boost)); + ListOfFields.Add(new Field(field, boost)); return this; } public Fields And(string field, double? boost = null) { - this.ListOfFields.Add(new Field(field, boost)); + ListOfFields.Add(new Field(field, boost)); return this; } public Fields And(PropertyInfo property, double? boost = null) { - this.ListOfFields.Add(new Field(property, boost)); + ListOfFields.Add(new Field(property, boost)); return this; } public Fields And(params Expression>[] fields) where T : class { - this.ListOfFields.AddRange(fields.Select(f => (Field)f)); + ListOfFields.AddRange(fields.Select(f => (Field)f)); return this; } public Fields And(params string[] fields) { - this.ListOfFields.AddRange(fields.Select(f => (Field)f)); + ListOfFields.AddRange(fields.Select(f => (Field)f)); return this; } public Fields And(params PropertyInfo[] properties) { - this.ListOfFields.AddRange(properties.Select(f => (Field)f)); + ListOfFields.AddRange(properties.Select(f => (Field)f)); return this; } public Fields And(params Field[] fields) { - this.ListOfFields.AddRange(fields); + ListOfFields.AddRange(fields); return this; } - public IEnumerator GetEnumerator() => this.ListOfFields.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); - public static bool operator ==(Fields left, Fields right) => Equals(left, right); public static bool operator !=(Fields left, Fields right) => !Equals(left, right); - public bool Equals(Fields other) => EqualsAllFields(this.ListOfFields, other.ListOfFields); - public override bool Equals(object obj) { switch (obj) @@ -117,9 +120,10 @@ private static bool EqualsAllFields(IReadOnlyList thisTypes, IReadOnlyLis if (thisTypes == null && otherTypes == null) return true; if (thisTypes == null || otherTypes == null) return false; if (thisTypes.Count != otherTypes.Count) return false; + return thisTypes.Count == otherTypes.Count && !thisTypes.Except(otherTypes).Any(); } - public override int GetHashCode() => this.ListOfFields.GetHashCode(); + public override int GetHashCode() => ListOfFields.GetHashCode(); } } diff --git a/src/Nest/CommonAbstractions/Infer/Fields/FieldsDescriptor.cs b/src/Nest/CommonAbstractions/Infer/Fields/FieldsDescriptor.cs index 73c7391b38e..64723a8caec 100644 --- a/src/Nest/CommonAbstractions/Infer/Fields/FieldsDescriptor.cs +++ b/src/Nest/CommonAbstractions/Infer/Fields/FieldsDescriptor.cs @@ -10,11 +10,15 @@ public class FieldsDescriptor : DescriptorPromiseBase, Fi public FieldsDescriptor() : base(new Fields()) { } public FieldsDescriptor Fields(params Expression>[] fields) => Assign(f => f.And(fields)); + public FieldsDescriptor Fields(params string[] fields) => Assign(f => f.And(fields)); + public FieldsDescriptor Fields(IEnumerable fields) => Assign(f => f.ListOfFields.AddRange(fields)); public FieldsDescriptor Field(Expression> field, double? boost = null) => Assign(f => f.And(field, boost)); + public FieldsDescriptor Field(string field, double? boost = null) => Assign(f => f.And(field, boost)); + public FieldsDescriptor Field(Field field) => Assign(f => f.And(field)); } } diff --git a/src/Nest/CommonAbstractions/Infer/Fields/FieldsJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/Fields/FieldsJsonConverter.cs index 144b044548b..630aa1fddeb 100644 --- a/src/Nest/CommonAbstractions/Infer/Fields/FieldsJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/Fields/FieldsJsonConverter.cs @@ -1,6 +1,4 @@ using System; -using System.Linq; -using Elasticsearch.Net; using Newtonsoft.Json; namespace Nest @@ -20,10 +18,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s if (fields != null) { var infer = serializer.GetConnectionSettings().Inferrer; - foreach (var f in fields.ListOfFields) - { - writer.WriteValue(infer.Field(f)); - } + foreach (var f in fields.ListOfFields) writer.WriteValue(infer.Field(f)); } writer.WriteEndArray(); } @@ -31,6 +26,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartArray) return null; + var fields = new Fields(); while (reader.TokenType != JsonToken.EndArray) { @@ -46,10 +42,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist reader.Read(); // "field"; var field = reader.ReadAsString(); fields.And(field); - while (reader.TokenType != JsonToken.EndObject) - { - reader.Read(); - } + while (reader.TokenType != JsonToken.EndObject) reader.Read(); reader.Read(); // "}"; break; } @@ -58,4 +51,3 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } } } - diff --git a/src/Nest/CommonAbstractions/Infer/Id/Id.cs b/src/Nest/CommonAbstractions/Infer/Id/Id.cs index afb2e259e11..092d7a68fee 100644 --- a/src/Nest/CommonAbstractions/Infer/Id/Id.cs +++ b/src/Nest/CommonAbstractions/Infer/Id/Id.cs @@ -10,47 +10,66 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class Id : IEquatable, IUrlParameter { - internal string StringValue { get; } - internal long? LongValue { get; } - internal string StringOrLongValue => this.StringValue ?? this.LongValue?.ToString(CultureInfo.InvariantCulture); - internal object Document { get; } - internal int Tag { get; } + public Id(string id) + { + Tag = 0; + StringValue = id; + } - public Id(string id) { Tag = 0; StringValue = id; } - public Id(long id) { Tag = 1; LongValue = id; } - public Id(object document) { Tag = 2; Document = document; } + public Id(long id) + { + Tag = 1; + LongValue = id; + } - public static implicit operator Id(string id) => id.IsNullOrEmpty() ? null : new Id(id); - public static implicit operator Id(long id) => new Id(id); - public static implicit operator Id(Guid id) => new Id(id.ToString("D")); + public Id(object document) + { + Tag = 2; + Document = document; + } - public static Id From(T document) where T : class => new Id(document); + internal object Document { get; } + internal long? LongValue { get; } + internal string StringOrLongValue => StringValue ?? LongValue?.ToString(CultureInfo.InvariantCulture); + internal string StringValue { get; } + internal int Tag { get; } private string DebugDisplay => StringOrLongValue ?? "Id from instance typeof: " + Document?.GetType().Name; - public override string ToString() => StringOrLongValue; - - string IUrlParameter.GetString(IConnectionConfigurationValues settings) - { - var nestSettings = (IConnectionSettingsValues)settings; - return nestSettings.Inferrer.Id(this.Document) ?? this.StringOrLongValue; - } + private static int TypeHashCode { get; } = typeof(Id).GetHashCode(); public bool Equals(Id other) { - if (this.Tag + other.Tag == 1) - return this.StringOrLongValue == other.StringOrLongValue; - else if (this.Tag != other.Tag) return false; - switch (this.Tag) + if (Tag + other.Tag == 1) + return StringOrLongValue == other.StringOrLongValue; + else if (Tag != other.Tag) return false; + + switch (Tag) { case 0: case 1: - return this.StringOrLongValue == other.StringOrLongValue; + return StringOrLongValue == other.StringOrLongValue; default: - return this.Document?.Equals(other.Document) ?? false; + return Document?.Equals(other.Document) ?? false; } } + string IUrlParameter.GetString(IConnectionConfigurationValues settings) + { + var nestSettings = (IConnectionSettingsValues)settings; + return nestSettings.Inferrer.Id(Document) ?? StringOrLongValue; + } + + public static implicit operator Id(string id) => id.IsNullOrEmpty() ? null : new Id(id); + + public static implicit operator Id(long id) => new Id(id); + + public static implicit operator Id(Guid id) => new Id(id.ToString("D")); + + public static Id From(T document) where T : class => new Id(document); + + public override string ToString() => StringOrLongValue; + public override bool Equals(object obj) { switch (obj) @@ -64,15 +83,14 @@ public override bool Equals(object obj) return Equals(new Id(obj)); } - private static int TypeHashCode { get; } = typeof(Id).GetHashCode(); public override int GetHashCode() { unchecked { var result = TypeHashCode; - result = (result * 397) ^ (this.StringValue?.GetHashCode() ?? 0); - result = (result * 397) ^ (this.LongValue?.GetHashCode() ?? 0); - result = (result * 397) ^ (this.Document?.GetHashCode() ?? 0); + result = (result * 397) ^ (StringValue?.GetHashCode() ?? 0); + result = (result * 397) ^ (LongValue?.GetHashCode() ?? 0); + result = (result * 397) ^ (Document?.GetHashCode() ?? 0); return result; } } diff --git a/src/Nest/CommonAbstractions/Infer/Id/IdExtensions.cs b/src/Nest/CommonAbstractions/Infer/Id/IdExtensions.cs index 70853750430..793ac155024 100644 --- a/src/Nest/CommonAbstractions/Infer/Id/IdExtensions.cs +++ b/src/Nest/CommonAbstractions/Infer/Id/IdExtensions.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Nest +namespace Nest { internal static class IdExtensions - { - internal static bool IsConditionless(this Id id) - { - return id == null || (id.StringOrLongValue == null && id.Document == null); - } + { + internal static bool IsConditionless(this Id id) => id == null || id.StringOrLongValue == null && id.Document == null; } } diff --git a/src/Nest/CommonAbstractions/Infer/Id/IdResolver.cs b/src/Nest/CommonAbstractions/Infer/Id/IdResolver.cs index 7bc0ccdca7d..0ba12d3cc66 100644 --- a/src/Nest/CommonAbstractions/Infer/Id/IdResolver.cs +++ b/src/Nest/CommonAbstractions/Infer/Id/IdResolver.cs @@ -6,22 +6,22 @@ namespace Nest { public class IdResolver { + private static readonly ConcurrentDictionary> IdDelegates = new ConcurrentDictionary>(); + + private static readonly MethodInfo MakeDelegateMethodInfo = + typeof(IdResolver).GetMethod(nameof(MakeDelegate), BindingFlags.Static | BindingFlags.NonPublic); + private readonly IConnectionSettingsValues _connectionSettings; private readonly ConcurrentDictionary> LocalIdDelegates = new ConcurrentDictionary>(); - private static readonly ConcurrentDictionary> IdDelegates = new ConcurrentDictionary>(); - private static readonly MethodInfo MakeDelegateMethodInfo = typeof(IdResolver).GetMethod(nameof(IdResolver.MakeDelegate), BindingFlags.Static | BindingFlags.NonPublic); - PropertyInfo GetPropertyCaseInsensitive(Type type, string fieldName) - => type.GetProperty(fieldName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); + public IdResolver(IConnectionSettingsValues connectionSettings) => _connectionSettings = connectionSettings; - public IdResolver(IConnectionSettingsValues connectionSettings) - { - _connectionSettings = connectionSettings; - } + private PropertyInfo GetPropertyCaseInsensitive(Type type, string fieldName) + => type.GetProperty(fieldName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); internal Func CreateIdSelector() where T : class { - Func idSelector = this.Resolve; + Func idSelector = Resolve; return idSelector; } @@ -37,7 +37,7 @@ public string Resolve(Type type, object @object) { if (type == null || @object == null) return null; - var preferLocal = this._connectionSettings.IdProperties.TryGetValue(type, out _); + var preferLocal = _connectionSettings.IdProperties.TryGetValue(type, out _); if (LocalIdDelegates.TryGetValue(type, out var cachedLookup)) return cachedLookup(@object); @@ -46,10 +46,8 @@ public string Resolve(Type type, object @object) return cachedLookup(@object); var idProperty = GetInferredId(type); - if (idProperty == null) - { - return null; - } + if (idProperty == null) return null; + var getMethod = idProperty.GetGetMethod(); var generic = MakeDelegateMethodInfo.MakeGenericMethod(type, getMethod.ReturnType); var func = (Func)generic.Invoke(null, new object[] { getMethod }); @@ -71,12 +69,12 @@ private PropertyInfo GetInferredId(Type type) // if the type specifies through ElasticAttribute what the id prop is // use that no matter what - this._connectionSettings.IdProperties.TryGetValue(type, out var propertyName); + _connectionSettings.IdProperties.TryGetValue(type, out var propertyName); if (!propertyName.IsNullOrEmpty()) return GetPropertyCaseInsensitive(type, propertyName); var esTypeAtt = ElasticsearchTypeAttribute.From(type); - propertyName = (esTypeAtt?.IdProperty.IsNullOrEmpty() ?? true) ? "Id" : esTypeAtt?.IdProperty; + propertyName = esTypeAtt?.IdProperty.IsNullOrEmpty() ?? true ? "Id" : esTypeAtt?.IdProperty; return GetPropertyCaseInsensitive(type, propertyName); } diff --git a/src/Nest/CommonAbstractions/Infer/IndexName/IndexName.cs b/src/Nest/CommonAbstractions/Infer/IndexName/IndexName.cs index 5a1f28f7590..82bf251e4a0 100644 --- a/src/Nest/CommonAbstractions/Infer/IndexName/IndexName.cs +++ b/src/Nest/CommonAbstractions/Infer/IndexName/IndexName.cs @@ -10,39 +10,56 @@ public class IndexName : IEquatable, IUrlParameter { private const char ClusterSeparator = ':'; - private static int TypeHashCode { get; } = typeof(IndexName).GetHashCode(); - - internal string DebugDisplay => Type == null ? Name : $"{nameof(IndexName)} for typeof: {Type?.Name}"; - - public string Cluster { get; } - public string Name { get; } - public Type Type { get; } - private IndexName(string index, string cluster = null) { - this.Name = index; - this.Cluster = cluster; + Name = index; + Cluster = cluster; } + private IndexName(Type type, string cluster = null) { - this.Type = type; - this.Cluster = cluster; + Type = type; + Cluster = cluster; } + private IndexName(string index, Type type, string cluster = null) { - this.Name = index; - this.Type = type; - this.Cluster = cluster; + Name = index; + Type = type; + Cluster = cluster; + } + + public string Cluster { get; } + public string Name { get; } + public Type Type { get; } + + internal string DebugDisplay => Type == null ? Name : $"{nameof(IndexName)} for typeof: {Type?.Name}"; + + private static int TypeHashCode { get; } = typeof(IndexName).GetHashCode(); + + bool IEquatable.Equals(IndexName other) => EqualsMarker(other); + + public string GetString(IConnectionConfigurationValues settings) + { + if (!(settings is IConnectionSettingsValues nestSettings)) + throw new Exception("Tried to pass index name on querystring but it could not be resolved because no nest settings are available"); + + return nestSettings.Inferrer.IndexName(this); } public static IndexName From() => typeof(T); + public static IndexName From(string clusterName) => From(typeof(T), clusterName); + private static IndexName From(Type t, string clusterName) => new IndexName(t, clusterName); + // TODO private? public static IndexName Rebuild(string index, Type t, string clusterName = null) => new IndexName(index, t, clusterName); public Indices And() => new Indices(new[] { this, typeof(T) }); + public Indices And(string clusterName) => new Indices(new[] { this, From(typeof(T), clusterName) }); + public Indices And(IndexName index) => new Indices(new[] { this, index }); private static IndexName Parse(string indexName) @@ -62,19 +79,18 @@ private static IndexName Parse(string indexName) } public static implicit operator IndexName(string indexName) => Parse(indexName); - public static implicit operator IndexName(Type type) => type == null ? null : new IndexName(type); - bool IEquatable.Equals(IndexName other) => EqualsMarker(other); + public static implicit operator IndexName(Type type) => type == null ? null : new IndexName(type); - public override bool Equals(object obj) => obj is string s ? this.EqualsString(s) : obj is IndexName i && EqualsMarker(i); + public override bool Equals(object obj) => obj is string s ? EqualsString(s) : obj is IndexName i && EqualsMarker(i); public override int GetHashCode() { unchecked { var result = TypeHashCode; - result = (result * 397) ^ (this.Name?.GetHashCode() ?? this.Type?.GetHashCode() ?? 0); - result = (result * 397) ^ (this.Cluster?.GetHashCode() ?? 0); + result = (result * 397) ^ (Name?.GetHashCode() ?? Type?.GetHashCode() ?? 0); + result = (result * 397) ^ (Cluster?.GetHashCode() ?? 0); return result; } } @@ -85,33 +101,27 @@ public override int GetHashCode() public override string ToString() { - if (!this.Name.IsNullOrEmpty()) - return PrefixClusterName(this.Name); - return this.Type != null ? PrefixClusterName(this.Type.Name) : string.Empty; + if (!Name.IsNullOrEmpty()) + return PrefixClusterName(Name); + + return Type != null ? PrefixClusterName(Type.Name) : string.Empty; } + private string PrefixClusterName(string name) => PrefixClusterName(this, name); + private static string PrefixClusterName(IndexName i, string name) => i.Cluster.IsNullOrEmpty() ? name : $"{i.Cluster}:{name}"; - private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == PrefixClusterName(this.Name); + private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == PrefixClusterName(Name); private bool EqualsMarker(IndexName other) { if (other == null) return false; - if (!this.Name.IsNullOrEmpty() && !other.Name.IsNullOrEmpty()) - return EqualsString(PrefixClusterName(other,other.Name)); - - if ((!this.Cluster.IsNullOrEmpty() || !other.Cluster.IsNullOrEmpty()) && this.Cluster != other.Cluster) return false; - - return this.Type != null && other?.Type != null && this.Type == other.Type; - } + if (!Name.IsNullOrEmpty() && !other.Name.IsNullOrEmpty()) + return EqualsString(PrefixClusterName(other, other.Name)); - public string GetString(IConnectionConfigurationValues settings) - { - if (!(settings is IConnectionSettingsValues nestSettings)) - throw new Exception("Tried to pass index name on querystring but it could not be resolved because no nest settings are available"); + if ((!Cluster.IsNullOrEmpty() || !other.Cluster.IsNullOrEmpty()) && Cluster != other.Cluster) return false; - return nestSettings.Inferrer.IndexName(this); + return Type != null && other?.Type != null && Type == other.Type; } - } } diff --git a/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameExtensions.cs b/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameExtensions.cs index c962b49bc36..97f0f7a4f12 100644 --- a/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameExtensions.cs +++ b/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameExtensions.cs @@ -6,11 +6,13 @@ public static string Resolve(this IndexName marker, IConnectionSettingsValues co { if (marker == null) return null; + connectionSettings.ThrowIfNull(nameof(connectionSettings)); if (marker.Type == null) return marker.Name; + return new IndexNameResolver(connectionSettings).Resolve(marker.Type); } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameJsonConverter.cs index f1ff0f64b9c..653d882b20f 100644 --- a/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameJsonConverter.cs @@ -23,9 +23,9 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.String) return null; + var typeName = reader.Value.ToString(); return (IndexName)typeName; } - } } diff --git a/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameResolver.cs b/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameResolver.cs index 4e02917f73a..0b25e09f064 100644 --- a/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameResolver.cs +++ b/src/Nest/CommonAbstractions/Infer/IndexName/IndexNameResolver.cs @@ -1,5 +1,4 @@ -using Elasticsearch.Net; -using System; +using System; namespace Nest { @@ -10,22 +9,24 @@ public class IndexNameResolver public IndexNameResolver(IConnectionSettingsValues connectionSettings) { connectionSettings.ThrowIfNull(nameof(connectionSettings)); - this._connectionSettings = connectionSettings; + _connectionSettings = connectionSettings; } - public string Resolve() where T : class => this.Resolve(typeof(T)); + + public string Resolve() where T : class => Resolve(typeof(T)); public string Resolve(IndexName i) { if (string.IsNullOrEmpty(i?.Name)) - return PrefixClusterName(i,this.Resolve(i?.Type)); + return PrefixClusterName(i, Resolve(i?.Type)); + ValidateIndexName(i.Name); return PrefixClusterName(i, i.Name); } public string Resolve(Type type) { - var indexName = this._connectionSettings.DefaultIndex; - var defaultIndices = this._connectionSettings.DefaultIndices; + var indexName = _connectionSettings.DefaultIndex; + var defaultIndices = _connectionSettings.DefaultIndices; if (defaultIndices != null && type != null) { if (defaultIndices.TryGetValue(type, out var value) && !string.IsNullOrEmpty(value)) @@ -34,6 +35,7 @@ public string Resolve(Type type) ValidateIndexName(indexName); return indexName; } + private static string PrefixClusterName(IndexName i, string name) => i.Cluster.IsNullOrEmpty() ? name : $"{i.Cluster}:{name}"; private static void ValidateIndexName(string indexName) diff --git a/src/Nest/CommonAbstractions/Infer/Indices/Indices.cs b/src/Nest/CommonAbstractions/Infer/Indices/Indices.cs index f893aaf4aab..73387397a31 100644 --- a/src/Nest/CommonAbstractions/Infer/Indices/Indices.cs +++ b/src/Nest/CommonAbstractions/Infer/Indices/Indices.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Linq; using Elasticsearch.Net; -using Newtonsoft.Json; namespace Nest { @@ -11,76 +10,64 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class Indices : Union, IUrlParameter { - public class AllIndicesMarker { internal AllIndicesMarker() { } } + internal Indices(AllIndicesMarker all) : base(all) { } + + internal Indices(ManyIndices indices) : base(indices) { } + + internal Indices(IEnumerable indices) : base(new ManyIndices(indices)) { } + public static Indices All { get; } = new Indices(new AllIndicesMarker()); public static Indices AllIndices { get; } = new Indices(new AllIndicesMarker()); - public class ManyIndices - { - private readonly List _indices = new List(); - public IReadOnlyList Indices => _indices; - internal ManyIndices(IEnumerable indices) - { - indices.ThrowIfEmpty(nameof(indices)); - this._indices.AddRange(indices); - } - internal ManyIndices(IEnumerable indices) - { - indices.ThrowIfEmpty(nameof(indices)); - this._indices.AddRange(indices.Select(s=>(IndexName)s)); - } - public ManyIndices And() + private string DebugDisplay => Match( + all => "_all", + types => $"Count: {types.Indices.Count} [" + string.Join(",", types.Indices.Select((t, i) => $"({i + 1}: {t.DebugDisplay})")) + "]" + ); + + string IUrlParameter.GetString(IConnectionConfigurationValues settings) => Match( + all => "_all", + many => { - this._indices.Add(typeof(T)); - return this; - } - } + if (!(settings is IConnectionSettingsValues nestSettings)) + throw new Exception( + "Tried to pass index names on querysting but it could not be resolved because no nest settings are available"); - internal Indices(Indices.AllIndicesMarker all) : base(all) { } - internal Indices(Indices.ManyIndices indices) : base(indices) { } - internal Indices(IEnumerable indices) : base(new ManyIndices(indices)) { } + var infer = nestSettings.Inferrer; + var indices = many.Indices.Select(i => infer.IndexName(i)).Distinct(); + return string.Join(",", indices); + } + ); public static IndexName Index(IndexName index) => index; + public static IndexName Index() => typeof(T); + public static ManyIndices Index(IEnumerable indices) => new ManyIndices(indices); + public static ManyIndices Index(params IndexName[] indices) => new ManyIndices(indices); public static ManyIndices Index(IEnumerable indices) => new ManyIndices(indices); + public static ManyIndices Index(params string[] indices) => new ManyIndices(indices); public static Indices Parse(string indicesString) { if (indicesString.IsNullOrEmptyCommaSeparatedList(out var indices)) return null; + return indices.Contains("_all") ? All : Index(indices.Select(i => (IndexName)i)); } public static implicit operator Indices(string indicesString) => Parse(indicesString); + public static implicit operator Indices(ManyIndices many) => many == null ? null : new Indices(many); + public static implicit operator Indices(string[] many) => many.IsEmpty() ? null : new ManyIndices(many); - public static implicit operator Indices(IndexName[] many) => many.IsEmpty()? null : new ManyIndices(many); - public static implicit operator Indices(IndexName index) => index == null ? null : new ManyIndices(new[] { index }); - public static implicit operator Indices(Type type) => type == null ? null : new ManyIndices(new IndexName[] { type }); - private string DebugDisplay => this.Match( - all => "_all", - types => $"Count: {types.Indices.Count} [" + string.Join(",", types.Indices.Select((t, i) => $"({i+1}: {t.DebugDisplay})")) + "]" - ); + public static implicit operator Indices(IndexName[] many) => many.IsEmpty() ? null : new ManyIndices(many); - string IUrlParameter.GetString(IConnectionConfigurationValues settings) - { - return this.Match( - all => "_all", - many => - { - if (!(settings is IConnectionSettingsValues nestSettings)) - throw new Exception("Tried to pass index names on querysting but it could not be resolved because no nest settings are available"); - - var infer = nestSettings.Inferrer; - var indices = many.Indices.Select(i => infer.IndexName(i)).Distinct(); - return string.Join(",", indices); - } - ); - } + public static implicit operator Indices(IndexName index) => index == null ? null : new ManyIndices(new[] { index }); + + public static implicit operator Indices(Type type) => type == null ? null : new ManyIndices(new IndexName[] { type }); public static bool operator ==(Indices left, Indices right) => Equals(left, right); @@ -89,7 +76,8 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings) public override bool Equals(object obj) { if (!(obj is Indices other)) return false; - return this.Match( + + return Match( all => other.Match(a => true, m => false), many => other.Match( a => false, @@ -102,15 +90,43 @@ private static bool EqualsAllIndices(IReadOnlyList thisIndices, IRead { if (thisIndices == null && otherIndices == null) return true; if (thisIndices == null || otherIndices == null) return false; + return thisIndices.Count == otherIndices.Count && !thisIndices.Except(otherIndices).Any(); } - public override int GetHashCode() + public override int GetHashCode() => Match( + all => "_all".GetHashCode(), + many => string.Concat(many.Indices.OrderBy(i => i.ToString())).GetHashCode() + ); + + public class AllIndicesMarker { - return this.Match( - all => "_all".GetHashCode(), - many => string.Concat(many.Indices.OrderBy(i => i.ToString())).GetHashCode() - ); + internal AllIndicesMarker() { } + } + + public class ManyIndices + { + private readonly List _indices = new List(); + + internal ManyIndices(IEnumerable indices) + { + indices.ThrowIfEmpty(nameof(indices)); + _indices.AddRange(indices); + } + + internal ManyIndices(IEnumerable indices) + { + indices.ThrowIfEmpty(nameof(indices)); + _indices.AddRange(indices.Select(s => (IndexName)s)); + } + + public IReadOnlyList Indices => _indices; + + public ManyIndices And() + { + _indices.Add(typeof(T)); + return this; + } } } } diff --git a/src/Nest/CommonAbstractions/Infer/Indices/IndicesExtensions.cs b/src/Nest/CommonAbstractions/Infer/Indices/IndicesExtensions.cs index 6c042edd153..d8b1a6d9154 100644 --- a/src/Nest/CommonAbstractions/Infer/Indices/IndicesExtensions.cs +++ b/src/Nest/CommonAbstractions/Infer/Indices/IndicesExtensions.cs @@ -5,6 +5,7 @@ public static class IndicesExtensions public static string Resolve(this Indices marker, IConnectionSettingsValues connectionSettings) { if (marker == null) return null; + connectionSettings.ThrowIfNull(nameof(connectionSettings)); return connectionSettings.Inferrer.Resolve(marker); } diff --git a/src/Nest/CommonAbstractions/Infer/Indices/IndicesJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/Indices/IndicesJsonConverter.cs index 0d78167febb..1199c1d4036 100644 --- a/src/Nest/CommonAbstractions/Infer/Indices/IndicesJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/Indices/IndicesJsonConverter.cs @@ -38,6 +38,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartArray) return null; + var indices = new List(); while (reader.TokenType != JsonToken.EndArray) { @@ -47,6 +48,5 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } return new Indices(indices); } - } } diff --git a/src/Nest/CommonAbstractions/Infer/Indices/IndicesMultiSyntaxJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/Indices/IndicesMultiSyntaxJsonConverter.cs index 5ed9167d160..3df5e27c75d 100644 --- a/src/Nest/CommonAbstractions/Infer/Indices/IndicesMultiSyntaxJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/Indices/IndicesMultiSyntaxJsonConverter.cs @@ -4,7 +4,6 @@ namespace Nest { - internal class IndicesMultiSyntaxJsonConverter : JsonConverter { public override bool CanConvert(Type objectType) => typeof(Indices) == objectType; @@ -18,7 +17,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s return; } marker.Match( - all=> writer.WriteValue("_all"), + all => writer.WriteValue("_all"), many => writer.WriteValue(((IUrlParameter)marker).GetString(serializer.GetConnectionSettings())) ); } @@ -27,11 +26,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { if (reader.TokenType == JsonToken.String) { - string indices = reader.Value.ToString(); + var indices = reader.Value.ToString(); return (Indices)indices; } return null; } - } } diff --git a/src/Nest/CommonAbstractions/Infer/Inferrer.cs b/src/Nest/CommonAbstractions/Infer/Inferrer.cs index 8aa5878518c..a7cbe8cc99d 100644 --- a/src/Nest/CommonAbstractions/Infer/Inferrer.cs +++ b/src/Nest/CommonAbstractions/Infer/Inferrer.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Globalization; -using System.Linq; using Elasticsearch.Net; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -12,57 +10,65 @@ namespace Nest public class Inferrer { private readonly IConnectionSettingsValues _connectionSettings; - private IdResolver IdResolver { get; } - private IndexNameResolver IndexNameResolver { get; } - private TypeNameResolver TypeNameResolver { get; } - private RelationNameResolver RelationNameResolver { get; } - private FieldResolver FieldResolver { get; } - private RoutingResolver RoutingResolver { get; } - - internal ConcurrentDictionary Contracts { get; } - internal ConcurrentDictionary>>> CreateMultiHitDelegates { get; } - internal ConcurrentDictionary>> CreateSearchResponseDelegates { get; } public Inferrer(IConnectionSettingsValues connectionSettings) { connectionSettings.ThrowIfNull(nameof(connectionSettings)); - this._connectionSettings = connectionSettings; - this.IdResolver = new IdResolver(connectionSettings); - this.IndexNameResolver = new IndexNameResolver(connectionSettings); - this.TypeNameResolver = new TypeNameResolver(connectionSettings); - this.RelationNameResolver = new RelationNameResolver(connectionSettings); - this.FieldResolver = new FieldResolver(connectionSettings); - this.RoutingResolver = new RoutingResolver(connectionSettings, this.IdResolver); - - this.Contracts = new ConcurrentDictionary(); - this.CreateMultiHitDelegates = new ConcurrentDictionary>>>(); - this.CreateSearchResponseDelegates = new ConcurrentDictionary>>(); + _connectionSettings = connectionSettings; + IdResolver = new IdResolver(connectionSettings); + IndexNameResolver = new IndexNameResolver(connectionSettings); + TypeNameResolver = new TypeNameResolver(connectionSettings); + RelationNameResolver = new RelationNameResolver(connectionSettings); + FieldResolver = new FieldResolver(connectionSettings); + RoutingResolver = new RoutingResolver(connectionSettings, IdResolver); + + Contracts = new ConcurrentDictionary(); + CreateMultiHitDelegates = + new ConcurrentDictionary>>>(); + CreateSearchResponseDelegates = + new ConcurrentDictionary> + >(); } - public string Resolve(IUrlParameter urlParameter) => urlParameter.GetString(this._connectionSettings); + internal ConcurrentDictionary Contracts { get; } + + internal ConcurrentDictionary>>> + CreateMultiHitDelegates { get; } + + internal ConcurrentDictionary>> + CreateSearchResponseDelegates { get; } + + private FieldResolver FieldResolver { get; } + private IdResolver IdResolver { get; } + private IndexNameResolver IndexNameResolver { get; } + private RelationNameResolver RelationNameResolver { get; } + private RoutingResolver RoutingResolver { get; } + private TypeNameResolver TypeNameResolver { get; } + + public string Resolve(IUrlParameter urlParameter) => urlParameter.GetString(_connectionSettings); + + public string Field(Field field) => FieldResolver.Resolve(field); - public string Field(Field field) => this.FieldResolver.Resolve(field); + public string PropertyName(PropertyName property) => FieldResolver.Resolve(property); - public string PropertyName(PropertyName property) => this.FieldResolver.Resolve(property); + public string IndexName() where T : class => IndexNameResolver.Resolve(); - public string IndexName() where T : class => this.IndexNameResolver.Resolve(); + public string IndexName(IndexName index) => IndexNameResolver.Resolve(index); - public string IndexName(IndexName index) => this.IndexNameResolver.Resolve(index); + public string Id(T instance) where T : class => IdResolver.Resolve(instance); - public string Id(T instance) where T : class => this.IdResolver.Resolve(instance); + public string Id(Type type, object instance) => IdResolver.Resolve(type, instance); - public string Id(Type type, object instance) => this.IdResolver.Resolve(type, instance); + public string TypeName() where T : class => TypeNameResolver.Resolve(); - public string TypeName() where T : class => this.TypeNameResolver.Resolve(); + public string TypeName(TypeName type) => TypeNameResolver.Resolve(type); - public string TypeName(TypeName type) => this.TypeNameResolver.Resolve(type); + public string RelationName() where T : class => RelationNameResolver.Resolve(); - public string RelationName() where T : class => this.RelationNameResolver.Resolve(); + public string RelationName(RelationName type) => RelationNameResolver.Resolve(type); - public string RelationName(RelationName type) => this.RelationNameResolver.Resolve(type); + public string Routing(T document) => RoutingResolver.Resolve(document); - public string Routing(T document) => this.RoutingResolver.Resolve(document); - - public string Routing(Type type, object instance) => this.RoutingResolver.Resolve(type, instance); + public string Routing(Type type, object instance) => RoutingResolver.Resolve(type, instance); } } diff --git a/src/Nest/CommonAbstractions/Infer/JoinFieldRouting/Routing.cs b/src/Nest/CommonAbstractions/Infer/JoinFieldRouting/Routing.cs index b3104b698e1..e5e3eaa35d5 100644 --- a/src/Nest/CommonAbstractions/Infer/JoinFieldRouting/Routing.cs +++ b/src/Nest/CommonAbstractions/Infer/JoinFieldRouting/Routing.cs @@ -11,14 +11,7 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class Routing : IEquatable, IUrlParameter { - internal string StringValue { get; } - internal long? LongValue { get; } - internal string StringOrLongValue => this.StringValue ?? this.LongValue?.ToString(CultureInfo.InvariantCulture); - - internal object Document { get; } - internal Func DocumentGetter { get; } - - internal int Tag { get; } + private static readonly char[] Separator = { ',' }; internal Routing(Func documentGetter) { @@ -44,15 +37,38 @@ public Routing(object document) Document = document; } - public static implicit operator Routing(string routing) => routing.IsNullOrEmptyCommaSeparatedList(out _) ? null : new Routing(routing); - public static implicit operator Routing(string[] routing) => routing.IsEmpty() ? null : new Routing(string.Join(",", routing)); - public static implicit operator Routing(long routing) => new Routing(routing); - public static implicit operator Routing(Guid routing) => new Routing(routing.ToString("D")); + internal object Document { get; } + internal Func DocumentGetter { get; } + internal long? LongValue { get; } + internal string StringOrLongValue => StringValue ?? LongValue?.ToString(CultureInfo.InvariantCulture); + internal string StringValue { get; } - /// Use the inferred routing from - public static Routing From(T document) where T : class => new Routing(document); + internal int Tag { get; } + + private string DebugDisplay => StringOrLongValue ?? "Routing from instance typeof: " + Document?.GetType().Name; + + private static int TypeHashCode { get; } = typeof(Routing).GetHashCode(); - private string DebugDisplay => this.StringOrLongValue ?? "Routing from instance typeof: " + Document?.GetType().Name; + public bool Equals(Routing other) + { + if (Tag == other.Tag) + { + switch (Tag) + { + case 0: + var t = DocumentGetter(); + var o = other.DocumentGetter(); + return t?.Equals(o) ?? false; + case 4: return Document?.Equals(other.Document) ?? false; + default: + return StringEquals(StringOrLongValue, other.StringOrLongValue); + } + } + else if (Tag + other.Tag == 3) + return StringEquals(StringOrLongValue, other.StringOrLongValue); + else + return false; + } string IUrlParameter.GetString(IConnectionConfigurationValues settings) { @@ -60,59 +76,48 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings) return GetString(nestSettings); } + public static implicit operator Routing(string routing) => routing.IsNullOrEmptyCommaSeparatedList(out _) ? null : new Routing(routing); + + public static implicit operator Routing(string[] routing) => routing.IsEmpty() ? null : new Routing(string.Join(",", routing)); + + public static implicit operator Routing(long routing) => new Routing(routing); + + public static implicit operator Routing(Guid routing) => new Routing(routing.ToString("D")); + + /// Use the inferred routing from + public static Routing From(T document) where T : class => new Routing(document); + private string GetString(IConnectionSettingsValues nestSettings) { string value = null; - if (this.DocumentGetter != null) + if (DocumentGetter != null) { - var doc = this.DocumentGetter(); + var doc = DocumentGetter(); value = nestSettings.Inferrer.Routing(doc); } - else if (this.Document != null) - value = nestSettings.Inferrer.Routing(this.Document); + else if (Document != null) + value = nestSettings.Inferrer.Routing(Document); - return value ?? this.StringOrLongValue; + return value ?? StringOrLongValue; } public static bool operator ==(Routing left, Routing right) => Equals(left, right); public static bool operator !=(Routing left, Routing right) => !Equals(left, right); - public bool Equals(Routing other) - { - if (this.Tag == other.Tag) - { - switch (this.Tag) - { - case 0: - var t = this.DocumentGetter(); - var o = other.DocumentGetter(); - return t?.Equals(o) ?? false; - case 4: return this.Document?.Equals(other.Document) ?? false; - default: - return StringEquals(this.StringOrLongValue, other.StringOrLongValue); - } - } - else if (this.Tag + other.Tag == 3) - return StringEquals(this.StringOrLongValue, other.StringOrLongValue); - else - return false; - } - - private static readonly char[] Separator = {','}; - private static bool StringEquals(string left, string right) { if (left == null && right == null) return true; else if (left == null || right == null) return false; + if (!left.Contains(",") || !right.Contains(",")) return left == right; - var l1 = left.Split(Separator, StringSplitOptions.RemoveEmptyEntries).Select(v=>v.Trim()).ToList(); - var l2 = right.Split(Separator, StringSplitOptions.RemoveEmptyEntries).Select(v=>v.Trim()).ToList(); + var l1 = left.Split(Separator, StringSplitOptions.RemoveEmptyEntries).Select(v => v.Trim()).ToList(); + var l2 = right.Split(Separator, StringSplitOptions.RemoveEmptyEntries).Select(v => v.Trim()).ToList(); if (l1.Count != l2.Count) return false; - return l1.Count == l2.Count && !l1.Except(l2).Any(); + return l1.Count == l2.Count && !l1.Except(l2).Any(); } public override bool Equals(object obj) @@ -129,16 +134,15 @@ public override bool Equals(object obj) return Equals(new Routing(obj)); } - private static int TypeHashCode { get; } = typeof(Routing).GetHashCode(); public override int GetHashCode() { unchecked { var result = TypeHashCode; - result = (result * 397) ^ (this.StringValue?.GetHashCode() ?? 0); - result = (result * 397) ^ (this.LongValue?.GetHashCode() ?? 0); - result = (result * 397) ^ (this.DocumentGetter?.GetHashCode() ?? 0); - result = (result * 397) ^ (this.Document?.GetHashCode() ?? 0); + result = (result * 397) ^ (StringValue?.GetHashCode() ?? 0); + result = (result * 397) ^ (LongValue?.GetHashCode() ?? 0); + result = (result * 397) ^ (DocumentGetter?.GetHashCode() ?? 0); + result = (result * 397) ^ (Document?.GetHashCode() ?? 0); return result; } } diff --git a/src/Nest/CommonAbstractions/Infer/JoinFieldRouting/RoutingResolver.cs b/src/Nest/CommonAbstractions/Infer/JoinFieldRouting/RoutingResolver.cs index 1008f2816b3..84cdc3b9f57 100644 --- a/src/Nest/CommonAbstractions/Infer/JoinFieldRouting/RoutingResolver.cs +++ b/src/Nest/CommonAbstractions/Infer/JoinFieldRouting/RoutingResolver.cs @@ -7,21 +7,26 @@ namespace Nest { public class RoutingResolver { - private static readonly ConcurrentDictionary> PropertyGetDelegates = new ConcurrentDictionary>(); - private readonly ConcurrentDictionary> LocalRouteDelegates = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> PropertyGetDelegates = + new ConcurrentDictionary>(); + private static readonly MethodInfo MakeDelegateMethodInfo = typeof(RoutingResolver).GetMethod(nameof(MakeDelegate), BindingFlags.Static | BindingFlags.NonPublic); + private readonly IConnectionSettingsValues _connectionSettings; private readonly IdResolver _idResolver; + private readonly ConcurrentDictionary> + LocalRouteDelegates = new ConcurrentDictionary>(); + public RoutingResolver(IConnectionSettingsValues connectionSettings, IdResolver idResolver) { _connectionSettings = connectionSettings; _idResolver = idResolver; } - PropertyInfo GetPropertyCaseInsensitive(Type type, string fieldName) => + private PropertyInfo GetPropertyCaseInsensitive(Type type, string fieldName) => type.GetProperty(fieldName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); internal static Func MakeDelegate(MethodInfo @get) @@ -35,6 +40,7 @@ internal static Func MakeDelegate(MethodInfo @get) public string Resolve(Type type, object @object) { if (TryConnectionSettingsRoute(type, @object, out var route)) return route; + var joinField = GetJoinFieldFromObject(type, @object); return joinField?.Match(p => _idResolver.Resolve(@object), c => ResolveId(c.Parent, _connectionSettings)); } @@ -42,7 +48,7 @@ public string Resolve(Type type, object @object) private bool TryConnectionSettingsRoute(Type type, object @object, out string route) { route = null; - if (!this._connectionSettings.RouteProperties.TryGetValue(type, out var propertyName)) + if (!_connectionSettings.RouteProperties.TryGetValue(type, out var propertyName)) return false; if (LocalRouteDelegates.TryGetValue(type, out var cachedLookup)) @@ -92,7 +98,7 @@ private static Func CreateGetterFunc(Type type, PropertyInfo joi { var getMethod = joinProperty.GetGetMethod(); var generic = MakeDelegateMethodInfo.MakeGenericMethod(type, getMethod.ReturnType); - var func = (Func) generic.Invoke(null, new object[] {getMethod}); + var func = (Func)generic.Invoke(null, new object[] { getMethod }); return func; } @@ -101,8 +107,8 @@ private static PropertyInfo GetJoinFieldProperty(Type type) var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); try { - var joinField = properties.SingleOrDefault(p => p.PropertyType == typeof(JoinField)); - return joinField; + var joinField = properties.SingleOrDefault(p => p.PropertyType == typeof(JoinField)); + return joinField; } catch (InvalidOperationException e) { diff --git a/src/Nest/CommonAbstractions/Infer/Metrics/IndexMetrics.cs b/src/Nest/CommonAbstractions/Infer/Metrics/IndexMetrics.cs index 240b15e6ece..614f5b1b00b 100644 --- a/src/Nest/CommonAbstractions/Infer/Metrics/IndexMetrics.cs +++ b/src/Nest/CommonAbstractions/Infer/Metrics/IndexMetrics.cs @@ -6,19 +6,22 @@ namespace Nest public class IndexMetrics : IEquatable, IUrlParameter { private readonly NodesStatsIndexMetric _enumValue; + + internal IndexMetrics(NodesStatsIndexMetric metric) => _enumValue = metric; + internal Enum Value => _enumValue; - public string GetString(IConnectionConfigurationValues settings) => this._enumValue.GetStringValue(); - internal IndexMetrics(NodesStatsIndexMetric metric) { _enumValue = metric; } + public bool Equals(IndexMetrics other) => Value.Equals(other.Value); + + public string GetString(IConnectionConfigurationValues settings) => _enumValue.GetStringValue(); public static implicit operator IndexMetrics(NodesStatsIndexMetric metric) => new IndexMetrics(metric); - public bool Equals(Enum other) => this.Value.Equals(other); - public bool Equals(IndexMetrics other) => this.Value.Equals(other.Value); + public bool Equals(Enum other) => Value.Equals(other); public override bool Equals(object obj) => obj is Enum e ? Equals(e) : obj is IndexMetrics m && Equals(m.Value); - public override int GetHashCode() => (_enumValue.GetHashCode()); + public override int GetHashCode() => _enumValue.GetHashCode(); public static bool operator ==(IndexMetrics left, IndexMetrics right) => Equals(left, right); diff --git a/src/Nest/CommonAbstractions/Infer/Metrics/Metrics.cs b/src/Nest/CommonAbstractions/Infer/Metrics/Metrics.cs index 458f720e23f..4e72fd8828e 100644 --- a/src/Nest/CommonAbstractions/Infer/Metrics/Metrics.cs +++ b/src/Nest/CommonAbstractions/Infer/Metrics/Metrics.cs @@ -5,30 +5,41 @@ namespace Nest { public class Metrics : IEquatable, IUrlParameter { - private readonly Enum _enumValue; - internal Enum Value => _enumValue; + internal Metrics(IndicesStatsMetric metric) => Value = metric; - public string GetString(IConnectionConfigurationValues settings) => this._enumValue.GetStringValue(); - internal Metrics(IndicesStatsMetric metric) { _enumValue = metric; } - internal Metrics(NodesStatsMetric metric){ _enumValue = metric; } - internal Metrics(NodesInfoMetric metric){ _enumValue = metric; } - internal Metrics(ClusterStateMetric metric){ _enumValue = metric; } - internal Metrics(WatcherStatsMetric metric){ _enumValue = metric; } - internal Metrics(NodesUsageMetric metric){ _enumValue = metric; } + internal Metrics(NodesStatsMetric metric) => Value = metric; + + internal Metrics(NodesInfoMetric metric) => Value = metric; + + internal Metrics(ClusterStateMetric metric) => Value = metric; + + internal Metrics(WatcherStatsMetric metric) => Value = metric; + + internal Metrics(NodesUsageMetric metric) => Value = metric; + + internal Enum Value { get; } + + public bool Equals(Metrics other) => Value.Equals(other.Value); + + public string GetString(IConnectionConfigurationValues settings) => Value.GetStringValue(); public static implicit operator Metrics(IndicesStatsMetric metric) => new Metrics(metric); + public static implicit operator Metrics(NodesStatsMetric metric) => new Metrics(metric); + public static implicit operator Metrics(NodesInfoMetric metric) => new Metrics(metric); + public static implicit operator Metrics(ClusterStateMetric metric) => new Metrics(metric); + public static implicit operator Metrics(WatcherStatsMetric metric) => new Metrics(metric); + public static implicit operator Metrics(NodesUsageMetric metric) => new Metrics(metric); - public bool Equals(Enum other) => this.Value.Equals(other); - public bool Equals(Metrics other) => this.Value.Equals(other.Value); + public bool Equals(Enum other) => Value.Equals(other); public override bool Equals(object obj) => obj is Enum e ? Equals(e) : obj is Metrics m && Equals(m.Value); - public override int GetHashCode() => (_enumValue != null ? _enumValue.GetHashCode() : 0); + public override int GetHashCode() => Value != null ? Value.GetHashCode() : 0; public static bool operator ==(Metrics left, Metrics right) => Equals(left, right); diff --git a/src/Nest/CommonAbstractions/Infer/Name/Name.cs b/src/Nest/CommonAbstractions/Infer/Name/Name.cs index 5d9bd54915d..40c95a62171 100644 --- a/src/Nest/CommonAbstractions/Infer/Name/Name.cs +++ b/src/Nest/CommonAbstractions/Infer/Name/Name.cs @@ -7,13 +7,17 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class Name : IEquatable, IUrlParameter { - private readonly string _name; - internal string Value => _name; - private string DebugDisplay => _name; + public Name(string name) => Value = name?.Trim(); - public Name(string name) => this._name = name?.Trim(); + internal string Value { get; } - string IUrlParameter.GetString(IConnectionConfigurationValues settings) => _name; + private string DebugDisplay => Value; + + private static int TypeHashCode { get; } = typeof(Name).GetHashCode(); + + public bool Equals(Name other) => EqualsString(other?.Value); + + string IUrlParameter.GetString(IConnectionConfigurationValues settings) => Value; public static implicit operator Name(string name) => name.IsNullOrEmpty() ? null : new Name(name); @@ -21,20 +25,17 @@ public class Name : IEquatable, IUrlParameter public static bool operator !=(Name left, Name right) => !Equals(left, right); - public bool Equals(Name other) => EqualsString(other?.Value); - public override bool Equals(object obj) => - obj is string s ? this.EqualsString(s) : (obj is Name i) && this.EqualsString(i.Value); + obj is string s ? EqualsString(s) : obj is Name i && EqualsString(i.Value); - private bool EqualsString(string other) => !other.IsNullOrEmpty() && other.Trim() == this.Value; + private bool EqualsString(string other) => !other.IsNullOrEmpty() && other.Trim() == Value; - private static int TypeHashCode { get; } = typeof(Name).GetHashCode(); public override int GetHashCode() { unchecked { var result = TypeHashCode; - result = (result * 397) ^ (this.Value?.GetHashCode() ?? 0); + result = (result * 397) ^ (Value?.GetHashCode() ?? 0); return result; } } diff --git a/src/Nest/CommonAbstractions/Infer/Name/Names.cs b/src/Nest/CommonAbstractions/Infer/Name/Names.cs index b8b57032a8f..293d74d0f32 100644 --- a/src/Nest/CommonAbstractions/Infer/Name/Names.cs +++ b/src/Nest/CommonAbstractions/Infer/Name/Names.cs @@ -9,24 +9,25 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class Names : IEquatable, IUrlParameter { - private readonly IList _names; - internal IList Value => _names; - - public Names(IEnumerable names) : this(names?.Select(n=>(Name)n).ToList()) { } + public Names(IEnumerable names) : this(names?.Select(n => (Name)n).ToList()) { } public Names(IEnumerable names) { - this._names = names?.ToList(); - if (!this._names.HasAny()) + Value = names?.ToList(); + if (!Value.HasAny()) throw new ArgumentException($"can not create {nameof(Names)} on an empty enumerable of ", nameof(names)); } - public static Names Parse(string names) => names.IsNullOrEmptyCommaSeparatedList(out var list) ? null : new Names(list); + internal IList Value { get; } + + private string DebugDisplay => ((IUrlParameter)this).GetString(null); + + public bool Equals(Names other) => EqualsAllIds(Value, other.Value); string IUrlParameter.GetString(IConnectionConfigurationValues settings) => - string.Join(",", this._names.Cast().Select(n => n.GetString(settings))); + string.Join(",", Value.Cast().Select(n => n.GetString(settings))); - private string DebugDisplay => ((IUrlParameter)this).GetString(null); + public static Names Parse(string names) => names.IsNullOrEmptyCommaSeparatedList(out var list) ? null : new Names(list); public static implicit operator Names(Name name) => name == null ? null : new Names(new[] { name }); @@ -38,18 +39,17 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings) => public static bool operator !=(Names left, Names right) => !Equals(left, right); - public bool Equals(Names other) => EqualsAllIds(this.Value, other.Value); - private static bool EqualsAllIds(ICollection thisIds, ICollection otherIds) { if (thisIds == null && otherIds == null) return true; if (thisIds == null || otherIds == null) return false; if (thisIds.Count != otherIds.Count) return false; + return thisIds.Count == otherIds.Count && !thisIds.Except(otherIds).Any(); } - public override bool Equals(object obj) => obj is string s ? this.Equals(Parse(s)) : (obj is Names i) && this.Equals(i); + public override bool Equals(object obj) => obj is string s ? Equals(Parse(s)) : obj is Names i && Equals(i); - public override int GetHashCode() => this._names.GetHashCode(); + public override int GetHashCode() => Value.GetHashCode(); } } diff --git a/src/Nest/CommonAbstractions/Infer/NodeId/NodeIds.cs b/src/Nest/CommonAbstractions/Infer/NodeId/NodeIds.cs index 62649c870a7..86e0e217ebb 100644 --- a/src/Nest/CommonAbstractions/Infer/NodeId/NodeIds.cs +++ b/src/Nest/CommonAbstractions/Infer/NodeId/NodeIds.cs @@ -9,41 +9,42 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class NodeIds : IEquatable, IUrlParameter { - private readonly IList _nodeIds; - internal IList Value => _nodeIds; - public NodeIds(IEnumerable nodeIds) { - this._nodeIds = nodeIds?.ToList(); - if (!this._nodeIds.HasAny()) - throw new ArgumentException($"can not create {nameof(NodeIds )} on an empty enumerable of ", nameof(nodeIds)); + Value = nodeIds?.ToList(); + if (!Value.HasAny()) + throw new ArgumentException($"can not create {nameof(NodeIds)} on an empty enumerable of ", nameof(nodeIds)); } + internal IList Value { get; } + private string DebugDisplay => ((IUrlParameter)this).GetString(null); - string IUrlParameter.GetString(IConnectionConfigurationValues settings) => string.Join(",", this._nodeIds); + public bool Equals(NodeIds other) => EqualsAllIds(Value, other.Value); + + string IUrlParameter.GetString(IConnectionConfigurationValues settings) => string.Join(",", Value); public static NodeIds Parse(string nodeIds) => nodeIds.IsNullOrEmptyCommaSeparatedList(out var nodes) ? null : new NodeIds(nodes); public static implicit operator NodeIds(string nodes) => Parse(nodes); + public static implicit operator NodeIds(string[] nodes) => nodes.IsEmpty() ? null : new NodeIds(nodes); public static bool operator ==(NodeIds left, NodeIds right) => Equals(left, right); public static bool operator !=(NodeIds left, NodeIds right) => !Equals(left, right); - public bool Equals(NodeIds other) => EqualsAllIds(this.Value, other.Value); - private static bool EqualsAllIds(ICollection thisIds, ICollection otherIds) { if (thisIds == null && otherIds == null) return true; if (thisIds == null || otherIds == null) return false; if (thisIds.Count != otherIds.Count) return false; + return thisIds.Count == otherIds.Count && !thisIds.Except(otherIds).Any(); } - public override bool Equals(object obj) => obj is string s ? this.Equals(Parse(s)) : (obj is NodeIds i) && this.Equals(i); + public override bool Equals(object obj) => obj is string s ? Equals(Parse(s)) : obj is NodeIds i && Equals(i); - public override int GetHashCode() => this._nodeIds.GetHashCode(); + public override int GetHashCode() => Value.GetHashCode(); } } diff --git a/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyName.cs b/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyName.cs index 1f4a7ef6ea3..d902d6a28bb 100644 --- a/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyName.cs +++ b/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyName.cs @@ -10,21 +10,9 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class PropertyName : IEquatable, IUrlParameter { - private static int TypeHashCode { get; } = typeof(PropertyName).GetHashCode(); - - public string Name { get; } - public Expression Expression { get; } - public PropertyInfo Property { get; } - public bool CacheableExpression { get; } - private readonly object _comparisonValue; private readonly Type _type; - internal string DebugDisplay => - $"{Expression?.ToString() ?? PropertyDebug ?? Name}{(_type == null ? "" : " typeof: " + _type.Name)}"; - - private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}"; - public PropertyName(string name) { Name = name; @@ -46,6 +34,29 @@ public PropertyName(PropertyInfo property) _type = property.DeclaringType; } + public bool CacheableExpression { get; } + public Expression Expression { get; } + + public string Name { get; } + public PropertyInfo Property { get; } + + internal string DebugDisplay => + $"{Expression?.ToString() ?? PropertyDebug ?? Name}{(_type == null ? "" : " typeof: " + _type.Name)}"; + + private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}"; + private static int TypeHashCode { get; } = typeof(PropertyName).GetHashCode(); + + public bool Equals(PropertyName other) => EqualsMarker(other); + + string IUrlParameter.GetString(IConnectionConfigurationValues settings) + { + if (!(settings is IConnectionSettingsValues nestSettings)) + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(PropertyName)} if no {nameof(IConnectionSettingsValues)} is provided"); + + return nestSettings.Inferrer.PropertyName(this); + } + public static implicit operator PropertyName(string name) => name.IsNullOrEmpty() ? null : new PropertyName(name); public static implicit operator PropertyName(Expression expression) => expression == null ? null : new PropertyName(expression); @@ -63,30 +74,17 @@ public override int GetHashCode() } } - public bool Equals(PropertyName other) => EqualsMarker(other); - public override bool Equals(object obj) => - obj is string s ? this.EqualsString(s) : (obj is PropertyName r) && this.EqualsMarker(r); + obj is string s ? EqualsString(s) : obj is PropertyName r && EqualsMarker(r); - private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == this.Name; + private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == Name; - public bool EqualsMarker(PropertyName other) - { - return _type != null - ? other != null && _type == other._type && _comparisonValue.Equals(other._comparisonValue) - : other != null && _comparisonValue.Equals(other._comparisonValue); - } + public bool EqualsMarker(PropertyName other) => _type != null + ? other != null && _type == other._type && _comparisonValue.Equals(other._comparisonValue) + : other != null && _comparisonValue.Equals(other._comparisonValue); public static bool operator ==(PropertyName left, PropertyName right) => Equals(left, right); public static bool operator !=(PropertyName left, PropertyName right) => !Equals(left, right); - - string IUrlParameter.GetString(IConnectionConfigurationValues settings) - { - if (!(settings is IConnectionSettingsValues nestSettings)) - throw new ArgumentNullException(nameof(settings), $"Can not resolve {nameof(PropertyName)} if no {nameof(IConnectionSettingsValues)} is provided"); - - return nestSettings.Inferrer.PropertyName(this); - } } } diff --git a/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyNameExtensions.cs b/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyNameExtensions.cs index 7965692fe70..bb89ca4648a 100644 --- a/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyNameExtensions.cs +++ b/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyNameExtensions.cs @@ -2,9 +2,7 @@ { internal static class PropertyNameExtensions { - internal static bool IsConditionless(this PropertyName property) - { - return property == null || (property.Name.IsNullOrEmpty() && property.Expression == null && property.Property == null); - } + internal static bool IsConditionless(this PropertyName property) => + property == null || property.Name.IsNullOrEmpty() && property.Expression == null && property.Property == null; } } diff --git a/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyNameJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyNameJsonConverter.cs index 96d954582e7..061979dd249 100644 --- a/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyNameJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/PropertyName/PropertyNameJsonConverter.cs @@ -22,12 +22,13 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s var infer = serializer.GetConnectionSettings().Inferrer; writer.WriteValue(infer.PropertyName(property)); } + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.String) return null; + var property = reader.Value.ToString(); return (PropertyName)property; } } } - diff --git a/src/Nest/CommonAbstractions/Infer/RelationName/RelationName.cs b/src/Nest/CommonAbstractions/Infer/RelationName/RelationName.cs index 1ad349e87fe..dcd603130a8 100644 --- a/src/Nest/CommonAbstractions/Infer/RelationName/RelationName.cs +++ b/src/Nest/CommonAbstractions/Infer/RelationName/RelationName.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.Linq; using Elasticsearch.Net; namespace Nest @@ -9,14 +8,28 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class RelationName : IEquatable, IUrlParameter { + private RelationName(string type) => Name = type; + + private RelationName(Type type) => Type = type; + public string Name { get; } public Type Type { get; } - private RelationName(string type) => this.Name = type; - private RelationName(Type type) => this.Type = type; - internal string DebugDisplay => Type == null ? Name : $"{nameof(RelationName)} for typeof: {Type?.Name}"; + private static int TypeHashCode { get; } = typeof(RelationName).GetHashCode(); + + public bool Equals(RelationName other) => EqualsMarker(other); + + string IUrlParameter.GetString(IConnectionConfigurationValues settings) + { + if (!(settings is IConnectionSettingsValues nestSettings)) + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(RelationName)} if no {nameof(IConnectionSettingsValues)} is provided"); + + return nestSettings.Inferrer.RelationName(this); + } + public static RelationName From() => typeof(T); public static RelationName Create(Type type) => GetRelationNameForType(type); @@ -29,13 +42,12 @@ public class RelationName : IEquatable, IUrlParameter public static implicit operator RelationName(Type type) => type == null ? null : new RelationName(type); - private static int TypeHashCode { get; } = typeof(RelationName).GetHashCode(); public override int GetHashCode() { unchecked { var result = TypeHashCode; - result = (result * 397) ^ (this.Name?.GetHashCode() ?? this.Type?.GetHashCode() ?? 0); + result = (result * 397) ^ (Name?.GetHashCode() ?? Type?.GetHashCode() ?? 0); return result; } } @@ -44,35 +56,27 @@ public override int GetHashCode() public static bool operator !=(RelationName left, RelationName right) => !Equals(left, right); - public bool Equals(RelationName other) => EqualsMarker(other); - public override bool Equals(object obj) => - obj is string s ? this.EqualsString(s) : (obj is RelationName r) && this.EqualsMarker(r); + obj is string s ? EqualsString(s) : obj is RelationName r && EqualsMarker(r); public bool EqualsMarker(RelationName other) { - if (!this.Name.IsNullOrEmpty() && other != null && !other.Name.IsNullOrEmpty()) + if (!Name.IsNullOrEmpty() && other != null && !other.Name.IsNullOrEmpty()) return EqualsString(other.Name); - if (this.Type != null && other?.Type != null) - return this.Type == other.Type; + if (Type != null && other?.Type != null) + return Type == other.Type; + return false; } + //already private in master, breaking change to change in 6.x - public bool EqualsString(string other) => !other.IsNullOrEmpty() && other == this.Name; + public bool EqualsString(string other) => !other.IsNullOrEmpty() && other == Name; public override string ToString() { - if (!this.Name.IsNullOrEmpty()) return this.Name; - return this.Type != null ? this.Type.Name : string.Empty; - } + if (!Name.IsNullOrEmpty()) return Name; - string IUrlParameter.GetString(IConnectionConfigurationValues settings) - { - if (!(settings is IConnectionSettingsValues nestSettings)) - throw new ArgumentNullException(nameof(settings), $"Can not resolve {nameof(RelationName)} if no {nameof(IConnectionSettingsValues)} is provided"); - - return nestSettings.Inferrer.RelationName(this); + return Type != null ? Type.Name : string.Empty; } - } } diff --git a/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameExtensions.cs b/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameExtensions.cs index d44ab306484..c5e5b9ed373 100644 --- a/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameExtensions.cs +++ b/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameExtensions.cs @@ -2,9 +2,6 @@ { internal static class RelationNameExtensions { - internal static bool IsConditionless(this RelationName marker) - { - return marker == null || marker.Name.IsNullOrEmpty() && marker.Type == null; - } + internal static bool IsConditionless(this RelationName marker) => marker == null || marker.Name.IsNullOrEmpty() && marker.Type == null; } } diff --git a/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameJsonConverter.cs index eda005474b8..5e77f2a8562 100644 --- a/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameJsonConverter.cs @@ -5,10 +5,7 @@ namespace Nest { internal class RelationNameJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) - { - return typeof(RelationName) == objectType; - } + public override bool CanConvert(Type objectType) => typeof(RelationName) == objectType; public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { @@ -28,8 +25,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { if (reader.TokenType == JsonToken.String) { - string typeName = reader.Value.ToString(); - return (RelationName) typeName; + var typeName = reader.Value.ToString(); + return (RelationName)typeName; } return null; } diff --git a/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameResolver.cs b/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameResolver.cs index a931f0d1330..a9c28e45667 100644 --- a/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameResolver.cs +++ b/src/Nest/CommonAbstractions/Infer/RelationName/RelationNameResolver.cs @@ -11,16 +11,17 @@ public class RelationNameResolver public RelationNameResolver(IConnectionSettingsValues connectionSettings) { connectionSettings.ThrowIfNull(nameof(connectionSettings)); - this._connectionSettings = connectionSettings; + _connectionSettings = connectionSettings; } - public string Resolve() where T : class => this.Resolve(typeof(T)); + public string Resolve() where T : class => Resolve(typeof(T)); - public string Resolve(RelationName t) => t?.Name ?? this.ResolveType(t?.Type); + public string Resolve(RelationName t) => t?.Name ?? ResolveType(t?.Type); private string ResolveType(Type type) { if (type == null) return null; + string typeName; if (RelationNames.TryGetValue(type, out typeName)) @@ -41,6 +42,5 @@ private string ResolveType(Type type) RelationNames.TryAdd(type, typeName); return typeName; } - } } diff --git a/src/Nest/CommonAbstractions/Infer/TaskId/TaskId.cs b/src/Nest/CommonAbstractions/Infer/TaskId/TaskId.cs index 80f52d4f409..2d4bd1e9b20 100644 --- a/src/Nest/CommonAbstractions/Infer/TaskId/TaskId.cs +++ b/src/Nest/CommonAbstractions/Infer/TaskId/TaskId.cs @@ -8,12 +8,6 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class TaskId : IUrlParameter, IEquatable { - public string NodeId { get; } - public long TaskNumber { get; } - public string FullyQualifiedId { get; } - - private string DebugDisplay => FullyQualifiedId; - /// /// A task id exists in the form [node_id]:[task_id] /// @@ -27,37 +21,43 @@ public TaskId(string taskId) if (tokens.Length != 2) throw new ArgumentException($"TaskId:{taskId} not in expected format of :", nameof(taskId)); - this.NodeId = tokens[0]; - this.FullyQualifiedId = taskId; + NodeId = tokens[0]; + FullyQualifiedId = taskId; if (!long.TryParse(tokens[1].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out var t) || t < -1 || t == 0) throw new ArgumentException($"TaskId task component:{tokens[1]} could not be parsed to long or is out of range", nameof(taskId)); - this.TaskNumber = t; + TaskNumber = t; } - public override string ToString() => FullyQualifiedId; + public string FullyQualifiedId { get; } + public string NodeId { get; } + public long TaskNumber { get; } + + private string DebugDisplay => FullyQualifiedId; + + public bool Equals(TaskId other) => EqualsString(other?.FullyQualifiedId); public string GetString(IConnectionConfigurationValues settings) => FullyQualifiedId; + public override string ToString() => FullyQualifiedId; + public static implicit operator TaskId(string taskId) => taskId.IsNullOrEmpty() ? null : new TaskId(taskId); public static bool operator ==(TaskId left, TaskId right) => Equals(left, right); public static bool operator !=(TaskId left, TaskId right) => !Equals(left, right); - public bool Equals(TaskId other) => EqualsString(other?.FullyQualifiedId); - public override bool Equals(object obj) => - obj != null && obj is string s ? this.EqualsString(s) : (obj is TaskId i) && this.EqualsString(i.FullyQualifiedId); + obj != null && obj is string s ? EqualsString(s) : obj is TaskId i && EqualsString(i.FullyQualifiedId); - private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == this.FullyQualifiedId; + private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == FullyQualifiedId; public override int GetHashCode() { unchecked { - return (NodeId.GetHashCode()*397) ^ TaskNumber.GetHashCode(); + return (NodeId.GetHashCode() * 397) ^ TaskNumber.GetHashCode(); } } } diff --git a/src/Nest/CommonAbstractions/Infer/TypeName/TypeName.cs b/src/Nest/CommonAbstractions/Infer/TypeName/TypeName.cs index 9fec2f045d8..35c92591800 100644 --- a/src/Nest/CommonAbstractions/Infer/TypeName/TypeName.cs +++ b/src/Nest/CommonAbstractions/Infer/TypeName/TypeName.cs @@ -9,16 +9,26 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class TypeName : IEquatable, IUrlParameter { - private static int TypeHashCode { get; } = typeof(TypeName).GetHashCode(); + private TypeName(string type) => Name = type; + + private TypeName(Type type) => Type = type; public string Name { get; } public Type Type { get; } - private TypeName(string type) => this.Name = type; + internal string DebugDisplay => Type == null ? Name : $"{nameof(TypeName)} for typeof: {Type?.Name}"; + private static int TypeHashCode { get; } = typeof(TypeName).GetHashCode(); - private TypeName(Type type) => this.Type = type; + public bool Equals(TypeName other) => EqualsMarker(other); - internal string DebugDisplay => Type == null ? Name : $"{nameof(TypeName)} for typeof: {Type?.Name}"; + string IUrlParameter.GetString(IConnectionConfigurationValues settings) + { + if (!(settings is IConnectionSettingsValues nestSettings)) + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(TypeName)} if no {nameof(IConnectionSettingsValues)} is provided"); + + return nestSettings.Inferrer.TypeName(this); + } public static TypeName Create(Type type) => GetTypeNameForType(type); @@ -35,57 +45,50 @@ public override int GetHashCode() unchecked { var result = TypeHashCode; - result = (result * 397) ^ (this.Name?.GetHashCode() ?? this.Type?.GetHashCode() ?? 0); + result = (result * 397) ^ (Name?.GetHashCode() ?? Type?.GetHashCode() ?? 0); return result; } } + public static bool operator ==(TypeName left, TypeName right) => Equals(left, right); public static bool operator !=(TypeName left, TypeName right) => !Equals(left, right); - public bool Equals(TypeName other) => EqualsMarker(other); - public override bool Equals(object obj) { var s = obj as string; - if (!s.IsNullOrEmpty()) return this.EqualsString(s); + if (!s.IsNullOrEmpty()) return EqualsString(s); + var pp = obj as TypeName; - return this.EqualsMarker(pp); + return EqualsMarker(pp); } public override string ToString() { - if (!this.Name.IsNullOrEmpty()) - return this.Name; - return this.Type != null ? this.Type.Name : string.Empty; + if (!Name.IsNullOrEmpty()) + return Name; + + return Type != null ? Type.Name : string.Empty; } private bool EqualsMarker(TypeName other) { - if (!this.Name.IsNullOrEmpty() && other != null && !other.Name.IsNullOrEmpty()) + if (!Name.IsNullOrEmpty() && other != null && !other.Name.IsNullOrEmpty()) return EqualsString(other.Name); - if (this.Type != null && other?.Type != null) - return this.Type == other.Type; - return false; - } + if (Type != null && other?.Type != null) + return Type == other.Type; - private bool EqualsString(string other) - { - return !other.IsNullOrEmpty() && other == this.Name; + return false; } - string IUrlParameter.GetString(IConnectionConfigurationValues settings) - { - if (!(settings is IConnectionSettingsValues nestSettings)) - throw new ArgumentNullException(nameof(settings), $"Can not resolve {nameof(TypeName)} if no {nameof(IConnectionSettingsValues)} is provided"); - - return nestSettings.Inferrer.TypeName(this); - } + private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == Name; public static TypeName From() => typeof(T); - public Types And() => new Types(new TypeName[] { this, typeof(T)}); + public Types And() => new Types(new TypeName[] { this, typeof(T) }); + public Types And(TypeName type) => new Types(new TypeName[] { this, type }); + public Types And(TypeName[] types) => new Types(new TypeName[] { this }.Concat(types)); } } diff --git a/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameExtensions.cs b/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameExtensions.cs index b61707ba4e8..8a04c7dbf8c 100644 --- a/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameExtensions.cs +++ b/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameExtensions.cs @@ -2,9 +2,6 @@ { internal static class TypeNameExtensions { - internal static bool IsConditionless(this TypeName marker) - { - return marker == null || marker.Name.IsNullOrEmpty() && marker.Type == null; - } + internal static bool IsConditionless(this TypeName marker) => marker == null || marker.Name.IsNullOrEmpty() && marker.Type == null; } } diff --git a/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameJsonConverter.cs index 7f14d21bc9d..8992a89cb17 100644 --- a/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameJsonConverter.cs @@ -5,10 +5,7 @@ namespace Nest { internal class TypeNameJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) - { - return typeof(TypeName) == objectType; - } + public override bool CanConvert(Type objectType) => typeof(TypeName) == objectType; public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { @@ -28,11 +25,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { if (reader.TokenType == JsonToken.String) { - string typeName = reader.Value.ToString(); - return (TypeName) typeName; + var typeName = reader.Value.ToString(); + return (TypeName)typeName; } return null; } - } } diff --git a/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameResolver.cs b/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameResolver.cs index 6cd13ed68fa..1e0b25a6175 100644 --- a/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameResolver.cs +++ b/src/Nest/CommonAbstractions/Infer/TypeName/TypeNameResolver.cs @@ -13,12 +13,12 @@ public class TypeNameResolver public TypeNameResolver(IConnectionSettingsValues connectionSettings) { connectionSettings.ThrowIfNull(nameof(connectionSettings)); - this._connectionSettings = connectionSettings; + _connectionSettings = connectionSettings; } - public string Resolve() where T : class => this.Resolve(typeof(T)); + public string Resolve() where T : class => Resolve(typeof(T)); - public string Resolve(TypeName t) => t?.Name ?? this.ResolveType(t?.Type); + public string Resolve(TypeName t) => t?.Name ?? ResolveType(t?.Type); private string ResolveType(Type type) { @@ -41,7 +41,7 @@ private string ResolveType(Type type) if (dataContract?.Name != null) typeName = dataContract.Name; else { - var inferredType =_connectionSettings.DefaultTypeNameInferrer(type); + var inferredType = _connectionSettings.DefaultTypeNameInferrer(type); typeName = !inferredType.IsNullOrEmpty() ? inferredType : _connectionSettings.DefaultTypeName; } } diff --git a/src/Nest/CommonAbstractions/Infer/Types/Types.cs b/src/Nest/CommonAbstractions/Infer/Types/Types.cs index b2e4a4ecd25..2d562d60a65 100644 --- a/src/Nest/CommonAbstractions/Infer/Types/Types.cs +++ b/src/Nest/CommonAbstractions/Infer/Types/Types.cs @@ -10,86 +10,78 @@ namespace Nest [DebuggerDisplay("{DebugDisplay,nq}")] public class Types : Union, IUrlParameter, IEquatable { - public class AllTypesMarker { internal AllTypesMarker() { } } + internal Types(AllTypesMarker all) : base(all) { } + + internal Types(ManyTypes types) : base(types) { } + + internal Types(IEnumerable types) : base(new ManyTypes(types)) { } + public static AllTypesMarker All { get; } = new AllTypesMarker(); public static AllTypesMarker AllTypes { get; } = new AllTypesMarker(); - public class ManyTypes + + private string DebugDisplay => Match( + all => "_all", + types => $"Count: {types.Types.Count} [" + string.Join(",", types.Types.Select((t, i) => $"({i + 1}: {t.DebugDisplay})")) + "]" + ); + + public bool Equals(Types other) { - private readonly List _types = new List(); - public IReadOnlyList Types => _types; - internal ManyTypes(IEnumerable types) - { - types.ThrowIfEmpty(nameof(types)); - this._types.AddRange(types); - } + if (other == null) return false; - internal ManyTypes(IEnumerable types) - { - types.ThrowIfEmpty(nameof(types)); - this._types.AddRange(types.Select(s=>(TypeName)s)); - } + return Match( + all => other.Match(a => true, m => false), + many => other.Match( + a => false, + m => EqualsAllTypes(m.Types, many.Types) + ) + ); + } - public ManyTypes And() + string IUrlParameter.GetString(IConnectionConfigurationValues settings) => Match( + all => null, + many => { - this._types.Add(typeof(T)); - return this; - } - } + if (!(settings is IConnectionSettingsValues nestSettings)) + throw new ArgumentNullException(nameof(settings), $"Can not resolve Types if no {nameof(IConnectionSettingsValues)} is provided"); - internal Types(AllTypesMarker all) : base(all) { } - internal Types(ManyTypes types) : base(types) { } - internal Types(IEnumerable types) : base(new ManyTypes(types)) { } + var types = many.Types.Select(t => nestSettings.Inferrer.TypeName(t)).Distinct(); + return string.Join(",", types); + } + ); public static TypeName Type(TypeName type) => type; + public static TypeName Type() => typeof(T); + public static ManyTypes Type(IEnumerable types) => new ManyTypes(types); + public static ManyTypes Type(params TypeName[] types) => new ManyTypes(types); + public static ManyTypes Type(IEnumerable indices) => new ManyTypes(indices); + public static ManyTypes Type(params string[] indices) => new ManyTypes(indices); - public static Types Parse(string typesString) => typesString.IsNullOrEmptyCommaSeparatedList(out var types) ? null : Type(types.Select(i => (TypeName)i)); + public static Types Parse(string typesString) => + typesString.IsNullOrEmptyCommaSeparatedList(out var types) ? null : Type(types.Select(i => (TypeName)i)); public static implicit operator Types(string typesString) => Parse(typesString); + public static implicit operator Types(AllTypesMarker all) => all == null ? null : new Types(all); + public static implicit operator Types(ManyTypes many) => many == null ? null : new Types(many); + public static implicit operator Types(TypeName type) => type == null ? null : new ManyTypes(new[] { type }); - public static implicit operator Types(TypeName[] type) => type.IsEmpty() ? null : new ManyTypes(type); - public static implicit operator Types(string[] many) => many.IsEmpty() ? null : new ManyTypes(many); - public static implicit operator Types(Type type) => type == null ? null : new ManyTypes(new TypeName[] { type }); - private string DebugDisplay => this.Match( - all => "_all", - types => $"Count: {types.Types.Count} [" + string.Join(",", types.Types.Select((t, i) => $"({i+1}: {t.DebugDisplay})")) + "]" - ); + public static implicit operator Types(TypeName[] type) => type.IsEmpty() ? null : new ManyTypes(type); - string IUrlParameter.GetString(IConnectionConfigurationValues settings) => this.Match( - all => null, - many => - { - if (!(settings is IConnectionSettingsValues nestSettings)) - throw new ArgumentNullException(nameof(settings), $"Can not resolve Types if no {nameof(IConnectionSettingsValues)} is provided"); + public static implicit operator Types(string[] many) => many.IsEmpty() ? null : new ManyTypes(many); - var types = many.Types.Select(t => nestSettings.Inferrer.TypeName(t)).Distinct(); - return string.Join(",", types); - } - ); + public static implicit operator Types(Type type) => type == null ? null : new ManyTypes(new TypeName[] { type }); public static bool operator ==(Types left, Types right) => Equals(left, right); public static bool operator !=(Types left, Types right) => !Equals(left, right); - public bool Equals(Types other) - { - if (other == null) return false; - return this.Match( - all => other.Match(a => true, m => false), - many => other.Match( - a => false, - m => EqualsAllTypes(m.Types, many.Types) - ) - ); - } - public override bool Equals(object obj) { Types other = null; @@ -104,15 +96,43 @@ private static bool EqualsAllTypes(IReadOnlyList thisTypes, IReadOnlyL if (thisTypes == null && otherTypes == null) return true; if (thisTypes == null || otherTypes == null) return false; if (thisTypes.Count != otherTypes.Count) return false; + return thisTypes.Count == otherTypes.Count && !thisTypes.Except(otherTypes).Any(); } - public override int GetHashCode() + public override int GetHashCode() => Match( + all => "_all".GetHashCode(), + many => string.Concat(many.Types).GetHashCode() + ); + + public class AllTypesMarker { - return this.Match( - all => "_all".GetHashCode(), - many => string.Concat(many.Types).GetHashCode() - ); + internal AllTypesMarker() { } + } + + public class ManyTypes + { + private readonly List _types = new List(); + + internal ManyTypes(IEnumerable types) + { + types.ThrowIfEmpty(nameof(types)); + _types.AddRange(types); + } + + internal ManyTypes(IEnumerable types) + { + types.ThrowIfEmpty(nameof(types)); + _types.AddRange(types.Select(s => (TypeName)s)); + } + + public IReadOnlyList Types => _types; + + public ManyTypes And() + { + _types.Add(typeof(T)); + return this; + } } } } diff --git a/src/Nest/CommonAbstractions/Infer/Types/TypesJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/Types/TypesJsonConverter.cs index fa8cd203d1b..bf540d07b00 100644 --- a/src/Nest/CommonAbstractions/Infer/Types/TypesJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/Types/TypesJsonConverter.cs @@ -19,12 +19,12 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s return; } marker.Match( - all=> writer.WriteNull(), + all => writer.WriteNull(), many => { var settings = serializer.GetConnectionSettings(); writer.WriteStartArray(); - foreach(var m in many.Types.Cast()) + foreach (var m in many.Types.Cast()) writer.WriteValue(m.GetString(settings)); writer.WriteEndArray(); } @@ -33,8 +33,8 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - if (reader.TokenType != JsonToken.StartArray) return null; + var types = new List(); while (reader.TokenType != JsonToken.EndArray) { @@ -44,6 +44,5 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } return new Types(types); } - } } diff --git a/src/Nest/CommonAbstractions/Infer/Types/TypesMultiSyntaxJsonConverter.cs b/src/Nest/CommonAbstractions/Infer/Types/TypesMultiSyntaxJsonConverter.cs index 9667af1330d..b4266e48aad 100644 --- a/src/Nest/CommonAbstractions/Infer/Types/TypesMultiSyntaxJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Infer/Types/TypesMultiSyntaxJsonConverter.cs @@ -17,7 +17,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s return; } marker.Match( - all=> writer.WriteNull(), + all => writer.WriteNull(), many => writer.WriteValue(((IUrlParameter)marker).GetString(serializer.GetConnectionSettings())) ); } @@ -26,11 +26,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { if (reader.TokenType == JsonToken.String) { - string types = reader.Value.ToString(); + var types = reader.Value.ToString(); return (Types)types; } return null; } - } } diff --git a/src/Nest/CommonAbstractions/LazyDocument/LazyDocument.cs b/src/Nest/CommonAbstractions/LazyDocument/LazyDocument.cs index 90809e23d1d..59e503061a3 100644 --- a/src/Nest/CommonAbstractions/LazyDocument/LazyDocument.cs +++ b/src/Nest/CommonAbstractions/LazyDocument/LazyDocument.cs @@ -1,8 +1,5 @@ using System; -using System.IO; -using System.Text; using Elasticsearch.Net; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Nest @@ -14,15 +11,15 @@ namespace Nest public interface ILazyDocument { /// - /// Creates an instance of from this - /// instance + /// Creates an instance of from this + /// instance /// /// The type T As(); /// - /// Creates an instance of from this - /// instance + /// Creates an instance of from this + /// instance /// /// The type object As(Type objectType); @@ -31,8 +28,6 @@ public interface ILazyDocument /// public class LazyDocument : ILazyDocument { - internal JToken Token { get; } - private readonly IElasticsearchSerializer _serializer; internal LazyDocument(JToken token, IElasticsearchSerializer serializer) @@ -41,6 +36,8 @@ internal LazyDocument(JToken token, IElasticsearchSerializer serializer) _serializer = serializer; } + internal JToken Token { get; } + /// public T As() { diff --git a/src/Nest/CommonAbstractions/LazyDocument/LazyDocumentJsonConverter.cs b/src/Nest/CommonAbstractions/LazyDocument/LazyDocumentJsonConverter.cs index 79c30fe2d71..d8d19d6e1c4 100644 --- a/src/Nest/CommonAbstractions/LazyDocument/LazyDocumentJsonConverter.cs +++ b/src/Nest/CommonAbstractions/LazyDocument/LazyDocumentJsonConverter.cs @@ -1,6 +1,5 @@ using System; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Nest { @@ -27,5 +26,4 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist public override bool CanConvert(Type objectType) => true; } - } diff --git a/src/Nest/CommonAbstractions/LowLevelDispatch/IHighLevelToLowLevelDispatcher.cs b/src/Nest/CommonAbstractions/LowLevelDispatch/IHighLevelToLowLevelDispatcher.cs index d7a851df5c0..2aee3a85a75 100644 --- a/src/Nest/CommonAbstractions/LowLevelDispatch/IHighLevelToLowLevelDispatcher.cs +++ b/src/Nest/CommonAbstractions/LowLevelDispatch/IHighLevelToLowLevelDispatcher.cs @@ -1,8 +1,8 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; -using System.Threading; namespace Nest { @@ -20,7 +20,7 @@ TResponse Dispatch( TRequest descriptor, Func responseGenerator, Func, TResponse> dispatch - ) + ) where TQueryString : RequestParameters, new() where TRequest : IRequest where TResponse : ResponseBase; @@ -29,7 +29,7 @@ Task DispatchAsync, CancellationToken, Task> dispatch - ) + ) where TQueryString : RequestParameters, new() where TRequest : IRequest where TResponse : ResponseBase, TResponseInterface diff --git a/src/Nest/CommonAbstractions/LowLevelDispatch/LowLevelDispatch.cs b/src/Nest/CommonAbstractions/LowLevelDispatch/LowLevelDispatch.cs index 785f33c37bf..9b8044799a0 100644 --- a/src/Nest/CommonAbstractions/LowLevelDispatch/LowLevelDispatch.cs +++ b/src/Nest/CommonAbstractions/LowLevelDispatch/LowLevelDispatch.cs @@ -8,12 +8,10 @@ namespace Nest { internal partial class LowLevelDispatch { + private static readonly Regex ReplaceParams = new Regex(@"\{(.+?)\}"); protected IElasticLowLevelClient _lowLevel; - public LowLevelDispatch(IElasticLowLevelClient rawElasticClient) - { - this._lowLevel = rawElasticClient; - } + public LowLevelDispatch(IElasticLowLevelClient rawElasticClient) => _lowLevel = rawElasticClient; internal bool AllSetNoFallback(params string[] pathVariables) => pathVariables.All(p => !p.IsNullOrEmpty()); @@ -26,7 +24,7 @@ internal static Exception InvalidDispatch(string apiCall, IRequest provided, Htt var sb = new StringBuilder(); sb.AppendLine($"Dispatching {apiCall}() from NEST into to Elasticsearch.NET failed"); sb.AppendLine($"Received a request marked as {provided.HttpMethod.GetStringValue()}"); - sb.AppendLine($"This endpoint accepts {string.Join(",", methods.Select(p=>p.GetStringValue()))}"); + sb.AppendLine($"This endpoint accepts {string.Join(",", methods.Select(p => p.GetStringValue()))}"); sb.AppendLine($"The request might not have enough information provided to make any of these endpoints:"); foreach (var endpoint in endpoints) sb.AppendLine($" - {PrettyPrintEndpoint(provided, endpoint)}"); @@ -34,37 +32,34 @@ internal static Exception InvalidDispatch(string apiCall, IRequest provided, Htt return new ArgumentException(sb.ToString()); } - private static readonly Regex ReplaceParams = new Regex(@"\{(.+?)\}"); - internal static string PrettyPrintEndpoint(IRequest request, string endpoint) { var pretty = ReplaceParams.Replace(endpoint, (m) => { var key = m.Groups[1].Value.ToLowerInvariant(); - switch(key) + switch (key) { - case "index" : return PrettyParam(key, request.RouteValues.Index); - case "name" : return PrettyParam(key, request.RouteValues.Name); - case "feature" : return PrettyParam(key, request.RouteValues.Feature); - case "field" : return PrettyParam(key, request.RouteValues.Field); - case "fields" : return PrettyParam(key, request.RouteValues.Fields); - case "id" : return PrettyParam(key, request.RouteValues.Id); - case "index_metric" : return PrettyParam(key, request.RouteValues.IndexMetric); - case "lang" : return PrettyParam(key, request.RouteValues.Lang); - case "metric" : return PrettyParam(key, request.RouteValues.Metric); - case "nodes" : return PrettyParam(key, request.RouteValues.NodeId); - case "node_id" : return PrettyParam(key, request.RouteValues.NodeId); - case "repository" : return PrettyParam(key, request.RouteValues.Repository); - case "scroll_id" : return PrettyParam(key, request.RouteValues.ScrollId); - case "snapshot" : return PrettyParam(key, request.RouteValues.Snapshot); - case "type" : return PrettyParam(key, request.RouteValues.Type); - default: return PrettyParam(key, ""); + case "index": return PrettyParam(key, request.RouteValues.Index); + case "name": return PrettyParam(key, request.RouteValues.Name); + case "feature": return PrettyParam(key, request.RouteValues.Feature); + case "field": return PrettyParam(key, request.RouteValues.Field); + case "fields": return PrettyParam(key, request.RouteValues.Fields); + case "id": return PrettyParam(key, request.RouteValues.Id); + case "index_metric": return PrettyParam(key, request.RouteValues.IndexMetric); + case "lang": return PrettyParam(key, request.RouteValues.Lang); + case "metric": return PrettyParam(key, request.RouteValues.Metric); + case "nodes": return PrettyParam(key, request.RouteValues.NodeId); + case "node_id": return PrettyParam(key, request.RouteValues.NodeId); + case "repository": return PrettyParam(key, request.RouteValues.Repository); + case "scroll_id": return PrettyParam(key, request.RouteValues.ScrollId); + case "snapshot": return PrettyParam(key, request.RouteValues.Snapshot); + case "type": return PrettyParam(key, request.RouteValues.Type); + default: return PrettyParam(key, ""); } }); return pretty; } private static string PrettyParam(string key, string value) => $"{{{key}={(value.IsNullOrEmpty() ? "" : value)}}}"; - } } diff --git a/src/Nest/CommonAbstractions/RawJson/RawJson.cs b/src/Nest/CommonAbstractions/RawJson/RawJson.cs index c968670982c..3cd5c2503de 100644 --- a/src/Nest/CommonAbstractions/RawJson/RawJson.cs +++ b/src/Nest/CommonAbstractions/RawJson/RawJson.cs @@ -5,11 +5,8 @@ /// internal class RawJson { - public string Data { get; set; } + public RawJson(string rawJsonData) => Data = rawJsonData; - public RawJson(string rawJsonData) - { - Data = rawJsonData; - } + public string Data { get; set; } } } diff --git a/src/Nest/CommonAbstractions/Reactive/BlockingSubscribeExtensions.cs b/src/Nest/CommonAbstractions/Reactive/BlockingSubscribeExtensions.cs index 764e363a3ff..72acf9a3647 100644 --- a/src/Nest/CommonAbstractions/Reactive/BlockingSubscribeExtensions.cs +++ b/src/Nest/CommonAbstractions/Reactive/BlockingSubscribeExtensions.cs @@ -10,7 +10,9 @@ public static BulkAllObserver Wait(this BulkAllObservable observable, Time WaitOnObservable, IBulkAllResponse, BulkAllObserver>( observable, maximumRunTime, (e, c) => new BulkAllObserver(onNext, e, c)); - public static ScrollAllObserver Wait(this IObservable> observable, TimeSpan maximumRunTime, Action> onNext) + public static ScrollAllObserver Wait(this IObservable> observable, TimeSpan maximumRunTime, + Action> onNext + ) where T : class => WaitOnObservable>, IScrollAllResponse, ScrollAllObserver>( observable, maximumRunTime, (e, c) => new ScrollAllObserver(onNext, e, c)); @@ -42,7 +44,8 @@ Func, Action, TObserver> factory observable.Subscribe(observer); handle.WaitOne(maximumRunTime); if (ex != null) throw ex; + return observer; } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/Reactive/CoordinatedRequestObserverBase.cs b/src/Nest/CommonAbstractions/Reactive/CoordinatedRequestObserverBase.cs index 3ce0c8e00b3..72d303dde4e 100644 --- a/src/Nest/CommonAbstractions/Reactive/CoordinatedRequestObserverBase.cs +++ b/src/Nest/CommonAbstractions/Reactive/CoordinatedRequestObserverBase.cs @@ -4,9 +4,9 @@ namespace Nest { internal static class CoordinatedRequestDefaults { - public static int BulkAllMaxDegreeOfParallelismDefault = 4; - public static TimeSpan BulkAllBackOffTimeDefault = TimeSpan.FromMinutes(1); public static int BulkAllBackOffRetriesDefault = 0; + public static TimeSpan BulkAllBackOffTimeDefault = TimeSpan.FromMinutes(1); + public static int BulkAllMaxDegreeOfParallelismDefault = 4; public static int BulkAllSizeDefault = 1000; public static int ReindexBackPressureFactor = 4; public static int ReindexScrollSize = 500; @@ -14,30 +14,21 @@ internal static class CoordinatedRequestDefaults public abstract class CoordinatedRequestObserverBase : IObserver { - private readonly Action _onNext; - private readonly Action _onError; private readonly Action _completed; + private readonly Action _onError; + private readonly Action _onNext; - protected CoordinatedRequestObserverBase(Action onNext = null, Action onError = null, System.Action completed = null) + protected CoordinatedRequestObserverBase(Action onNext = null, Action onError = null, Action completed = null) { _onNext = onNext; _onError = onError; _completed = completed; } - public void OnNext(T value) - { - this._onNext?.Invoke(value); - } + public void OnCompleted() => _completed?.Invoke(); - public void OnError(Exception error) - { - this._onError?.Invoke(error); - } + public void OnError(Exception error) => _onError?.Invoke(error); - public void OnCompleted() - { - this._completed?.Invoke(); - } + public void OnNext(T value) => _onNext?.Invoke(value); } } diff --git a/src/Nest/CommonAbstractions/Reactive/GetEnumerator.cs b/src/Nest/CommonAbstractions/Reactive/GetEnumerator.cs index d7a08f6e77d..a6b48c1e046 100644 --- a/src/Nest/CommonAbstractions/Reactive/GetEnumerator.cs +++ b/src/Nest/CommonAbstractions/Reactive/GetEnumerator.cs @@ -8,12 +8,11 @@ namespace Nest { internal class GetEnumerator : IEnumerator, IObserver { + private readonly SemaphoreSlim _gate; private readonly ConcurrentQueue _queue; private TSource _current; - private Exception _error; private bool _disposed; - - private readonly SemaphoreSlim _gate; + private Exception _error; private IDisposable _subscription; public GetEnumerator() @@ -22,33 +21,15 @@ public GetEnumerator() _gate = new SemaphoreSlim(0); } - private IEnumerator Run(IObservable source) - { - // - // [OK] Use of unsafe Subscribe: non-pretentious exact mirror with the dual GetEnumerator method. - // - _subscription = source.Subscribe/*Unsafe*/(this); - return this; - } - public IEnumerable ToEnumerable(IObservable source) => - new AnonymousEnumerable(() => this.Run(source)); + public TSource Current => _current; - public virtual void OnNext(TSource value) - { - _queue.Enqueue(value); - _gate.Release(); - } + object IEnumerator.Current => _current; - public void OnError(Exception error) + public void Dispose() { - _error = error; _subscription.Dispose(); - _gate.Release(); - } - public void OnCompleted() - { - _subscription.Dispose(); + _disposed = true; _gate.Release(); } @@ -68,41 +49,48 @@ public bool MoveNext() return false; } - public TSource Current => _current; + public void Reset() => throw new NotSupportedException(); - object IEnumerator.Current => _current; + public void OnCompleted() + { + _subscription.Dispose(); + _gate.Release(); + } - public void Dispose() + public void OnError(Exception error) { + _error = error; _subscription.Dispose(); + _gate.Release(); + } - _disposed = true; + public virtual void OnNext(TSource value) + { + _queue.Enqueue(value); _gate.Release(); } - public void Reset() + private IEnumerator Run(IObservable source) { - throw new NotSupportedException(); + // + // [OK] Use of unsafe Subscribe: non-pretentious exact mirror with the dual GetEnumerator method. + // + _subscription = source.Subscribe /*Unsafe*/(this); + return this; } + public IEnumerable ToEnumerable(IObservable source) => + new AnonymousEnumerable(() => Run(source)); + internal sealed class AnonymousEnumerable : IEnumerable { private readonly Func> _getEnumerator; - public AnonymousEnumerable(Func> getEnumerator) - { - this._getEnumerator = getEnumerator; - } + public AnonymousEnumerable(Func> getEnumerator) => _getEnumerator = getEnumerator; - public IEnumerator GetEnumerator() - { - return _getEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return this.GetEnumerator(); - } + public IEnumerator GetEnumerator() => _getEnumerator(); } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/Reactive/PartitionHelper.cs b/src/Nest/CommonAbstractions/Reactive/PartitionHelper.cs index 6e3b2c6a5ae..1c9d4299fdd 100644 --- a/src/Nest/CommonAbstractions/Reactive/PartitionHelper.cs +++ b/src/Nest/CommonAbstractions/Reactive/PartitionHelper.cs @@ -16,7 +16,8 @@ internal PartitionHelper(IEnumerable i, int ps) _partitionSize = ps; } - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + public IEnumerator> GetEnumerator() { using (var enumerator = _items.GetEnumerator()) @@ -32,9 +33,10 @@ private IEnumerable GetNextBatch(IEnumerator enumerator) for (var i = 0; i < _partitionSize; ++i) { yield return enumerator.Current; + _hasMoreItems = enumerator.MoveNext(); if (!_hasMoreItems) yield break; } } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/Reactive/ProducerConsumerBackPressure.cs b/src/Nest/CommonAbstractions/Reactive/ProducerConsumerBackPressure.cs index 141835016fb..ddfcd375795 100644 --- a/src/Nest/CommonAbstractions/Reactive/ProducerConsumerBackPressure.cs +++ b/src/Nest/CommonAbstractions/Reactive/ProducerConsumerBackPressure.cs @@ -10,32 +10,35 @@ namespace Nest /// public class ProducerConsumerBackPressure { - private readonly SemaphoreSlim _consumerLimiter; private readonly int _backPressureFactor; + private readonly SemaphoreSlim _consumerLimiter; private readonly int _slots; /// /// Simple back pressure implementation that makes sure the minimum max concurrency between producer and consumer /// is not amplified by the greedier of the two by more then the backPressureFactor /// - /// The maximum amplification back pressure of the greedier part of the producer consumer pipeline, if null defaults to 4 + /// + /// The maximum amplification back pressure of the greedier part of the producer consumer pipeline, if null + /// defaults to 4 + /// /// The minimum maximum concurrency which would be the bottleneck of the producer consumer pipeline internal ProducerConsumerBackPressure(int? backPressureFactor, int maxConcurrency) { - this._backPressureFactor = backPressureFactor.GetValueOrDefault(4); - this._slots = maxConcurrency * this._backPressureFactor; - this._consumerLimiter = new SemaphoreSlim(_slots, _slots); + _backPressureFactor = backPressureFactor.GetValueOrDefault(4); + _slots = maxConcurrency * _backPressureFactor; + _consumerLimiter = new SemaphoreSlim(_slots, _slots); } public Task WaitAsync(CancellationToken token = default(CancellationToken)) => - this._consumerLimiter.WaitAsync(token); + _consumerLimiter.WaitAsync(token); public void Release() { - var minimumRelease = _slots - this._consumerLimiter.CurrentCount; - var release = Math.Min(minimumRelease, this._backPressureFactor); + var minimumRelease = _slots - _consumerLimiter.CurrentCount; + var release = Math.Min(minimumRelease, _backPressureFactor); if (release > 0) - this._consumerLimiter.Release(release); + _consumerLimiter.Release(release); } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/Request/RequestBase.cs b/src/Nest/CommonAbstractions/Request/RequestBase.cs index 182f8d21c2d..34610417896 100644 --- a/src/Nest/CommonAbstractions/Request/RequestBase.cs +++ b/src/Nest/CommonAbstractions/Request/RequestBase.cs @@ -33,42 +33,40 @@ public interface IProxyRequest : IRequest public abstract class RequestBase : IRequest where TParameters : IRequestParameters, new() { - [JsonIgnore] - protected IRequest RequestState => this; + protected RequestBase() => Initialize(); - protected RequestBase() - { - Initialize(); - } protected RequestBase(Func pathSelector) { pathSelector(RequestState.RouteValues); Initialize(); } - protected virtual void Initialize() { } - protected virtual HttpMethod HttpMethod => RequestState.RequestParameters.DefaultHttpMethod; [JsonIgnore] - HttpMethod IRequest.HttpMethod => this.HttpMethod; + protected IRequest RequestState => this; [JsonIgnore] - RouteValues IRequest.RouteValues { get; } = new RouteValues(); + HttpMethod IRequest.HttpMethod => HttpMethod; [JsonIgnore] TParameters IRequest.RequestParameters { get; set; } = new TParameters(); + [JsonIgnore] + RouteValues IRequest.RouteValues { get; } = new RouteValues(); + + protected virtual void Initialize() { } + protected TOut Q(string name) => RequestState.RequestParameters.GetQueryStringValue(name); protected void Q(string name, object value) => RequestState.RequestParameters.SetQueryString(name, value); - } public abstract partial class PlainRequestBase : RequestBase where TParameters : IRequestParameters, new() { protected PlainRequestBase() { } + protected PlainRequestBase(Func pathSelector) : base(pathSelector) { } /// @@ -81,31 +79,34 @@ public IRequestConfiguration RequestConfiguration } } - /// - /// Base class for all Request descriptor types - /// + /// + /// Base class for all Request descriptor types + /// public abstract partial class RequestDescriptorBase : RequestBase, IDescriptor where TDescriptor : RequestDescriptorBase, TInterface where TParameters : RequestParameters, new() { private readonly TDescriptor _descriptor; - protected RequestDescriptorBase() { _descriptor = (TDescriptor)this; } - protected RequestDescriptorBase(Func pathSelector) : base(pathSelector) { _descriptor = (TDescriptor)this; } + protected RequestDescriptorBase() => _descriptor = (TDescriptor)this; + + protected RequestDescriptorBase(Func pathSelector) : base(pathSelector) => _descriptor = (TDescriptor)this; - protected TInterface Self => _descriptor; protected IRequestConfiguration RequestConfig => ((IRequestParameters)RequestState.RequestParameters).RequestConfiguration; + protected TInterface Self => _descriptor; + protected TDescriptor Assign(Action assign) => Fluent.Assign(_descriptor, assign); protected TDescriptor AssignParam(Action assigner) { - assigner?.Invoke(this.RequestState.RequestParameters); + assigner?.Invoke(RequestState.RequestParameters); return _descriptor; } + protected TDescriptor Qs(Action assigner) { - assigner?.Invoke(this.RequestState.RequestParameters); + assigner?.Invoke(RequestState.RequestParameters); return _descriptor; } @@ -126,21 +127,21 @@ public TDescriptor RequestConfiguration(Func - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) => base.Equals(obj); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => base.GetHashCode(); /// - /// Hides the method. + /// Hides the method. /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Nest/CommonAbstractions/Request/RouteValues.cs b/src/Nest/CommonAbstractions/Request/RouteValues.cs index e77660c988b..93821e94cbd 100644 --- a/src/Nest/CommonAbstractions/Request/RouteValues.cs +++ b/src/Nest/CommonAbstractions/Request/RouteValues.cs @@ -1,59 +1,58 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Elasticsearch.Net; namespace Nest { public class RouteValues { - private readonly Dictionary _routeValues = new Dictionary(); private readonly Dictionary _resolved = new Dictionary(); + private readonly Dictionary _routeValues = new Dictionary(); + public string ActionId => GetResolved("action_id"); + public string Alias => GetResolved("alias"); + public string CategoryId => GetResolved("category_id"); + public string Context => GetResolved("context"); + public string DatafeedId => GetResolved("datafeed_id"); + public string Feature => GetResolved("feature"); + public string Field => GetResolved("field"); + public string Fields => GetResolved("fields"); + public string FilterId => GetResolved("filter_id"); + public string Id => GetResolved("id"); public string Index => GetResolved("index"); - public string Type => GetResolved("type"); - public string Id => GetResolved("id"); + public string IndexMetric => GetResolved("index_metric"); + public string JobId => GetResolved("job_id"); + public string Lang => GetResolved("lang"); + public string Metric => GetResolved("metric"); public string Name => GetResolved("name"); - public string Field => GetResolved("field"); - public string ScrollId => GetResolved("scroll_id"); + public string NewIndex => GetResolved("new_index"); public string NodeId => GetResolved("node_id"); - public string Fields => GetResolved("fields"); + public string Realms => GetResolved("realms"); public string Repository => GetResolved("repository"); + public string ScrollId => GetResolved("scroll_id"); public string Snapshot => GetResolved("snapshot"); - public string Feature => GetResolved("feature"); - public string Metric => GetResolved("metric"); - public string IndexMetric => GetResolved("index_metric"); - public string Lang => GetResolved("lang"); - public string TaskId => GetResolved("task_id"); - public string Realms => GetResolved("realms"); - public string Username => GetResolved("username"); + public string SnapshotId => GetResolved("snapshot_id"); public string Target => GetResolved("target"); - public string NewIndex => GetResolved("new_index"); - public string Alias => GetResolved("alias"); - public string WatchId => GetResolved("watch_id"); + public string TaskId => GetResolved("task_id"); public string ThreadPoolPatterns => GetResolved("thread_pool_patterns"); - public string ActionId => GetResolved("action_id"); - public string JobId => GetResolved("job_id"); - public string DatafeedId => GetResolved("datafeed_id"); - public string FilterId => GetResolved("filter_id"); - public string SnapshotId => GetResolved("snapshot_id"); - public string CategoryId => GetResolved("category_id"); public string Timestamp => GetResolved("timestamp"); - public string Context => GetResolved("context"); + public string Type => GetResolved("type"); + public string Username => GetResolved("username"); public WatcherStatsMetric? WatcherStatsMetric => GetResolved("watcher_stats_metric").ToEnum(); + public string WatchId => GetResolved("watch_id"); - private string GetResolved(string route) => this._resolved.TryGetValue(route, out var resolved) ? resolved : null; + private string GetResolved(string route) => _resolved.TryGetValue(route, out var resolved) ? resolved : null; private RouteValues Route(string name, IUrlParameter routeValue, bool required = true) { if (routeValue == null && !required) { - if (this._routeValues.ContainsKey(name)) - this._routeValues.Remove(name); + if (_routeValues.ContainsKey(name)) + _routeValues.Remove(name); return this; } if (routeValue == null) return this; - this._routeValues[name] = routeValue; + _routeValues[name] = routeValue; return this; } @@ -62,25 +61,27 @@ public void Resolve(IConnectionSettingsValues settings) foreach (var kv in _routeValues) { var key = kv.Value.GetString(settings); - this._resolved[kv.Key] = key.IsNullOrEmpty() ? key : key; + _resolved[kv.Key] = key.IsNullOrEmpty() ? key : key; } } internal RouteValues Required(string route, IUrlParameter value) => Route(route, value); + internal RouteValues Optional(string route, IUrlParameter value) => Route(route, value, false); internal TActual Get(string route) where TActual : class, IUrlParameter { IUrlParameter actual; - if (this._routeValues.TryGetValue(route, out actual) && actual != null) + if (_routeValues.TryGetValue(route, out actual) && actual != null) return (TActual)actual; + return null; } public void Remove(string route) { - this._resolved.Remove(route); - this._routeValues.Remove(route); + _resolved.Remove(route); + _routeValues.Remove(route); } } } diff --git a/src/Nest/CommonAbstractions/Response/DictionaryResponseBase.cs b/src/Nest/CommonAbstractions/Response/DictionaryResponseBase.cs index b8af6a47120..65b020264cc 100644 --- a/src/Nest/CommonAbstractions/Response/DictionaryResponseBase.cs +++ b/src/Nest/CommonAbstractions/Response/DictionaryResponseBase.cs @@ -29,10 +29,10 @@ public static JObject ReadServerErrorFirst(JsonReader reader, out Error error, o if (errorProperty?.Value?.Type == JTokenType.String) { var reason = errorProperty.Value.Value(); - error = new Error {Reason = reason}; + error = new Error { Reason = reason }; errorProperty.Remove(); } - else if (errorProperty?.Value?.Type == JTokenType.Object && ((JObject) errorProperty.Value)["reason"] != null) + else if (errorProperty?.Value?.Type == JTokenType.Object && ((JObject)errorProperty.Value)["reason"] != null) { error = errorProperty.Value.ToObject(); errorProperty.Remove(); @@ -51,10 +51,11 @@ public static JObject ReadServerErrorFirst(JsonReader reader, out Error error, o internal class DictionaryResponseJsonConverter : JsonConverter where TResponse : ResponseBase, IDictionaryResponse, new() { - public override bool CanConvert(Type objectType) => true; public override bool CanRead => true; public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => true; + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var j = DictionaryResponseJsonConverterHelpers.ReadServerErrorFirst(reader, out var error, out var statusCode); @@ -68,6 +69,5 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { } - } } diff --git a/src/Nest/CommonAbstractions/Response/ElasticsearchVersionInfo.cs b/src/Nest/CommonAbstractions/Response/ElasticsearchVersionInfo.cs index 97bd7578018..c1d5bd4d802 100644 --- a/src/Nest/CommonAbstractions/Response/ElasticsearchVersionInfo.cs +++ b/src/Nest/CommonAbstractions/Response/ElasticsearchVersionInfo.cs @@ -2,15 +2,14 @@ namespace Nest { - public class ElasticsearchVersionInfo { - public string Number { get; set; } - [JsonProperty("snapshot_build")] public bool IsSnapShotBuild { get; set; } [JsonProperty("lucene_version")] public string LuceneVersion { get; set; } + + public string Number { get; set; } } } diff --git a/src/Nest/CommonAbstractions/Response/ResolvableDictionaryProxy.cs b/src/Nest/CommonAbstractions/Response/ResolvableDictionaryProxy.cs index 0dff88b0263..7e1c0dadc9c 100644 --- a/src/Nest/CommonAbstractions/Response/ResolvableDictionaryProxy.cs +++ b/src/Nest/CommonAbstractions/Response/ResolvableDictionaryProxy.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using Elasticsearch.Net; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Nest { @@ -11,54 +10,55 @@ public class ResolvableDictionaryProxy : IIsAReadOnlyDictionary Original { get; } = EmptyReadOnly.Dictionary; - protected internal IReadOnlyDictionary BackingDictionary { get; } = EmptyReadOnly.Dictionary; internal ResolvableDictionaryProxy(IConnectionConfigurationValues connectionSettings, IReadOnlyDictionary backingDictionary) { - this._connectionSettings = connectionSettings; + _connectionSettings = connectionSettings; if (backingDictionary == null) return; - this.Original = backingDictionary; + Original = backingDictionary; var dictionary = new Dictionary(); foreach (var key in backingDictionary.Keys) dictionary[Sanitize(key)] = backingDictionary[key]; - this.BackingDictionary = dictionary; + BackingDictionary = dictionary; } - private string Sanitize(TKey key) => key?.GetString(_connectionSettings); + public int Count => BackingDictionary.Count; - IEnumerator> IEnumerable>.GetEnumerator() => - this.Original.GetEnumerator(); + public TValue this[TKey key] => BackingDictionary.TryGetValue(Sanitize(key), out var v) ? v : default(TValue); + public TValue this[string key] => BackingDictionary.TryGetValue(key, out var v) ? v : default(TValue); - IEnumerator IEnumerable.GetEnumerator() => this.Original.GetEnumerator(); + public IEnumerable Keys => Original.Keys; + public IEnumerable ResolvedKeys => BackingDictionary.Keys; - public int Count => this.BackingDictionary.Count; + public IEnumerable Values => BackingDictionary.Values; + protected internal IReadOnlyDictionary BackingDictionary { get; } = EmptyReadOnly.Dictionary; + private IReadOnlyDictionary Original { get; } = EmptyReadOnly.Dictionary; - public bool ContainsKey(TKey key) => this.BackingDictionary.ContainsKey(Sanitize(key)); + IEnumerator IEnumerable.GetEnumerator() => Original.GetEnumerator(); - public bool TryGetValue(TKey key, out TValue value) => - this.BackingDictionary.TryGetValue(Sanitize(key), out value); + IEnumerator> IEnumerable>.GetEnumerator() => + Original.GetEnumerator(); - public TValue this[TKey key] => this.BackingDictionary.TryGetValue(Sanitize(key), out var v) ? v : default(TValue); - public TValue this[string key] => this.BackingDictionary.TryGetValue(key, out var v) ? v : default(TValue); + public bool ContainsKey(TKey key) => BackingDictionary.ContainsKey(Sanitize(key)); - public IEnumerable Keys => this.Original.Keys; - public IEnumerable ResolvedKeys => this.BackingDictionary.Keys; + public bool TryGetValue(TKey key, out TValue value) => + BackingDictionary.TryGetValue(Sanitize(key), out value); - public IEnumerable Values => this.BackingDictionary.Values; + private string Sanitize(TKey key) => key?.GetString(_connectionSettings); } internal abstract class ResolvableDictionaryJsonConverterBase : JsonConverter where TDictionary : ResolvableDictionaryProxy where TKey : IUrlParameter { - public override bool CanConvert(Type objectType) => true; public override bool CanRead => true; public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => true; + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) @@ -71,11 +71,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } protected abstract TDictionary Create(IConnectionSettingsValues settings, Dictionary dictionary); - } internal class ResolvableDictionaryJsonConverter - : ResolvableDictionaryJsonConverterBase,TKey, TValue> + : ResolvableDictionaryJsonConverterBase, TKey, TValue> where TKey : IUrlParameter { protected override ResolvableDictionaryProxy Create(IConnectionSettingsValues s, Dictionary d) => @@ -83,12 +82,13 @@ protected override ResolvableDictionaryProxy Create(IConnectionSet } internal class ResolvableDictionaryResponseJsonConverter : JsonConverter - where TResponse : ResponseBase, IDictionaryResponse , new() where TKey : IUrlParameter + where TResponse : ResponseBase, IDictionaryResponse, new() where TKey : IUrlParameter { - public override bool CanConvert(Type objectType) => true; public override bool CanRead => true; public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => true; + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var j = DictionaryResponseJsonConverterHelpers.ReadServerErrorFirst(reader, out var error, out var statusCode); diff --git a/src/Nest/CommonAbstractions/Response/ResponseBase.cs b/src/Nest/CommonAbstractions/Response/ResponseBase.cs index 115c2f62b48..ce8bd6a588a 100644 --- a/src/Nest/CommonAbstractions/Response/ResponseBase.cs +++ b/src/Nest/CommonAbstractions/Response/ResponseBase.cs @@ -1,6 +1,4 @@ using System; -using System.Diagnostics; -using System.Linq; using System.Text; using Elasticsearch.Net; using Newtonsoft.Json; @@ -13,60 +11,92 @@ namespace Nest public interface IResponse : IElasticsearchResponse { /// - /// This property can be used to check if a response is functionally valid or not. - /// This is a NEST abstraction to have a single point to check whether something wrong happened with the request. - /// For instance an elasticsearch bulk response always returns 200 and individual bulk items may fail, will be false in that case - /// You can also configure the client to always throw an using if the response is not valid + /// A lazy human readable string representation of what happened during this request for both successful and + /// failed requests, very useful while developing or to log when is false on responses. /// [JsonIgnore] - bool IsValid { get; } + string DebugInformation { get; } /// - /// If the response results in an error on elasticsearch's side an
error
element will be returned, this is mapped to in NEST. - /// Possibly set when is false, depending on the cause of the error - /// You can also configure the client to always throw an using if the response is not valid + /// This property can be used to check if a response is functionally valid or not. + /// This is a NEST abstraction to have a single point to check whether something wrong happened with the request. + /// + /// For instance an elasticsearch bulk response always returns 200 and individual bulk items may fail, will be + /// false in that case + /// + /// + /// You can also configure the client to always throw an using + /// if the response is not valid + /// ///
[JsonIgnore] - ServerError ServerError { get; } + bool IsValid { get; } /// /// If the request resulted in an exception on the client side this will hold the exception that was thrown. - /// This property is a shortcut to 's and is possibly set when is false depending on the cause of the error - /// You can also configure the client to always throw an using if the response is not valid + /// + /// This property is a shortcut to 's and + /// is possibly set when is false depending on the cause of the error + /// + /// + /// You can also configure the client to always throw an using + /// if the response is not valid + /// /// [JsonIgnore] Exception OriginalException { get; } - /// - /// A lazy human readable string representation of what happened during this request for both successful and - /// failed requests, very useful while developing or to log when is false on responses. - /// - [JsonIgnore] - string DebugInformation { get; } + /// + /// If the response results in an error on elasticsearch's side an
error
element will be returned, this is mapped to + /// in NEST. + /// Possibly set when is false, depending on the cause of the error + /// + /// You can also configure the client to always throw an using + /// if the response is not valid + /// + ///
+ [JsonIgnore] + ServerError ServerError { get; } } public abstract class ResponseBase : IResponse { + private Error _error; private IApiCallDetails _originalApiCall; private ServerError _serverError; - private Error _error; private int? _statusCode; - [JsonIgnore] - IApiCallDetails IElasticsearchResponse.ApiCall { get => _originalApiCall; set => _originalApiCall = value; } + /// Returns useful information about the request(s) that were part of this API call. + public virtual IApiCallDetails ApiCall => _originalApiCall; - bool IElasticsearchResponse.TryGetServerErrorReason(out string reason) + /// + public string DebugInformation { - reason = this.ServerError?.Error?.ToString(); - return !reason.IsNullOrEmpty(); + get + { + var sb = new StringBuilder(); + sb.Append($"{(!IsValid ? "Inv" : "V")}alid NEST response built from a "); + sb.AppendLine(ApiCall?.ToString().ToCamelCase() ?? "null ApiCall which is highly exceptional, please open a bug if you see this"); + if (!IsValid) DebugIsValid(sb); + if (ApiCall != null) ResponseStatics.DebugInformationBuilder(ApiCall, sb); + return sb.ToString(); + } } + /// + public virtual bool IsValid => (ApiCall?.Success ?? false) && ServerError == null; + + + /// + public Exception OriginalException => ApiCall?.OriginalException; + public ServerError ServerError { get { if (_serverError != null) return _serverError; if (_error == null) return null; + _serverError = new ServerError(_error, _statusCode); return _serverError; } @@ -94,32 +124,22 @@ internal int? StatusCode } } - /// - public virtual bool IsValid => (this.ApiCall?.Success ?? false) && (this.ServerError == null); - - /// Returns useful information about the request(s) that were part of this API call. - public virtual IApiCallDetails ApiCall => _originalApiCall; - - - /// - public Exception OriginalException => this.ApiCall?.OriginalException; + [JsonIgnore] + IApiCallDetails IElasticsearchResponse.ApiCall + { + get => _originalApiCall; + set => _originalApiCall = value; + } - /// - public string DebugInformation + bool IElasticsearchResponse.TryGetServerErrorReason(out string reason) { - get - { - var sb = new StringBuilder(); - sb.Append($"{(!this.IsValid ? "Inv" : "V")}alid NEST response built from a "); - sb.AppendLine(this.ApiCall?.ToString().ToCamelCase() ?? "null ApiCall which is highly exceptional, please open a bug if you see this"); - if (!this.IsValid) this.DebugIsValid(sb); - if (this.ApiCall != null) ResponseStatics.DebugInformationBuilder(ApiCall, sb); - return sb.ToString(); - } + reason = ServerError?.Error?.ToString(); + return !reason.IsNullOrEmpty(); } + /// Subclasses can override this to provide more information on why a call is not valid. protected virtual void DebugIsValid(StringBuilder sb) { } - public override string ToString() => $"{(!this.IsValid ? "Inv" : "V")}alid NEST response built from a {this.ApiCall?.ToString().ToCamelCase()}"; + public override string ToString() => $"{(!IsValid ? "Inv" : "V")}alid NEST response built from a {ApiCall?.ToString().ToCamelCase()}"; } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/IgnoreAttribute.cs b/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/IgnoreAttribute.cs index 1c2059e0e69..24d2cb09215 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/IgnoreAttribute.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/IgnoreAttribute.cs @@ -4,4 +4,4 @@ namespace Nest { [AttributeUsage(AttributeTargets.Property)] public class IgnoreAttribute : Attribute { } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/PropertyNameAttribute.cs b/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/PropertyNameAttribute.cs index ef28549ee45..cf38fa2c110 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/PropertyNameAttribute.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/PropertyNameAttribute.cs @@ -5,7 +5,8 @@ namespace Nest [AttributeUsage(AttributeTargets.Property)] public class PropertyNameAttribute : Attribute { - public string Name { get; set; } public PropertyNameAttribute(string name) => Name = name; + + public string Name { get; set; } } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/StringTimeSpanAttribute.cs b/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/StringTimeSpanAttribute.cs index b3b6c9f6ac5..2ffcf994020 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/StringTimeSpanAttribute.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/Attributes/StringTimeSpanAttribute.cs @@ -4,4 +4,4 @@ namespace Nest { [AttributeUsage(AttributeTargets.Property)] public class StringTimeSpanAttribute : Attribute { } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/ContractJsonConverterAttribute.cs b/src/Nest/CommonAbstractions/SerializationBehavior/ContractJsonConverterAttribute.cs index 905158e50fe..4d5c98e28f9 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/ContractJsonConverterAttribute.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/ContractJsonConverterAttribute.cs @@ -3,29 +3,23 @@ namespace Nest { - internal class ContractJsonConverterAttribute : Attribute { - public JsonConverter Converter { get; } - public ContractJsonConverterAttribute(Type jsonConverter) { - if (typeof(JsonConverter).IsAssignableFrom(jsonConverter)) - { - Converter = jsonConverter.CreateInstance(); - } + if (typeof(JsonConverter).IsAssignableFrom(jsonConverter)) Converter = jsonConverter.CreateInstance(); } + + public JsonConverter Converter { get; } } + internal class ExactContractJsonConverterAttribute : Attribute { - public JsonConverter Converter { get; } - public ExactContractJsonConverterAttribute(Type jsonConverter) { - if (typeof(JsonConverter).IsAssignableFrom(jsonConverter)) - { - Converter = jsonConverter.CreateInstance(); - } + if (typeof(JsonConverter).IsAssignableFrom(jsonConverter)) Converter = jsonConverter.CreateInstance(); } + + public JsonConverter Converter { get; } } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/ElasticContractResolver.cs b/src/Nest/CommonAbstractions/SerializationBehavior/ElasticContractResolver.cs index 3e490d7d473..9d4c99e2b8b 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/ElasticContractResolver.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/ElasticContractResolver.cs @@ -13,15 +13,29 @@ namespace Nest { internal class ElasticContractResolver : DefaultContractResolver { + private static readonly Type _readAsType = typeof(ReadAsTypeJsonConverter<>); + private static readonly MachineLearningDateTimeConverter MachineLearningDateTimeConverter = new MachineLearningDateTimeConverter(); + + private static readonly StringEnumConverter StringEnumConverter = new StringEnumConverter(); + private static readonly Type[] StringSignalTypes = { typeof(KeywordAttribute), typeof(TextAttribute) }; + private static readonly StringTimeSpanConverter StringTimeSpanConverter = new StringTimeSpanConverter(); + + private static readonly Assembly ThisAssembly = typeof(ElasticContractResolver).Assembly(); private readonly Lazy _usingSourceSerializer; - public static JsonSerializer Empty { get; } = new JsonSerializer(); + public ElasticContractResolver(IConnectionSettingsValues connectionSettings) + { + ConnectionSettings = connectionSettings; + _usingSourceSerializer = new Lazy(() => connectionSettings.RequestResponseSerializer != connectionSettings.SourceSerializer); + } /// /// ConnectionSettings can be requested by JsonConverters. /// public IConnectionSettingsValues ConnectionSettings { get; } + public static JsonSerializer Empty { get; } = new JsonSerializer(); + public bool UsingSourceSerializer => _usingSourceSerializer.Value; /// @@ -29,60 +43,50 @@ internal class ElasticContractResolver : DefaultContractResolver /// internal JsonConverterPiggyBackState PiggyBackState { get; set; } - public ElasticContractResolver(IConnectionSettingsValues connectionSettings) - { - this.ConnectionSettings = connectionSettings; - _usingSourceSerializer = new Lazy(() => connectionSettings.RequestResponseSerializer != connectionSettings.SourceSerializer); - } - protected bool CanRemoveSourceConverter(JsonConverter converter) { if (UsingSourceSerializer || converter == null) return false; + return converter is SourceConverter; } - protected override JsonContract CreateContract(Type objectType) + protected override JsonContract CreateContract(Type objectType) => ConnectionSettings.Inferrer.Contracts.GetOrAdd(objectType, o => { - // cache contracts per connection settings - return this.ConnectionSettings.Inferrer.Contracts.GetOrAdd(objectType, o => - { - var contract = base.CreateContract(o); + var contract = base.CreateContract(o); - if (o == typeof(Error)) contract.Converter = new ErrorJsonConverter(); - else if (o == typeof(ErrorCause)) contract.Converter = new ErrorCauseJsonConverter(); - else if (CanRemoveSourceConverter(contract.Converter)) contract.Converter = null; //rely on defaults - else if (o.IsGeneric() && o.GetGenericTypeDefinition() == typeof(SuggestDictionary<>)) - contract.Converter = - (JsonConverter)typeof(SuggestDictionaryConverter<>).CreateGenericInstance(o.GetGenericArguments()); + if (o == typeof(Error)) contract.Converter = new ErrorJsonConverter(); + else if (o == typeof(ErrorCause)) contract.Converter = new ErrorCauseJsonConverter(); + else if (CanRemoveSourceConverter(contract.Converter)) contract.Converter = null; //rely on defaults + else if (o.IsGeneric() && o.GetGenericTypeDefinition() == typeof(SuggestDictionary<>)) + contract.Converter = + (JsonConverter)typeof(SuggestDictionaryConverter<>).CreateGenericInstance(o.GetGenericArguments()); - else if (contract.Converter == null && - (typeof(IDictionary).IsAssignableFrom(o) || o.IsGenericDictionary()) && !typeof(IIsADictionary).IsAssignableFrom(o)) - { - if (!o.TryGetGenericDictionaryArguments(out var genericArguments)) - contract.Converter = new VerbatimDictionaryKeysJsonConverter(); - else - contract.Converter = - (JsonConverter)typeof(VerbatimDictionaryKeysJsonConverter<,>).CreateGenericInstance(genericArguments); - } + else if (contract.Converter == null && + (typeof(IDictionary).IsAssignableFrom(o) || o.IsGenericDictionary()) && !typeof(IIsADictionary).IsAssignableFrom(o)) + { + if (!o.TryGetGenericDictionaryArguments(out var genericArguments)) + contract.Converter = new VerbatimDictionaryKeysJsonConverter(); + else + contract.Converter = + (JsonConverter)typeof(VerbatimDictionaryKeysJsonConverter<,>).CreateGenericInstance(genericArguments); + } - else if (o == typeof(DateTime) || o == typeof(DateTime?)) - contract.Converter = new IsoDateTimeConverter { Culture = CultureInfo.InvariantCulture }; - else if (o == typeof(TimeSpan) || o == typeof(TimeSpan?)) - contract.Converter = new TimeSpanToStringConverter(); - else if (typeof(IEnumerable).IsAssignableFrom(o)) - contract.Converter = new QueryContainerCollectionJsonConverter(); + else if (o == typeof(DateTime) || o == typeof(DateTime?)) + contract.Converter = new IsoDateTimeConverter { Culture = CultureInfo.InvariantCulture }; + else if (o == typeof(TimeSpan) || o == typeof(TimeSpan?)) + contract.Converter = new TimeSpanToStringConverter(); + else if (typeof(IEnumerable).IsAssignableFrom(o)) + contract.Converter = new QueryContainerCollectionJsonConverter(); - ApplyBuildInSerializersForType(o, contract); + ApplyBuildInSerializersForType(o, contract); - if (!o.FullName.StartsWith("Nest.", StringComparison.OrdinalIgnoreCase)) return contract; - if (ApplyExactContractJsonAttribute(o, contract)) return contract; - if (ApplyContractJsonAttribute(o, contract)) return contract; + if (!o.FullName.StartsWith("Nest.", StringComparison.OrdinalIgnoreCase)) return contract; + if (ApplyExactContractJsonAttribute(o, contract)) return contract; + if (ApplyContractJsonAttribute(o, contract)) return contract; - return contract; - }); - } + return contract; + }); - private static Type _readAsType = typeof(ReadAsTypeJsonConverter<>); protected override JsonConverter ResolveContractConverter(Type objectType) { var info = objectType.GetTypeInfo(); @@ -93,20 +97,22 @@ protected override JsonConverter ResolveContractConverter(Type objectType) var readAsType = attribute.Type; var readAsTypeInfo = readAsType.GetTypeInfo(); if (!readAsTypeInfo.IsGenericType || !readAsTypeInfo.IsGenericTypeDefinition) - return (JsonConverter) _readAsType.CreateGenericInstance(objectType); + return (JsonConverter)_readAsType.CreateGenericInstance(objectType); var targetType = objectType; if (info.IsGenericType) targetType = targetType.GetGenericArguments().First(); var concreteType = readAsType.MakeGenericType(targetType); - return (JsonConverter) _readAsType.CreateGenericInstance(concreteType); - + return (JsonConverter)_readAsType.CreateGenericInstance(concreteType); } private static bool ApplyExactContractJsonAttribute(Type objectType, JsonContract contract) { - var attribute = (ExactContractJsonConverterAttribute)objectType.GetTypeInfo().GetCustomAttributes(typeof(ExactContractJsonConverterAttribute)).FirstOrDefault(); + var attribute = (ExactContractJsonConverterAttribute)objectType.GetTypeInfo() + .GetCustomAttributes(typeof(ExactContractJsonConverterAttribute)) + .FirstOrDefault(); if (attribute?.Converter == null) return false; + contract.Converter = attribute.Converter; return true; } @@ -115,8 +121,12 @@ private static bool ApplyContractJsonAttribute(Type objectType, JsonContract con { foreach (var t in TypeWithInterfaces(objectType)) { - var attribute = (ContractJsonConverterAttribute)t.GetTypeInfo().GetCustomAttributes(typeof(ContractJsonConverterAttribute), true).FirstOrDefault(); + var attribute = + (ContractJsonConverterAttribute)t.GetTypeInfo() + .GetCustomAttributes(typeof(ContractJsonConverterAttribute), true) + .FirstOrDefault(); if (attribute?.Converter == null) continue; + contract.Converter = attribute.Converter; return true; } @@ -126,11 +136,10 @@ private static bool ApplyContractJsonAttribute(Type objectType, JsonContract con private static IEnumerable TypeWithInterfaces(Type objectType) { yield return objectType; + foreach (var i in objectType.GetInterfaces()) yield return i; } - private static readonly Assembly ThisAssembly = typeof(ElasticContractResolver).Assembly(); - protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); @@ -165,41 +174,32 @@ protected override IList CreateProperties(Type type, MemberSeriali return base.CreateProperties(type, memberSerialization); } - public IList PropertiesOfAllInterfaces(Type t, MemberSerialization memberSerialization) - { - return ( + public IList PropertiesOfAllInterfaces(Type t, MemberSerialization memberSerialization) => ( from i in t.GetInterfaces() select base.CreateProperties(i, memberSerialization) - ) - .SelectMany(interfaceProps => interfaceProps) - .DistinctBy(p => p.PropertyName) - .ToList(); - } + ) + .SelectMany(interfaceProps => interfaceProps) + .DistinctBy(p => p.PropertyName) + .ToList(); public IList PropertiesOfInterface(Type t, MemberSerialization memberSerialization) - where TInterface : class - { - return ( + where TInterface : class => ( from i in t.GetInterfaces().Where(i => typeof(TInterface).IsAssignableFrom(i)) select base.CreateProperties(i, memberSerialization) - ) - .SelectMany(interfaceProps => interfaceProps) - .DistinctBy(p => p.PropertyName) - .ToList(); - } + ) + .SelectMany(interfaceProps => interfaceProps) + .DistinctBy(p => p.PropertyName) + .ToList(); - public IList PropertiesOfAll(Type t, MemberSerialization memberSerialization) - { - return base.CreateProperties(t, memberSerialization) - .Concat(PropertiesOfAllInterfaces(t, memberSerialization)) - .DistinctBy(p => p.PropertyName) - .ToList(); - } + public IList PropertiesOfAll(Type t, MemberSerialization memberSerialization) => base.CreateProperties(t, memberSerialization) + .Concat(PropertiesOfAllInterfaces(t, memberSerialization)) + .DistinctBy(p => p.PropertyName) + .ToList(); protected override string ResolvePropertyName(string fieldName) { - if (this.ConnectionSettings.DefaultFieldNameInferrer != null) - return this.ConnectionSettings.DefaultFieldNameInferrer(fieldName); + if (ConnectionSettings.DefaultFieldNameInferrer != null) + return ConnectionSettings.DefaultFieldNameInferrer(fieldName); return fieldName.ToCamelCase(); } @@ -208,42 +208,43 @@ protected static bool ShouldSerializeQueryContainer(object o, JsonProperty prop) { if (o == null) return false; if (!(prop.ValueProvider.GetValue(o) is QueryContainer q)) return false; + return q.IsWritable; } protected static bool ShouldSerializeQueryContainers(object o, JsonProperty prop) { if (o == null) return false; + var q = prop.ValueProvider.GetValue(o) as IEnumerable; - return (q.AsInstanceOrToListOrNull()?.Any(qq=>qq != null && qq.IsWritable)).GetValueOrDefault(false); + return (q.AsInstanceOrToListOrNull()?.Any(qq => qq != null && qq.IsWritable)).GetValueOrDefault(false); } + protected bool ShouldSerializeRouting(object o, JsonProperty prop) { if (o == null) return false; + var q = prop.ValueProvider.GetValue(o) as Routing; if (q == null) return false; + //not ideal to resolve twice but for now the only way not to send routing: null - var resolved = this.ConnectionSettings.Inferrer.Resolve(q); + var resolved = ConnectionSettings.Inferrer.Resolve(q); return !resolved.IsNullOrEmpty(); } - private static readonly StringEnumConverter StringEnumConverter = new StringEnumConverter(); - private static readonly StringTimeSpanConverter StringTimeSpanConverter = new StringTimeSpanConverter(); - private static readonly MachineLearningDateTimeConverter MachineLearningDateTimeConverter = new MachineLearningDateTimeConverter(); - private static readonly Type[] StringSignalTypes = {typeof(KeywordAttribute), typeof(TextAttribute)}; private static void ApplyBuildInSerializers(MemberInfo member, JsonProperty property) { var attributes = member.GetCustomAttributes().ToList(); var stringy = attributes.Any(a => StringSignalTypes.Contains(a.GetType())); - if (attributes.OfType().Any() || (property.PropertyType.IsEnumType() && stringy)) + if (attributes.OfType().Any() || property.PropertyType.IsEnumType() && stringy) property.Converter = StringEnumConverter; if ((property.PropertyType == typeof(TimeSpan) || property.PropertyType == typeof(TimeSpan?)) - && (attributes.OfType().Any() || stringy)) + && (attributes.OfType().Any() || stringy)) property.Converter = StringTimeSpanConverter; if ((property.PropertyType == typeof(DateTime) || property.PropertyType == typeof(DateTime?)) - && (attributes.OfType().Any())) + && attributes.OfType().Any()) property.Converter = MachineLearningDateTimeConverter; } @@ -256,10 +257,10 @@ private static void ApplyBuildInSerializersForType(Type type, JsonContract contr /// Renames/Ignores a property based on the connection settings mapping or custom attributes for the property private void ApplyPropertyOverrides(MemberInfo member, JsonProperty property) { - if (!this.ConnectionSettings.PropertyMappings.TryGetValue(member, out var propertyMapping)) + if (!ConnectionSettings.PropertyMappings.TryGetValue(member, out var propertyMapping)) propertyMapping = ElasticsearchPropertyAttributeBase.From(member); - var serializerMapping = this.ConnectionSettings.PropertyMappingProvider?.CreatePropertyMapping(member); + var serializerMapping = ConnectionSettings.PropertyMappingProvider?.CreatePropertyMapping(member); var nameOverride = propertyMapping?.Name ?? serializerMapping?.Name; if (!nameOverride.IsNullOrEmpty()) property.PropertyName = nameOverride; @@ -280,20 +281,21 @@ private void ApplyShouldSerializer(JsonProperty property) // Skip serialization of empty collections that have DefaultValueHandling set to Ignore. else if (property.DefaultValueHandling.HasValue - && property.DefaultValueHandling.Value == DefaultValueHandling.Ignore - && !typeof(string).IsAssignableFrom(property.PropertyType) - && typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) + && property.DefaultValueHandling.Value == DefaultValueHandling.Ignore + && !typeof(string).IsAssignableFrom(property.PropertyType) + && typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { bool ShouldSerialize(object obj) { if (!(property.ValueProvider.GetValue(obj) is ICollection collection)) return true; + return collection.Count != 0 && collection.Cast().Any(item => item != null); } property.ShouldSerialize = property.ShouldSerialize == null - ? (Predicate) ShouldSerialize - : (o => property.ShouldSerialize(o) && ShouldSerialize(o)); + ? (Predicate)ShouldSerialize + : o => property.ShouldSerialize(o) && ShouldSerialize(o); } } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/CompositeJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/CompositeJsonConverter.cs index 51da6df74d0..179c728f081 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/CompositeJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/CompositeJsonConverter.cs @@ -7,31 +7,22 @@ internal class CompositeJsonConverter : JsonConverter where TRead : JsonConverter, new() where TWrite : JsonConverter, new() { - private TRead Read { get; set; } - private TWrite Write { get; set; } - - public override bool CanRead => true; - public override bool CanWrite => true; - public CompositeJsonConverter() { - this.Read = new TRead(); - this.Write = new TWrite(); + Read = new TRead(); + Write = new TWrite(); } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - this.Write.WriteJson(writer, value, serializer); - } + public override bool CanRead => true; + public override bool CanWrite => true; + private TRead Read { get; set; } + private TWrite Write { get; set; } - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return this.Read.ReadJson(reader, objectType, existingValue, serializer); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => Write.WriteJson(writer, value, serializer); - public override bool CanConvert(Type objectType) - { - return true; - } + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => + Read.ReadJson(reader, objectType, existingValue, serializer); + + public override bool CanConvert(Type objectType) => true; } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/EnumMemberValueCasingJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/EnumMemberValueCasingJsonConverter.cs index 58268ab53b0..2d19d4edd22 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/EnumMemberValueCasingJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/EnumMemberValueCasingJsonConverter.cs @@ -5,13 +5,14 @@ using Newtonsoft.Json; #if DOTNETCORE using System.Reflection; + #endif namespace Nest { /// /// A Json converter that can serialize enums to strings where the string values - /// are specified using and where values + /// are specified using and where values /// differ in casing. /// /// @@ -81,9 +82,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist return Enum.TryParse(value, true, out enumValue) ? enumValue : default(TEnum); } - public override bool CanConvert(Type objectType) - { - return objectType == typeof(TEnum); - } + public override bool CanConvert(Type objectType) => objectType == typeof(TEnum); } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ErrorCauseJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ErrorCauseJsonConverter.cs index a3c25abae51..27def9ffedf 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ErrorCauseJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ErrorCauseJsonConverter.cs @@ -14,6 +14,7 @@ internal class ErrorCauseJsonConverter : JsonConverter { public override bool CanRead => true; public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => objectType == typeof(Error); public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { } @@ -21,7 +22,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => ReadError(reader, serializer, (e, prop) => { - if (!this.ReadProperty(e, prop, reader, serializer)) + if (!ReadProperty(e, prop, reader, serializer)) reader.Skip(); }); @@ -35,7 +36,7 @@ private TInnerError ReadError(JsonReader reader, JsonSerializer ser { if (reader.TokenType == JsonToken.String) { - var reason = (string) reader.Value; + var reason = (string)reader.Value; return new TInnerError { Reason = reason }; } if (reader.TokenType != JsonToken.StartObject) @@ -49,7 +50,7 @@ private TInnerError ReadError(JsonReader reader, JsonSerializer ser reader.Read(); do { - var propertyName = (string) reader.Value; + var propertyName = (string)reader.Value; switch (propertyName) { case "type": @@ -139,6 +140,7 @@ protected static IReadOnlyCollection ExtractFailedShards(JsonReade { reader.Read(); if (reader.TokenType != JsonToken.StartArray) return EmptyReadOnly.Collection; + var shardFailures = serializer.Deserialize>(reader); return new ReadOnlyCollection(shardFailures); } @@ -148,7 +150,7 @@ private static IReadOnlyCollection ReadArray(JsonReader reader) var a = new string[0] { }; reader.Read(); if (reader.TokenType == JsonToken.String) - a = new[] {(reader.Value as string)}; + a = new[] { reader.Value as string }; else if (reader.TokenType == JsonToken.StartArray) a = JArray.Load(reader).ToObject>().ToArray(); return new ReadOnlyCollection(a); diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ErrorJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ErrorJsonConverter.cs index a9c7fcce0ea..3473bc8c7a7 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ErrorJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ErrorJsonConverter.cs @@ -23,8 +23,10 @@ private static bool ExtractHeaders(Error error, JsonReader reader, JsonSerialize reader.Read(); if (reader.TokenType != JsonToken.StartObject) return false; + var dict = serializer.Deserialize>(reader); if (dict == null) return false; + error.Headers = new ReadOnlyDictionary(dict); return true; } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/FromJson.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/FromJson.cs index 14d14a5688a..b26dadc0853 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/FromJson.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/FromJson.cs @@ -16,7 +16,8 @@ public static T ReadAs(JsonReader reader, JsonSerializer serializer) } /// - /// Read the json as an instance of + /// Read the json as an instance of + /// /// public static object Read(JsonReader reader, Type objectType, JsonSerializer serializer) { @@ -24,6 +25,5 @@ public static object Read(JsonReader reader, Type objectType, JsonSerializer ser serializer.Populate(reader, t); return t; } - } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/GenericProxyRequestConverterBase.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/GenericProxyRequestConverterBase.cs index e4c974b7d0e..9899465bb3e 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/GenericProxyRequestConverterBase.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/GenericProxyRequestConverterBase.cs @@ -3,7 +3,6 @@ using System.Reflection; using System.Text; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using static Elasticsearch.Net.SerializationFormatting; namespace Nest @@ -17,6 +16,7 @@ protected GenericProxyRequestConverterBase(Type genericRequestType) => public override bool CanRead => true; public override bool CanWrite => true; + public override bool CanConvert(Type objectType) => true; public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) @@ -24,13 +24,13 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var token = reader.ReadTokenWithDateParseHandlingNone(); using (var ms = token.ToStream(serializer.GetConnectionSettings().MemoryStreamFactory)) { - //not optimized but deserializing create requests is far from common practice - var genericType = objectType.GetTypeInfo().GenericTypeArguments[0]; + //not optimized but deserializing create requests is far from common practice + var genericType = objectType.GetTypeInfo().GenericTypeArguments[0]; var o = serializer.GetConnectionSettings().SourceSerializer.Deserialize(genericType, ms); var path = typeof(DocumentPath<>).CreateGenericInstance(genericType, o); - // index, type and id are optional parameters on _genericRequestType but need to be passed to construct through reflection - var x = _genericRequestType.CreateGenericInstance(genericType, path, null, null, null); - return x; + // index, type and id are optional parameters on _genericRequestType but need to be passed to construct through reflection + var x = _genericRequestType.CreateGenericInstance(genericType, path, null, null, null); + return x; } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/IndicesBoostJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/IndicesBoostJsonConverter.cs index 6f0c6fb3011..e4e5199b605 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/IndicesBoostJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/IndicesBoostJsonConverter.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Newtonsoft.Json; namespace Nest @@ -18,7 +17,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s var settings = serializer.GetConnectionSettings(); writer.WriteStartArray(); - foreach(var entry in dictionary) + foreach (var entry in dictionary) { writer.WriteStartObject(); var indexName = settings.Inferrer.IndexName(entry.Key); diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/JsonConverterBase.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/JsonConverterBase.cs index 304e84d59be..937125e5c1f 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/JsonConverterBase.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/JsonConverterBase.cs @@ -5,14 +5,16 @@ namespace Nest { internal abstract class JsonConverterBase : JsonConverter where T : class { - public override bool CanConvert(Type objectType) => true; - public override bool CanWrite => true; public override bool CanRead => true; + public override bool CanWrite => true; + + public override bool CanConvert(Type objectType) => true; public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (!(value is T v)) return; - this.WriteJson(writer, v, serializer); + + WriteJson(writer, v, serializer); } public abstract void WriteJson(JsonWriter writer, T value, JsonSerializer serializer); diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/KeyValueJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/KeyValueJsonConverter.cs index addb0aa99a2..0ac1b39cd3e 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/KeyValueJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/KeyValueJsonConverter.cs @@ -6,11 +6,13 @@ namespace Nest { - internal class KeyValueConversion { private static readonly ConcurrentDictionary KnownTypes = new ConcurrentDictionary(); + public JsonProperty KeyProperty { get; set; } + public JsonProperty ValueProperty { get; set; } + public static KeyValueConversion Create() where TContainer : class, new() { var t = typeof(TContainer); @@ -22,23 +24,21 @@ internal class KeyValueConversion var valueProp = properties.FirstOrDefault(p => p.PropertyType == typeof(TValue)); if (keyProp == null) throw new Exception($"No key property found on type {t.Name}"); if (valueProp == null) throw new Exception($"No value property found on type {t.Name}"); - conversion = new KeyValueConversion { KeyProperty = keyProp, ValueProperty = valueProp}; + + conversion = new KeyValueConversion { KeyProperty = keyProp, ValueProperty = valueProp }; KnownTypes.TryAdd(t, conversion); return conversion; } - - public JsonProperty KeyProperty { get; set; } - public JsonProperty ValueProperty { get; set; } } internal class KeyValueJsonConverter : JsonConverter where TContainer : class, new() { - - public override bool CanConvert(Type objectType) => true; public override bool CanRead => true; public override bool CanWrite => true; + public override bool CanConvert(Type objectType) => true; + public override void WriteJson(JsonWriter writer, object v, JsonSerializer serializer) { var conversion = KeyValueConversion.Create(); @@ -46,7 +46,8 @@ public override void WriteJson(JsonWriter writer, object v, JsonSerializer seria { writer.WriteNull(); return; - }; + } + ; var key = conversion.KeyProperty.ValueProvider.GetValue(v).ToString(); var value = conversion.ValueProperty.ValueProvider.GetValue(v); @@ -54,7 +55,8 @@ public override void WriteJson(JsonWriter writer, object v, JsonSerializer seria { writer.WriteNull(); return; - }; + } + ; writer.WriteStartObject(); writer.WritePropertyName(key); @@ -66,6 +68,7 @@ public override void WriteJson(JsonWriter writer, object v, JsonSerializer seria public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) return null; + var depth = reader.Depth; reader.Read(); //property name @@ -76,9 +79,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist if (reader.Depth > depth) { do - { reader.Read(); - } while (reader.Depth >= depth && reader.TokenType != JsonToken.EndObject); + while (reader.Depth >= depth && reader.TokenType != JsonToken.EndObject); } var conversion = KeyValueConversion.Create(); @@ -89,6 +91,5 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist conversion.ValueProperty.ValueProvider.SetValue(o, value); return o; } - } -} \ No newline at end of file +} diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadAsTypeJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadAsTypeJsonConverter.cs index 240036c83e2..77c4d9d0f49 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadAsTypeJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadAsTypeJsonConverter.cs @@ -19,11 +19,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist internal class ReadAsAttribute : Attribute { - public Type Type { get; } + public ReadAsAttribute(Type readAs) => Type = readAs; - public ReadAsAttribute(Type readAs) - { - this.Type = readAs; - } + public Type Type { get; } } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadOnlyCollectionJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadOnlyCollectionJsonConverter.cs index cec6bc92bb4..724a1aeacf4 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadOnlyCollectionJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadOnlyCollectionJsonConverter.cs @@ -6,12 +6,12 @@ namespace Nest { /// - /// Json converter that deserializes into an or - /// where does not have a custom deserializer and should be deserialized - /// into concrete types of + /// Json converter that deserializes into an or + /// where does not have a custom deserializer and should be deserialized + /// into concrete types of /// /// - /// may not have a deserializer for valid reasons, for example, an interface may be implemented by two + /// may not have a deserializer for valid reasons, for example, an interface may be implemented by two /// concrete types that need to be deserialized. In this case, a deserializer would not know which concrete type to deserialize to in /// a given context. /// @@ -21,13 +21,10 @@ internal class ReadOnlyCollectionJsonConverter : JsonConv where TDocument : TInterface where TInterface : class { - public override bool CanWrite => false; public override bool CanRead => true; + public override bool CanWrite => false; - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotSupportedException(); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadSingleOrEnumerableJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadSingleOrEnumerableJsonConverter.cs index ed414f96137..3ce69043b10 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadSingleOrEnumerableJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReadSingleOrEnumerableJsonConverter.cs @@ -5,16 +5,14 @@ namespace Nest { internal class ReadSingleOrEnumerableJsonConverter : JsonConverter { + public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => true; - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return reader.TokenType == JsonToken.StartArray + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => + reader.TokenType == JsonToken.StartArray ? serializer.Deserialize(reader) : new[] { serializer.Deserialize(reader) }; - } - - public override bool CanWrite => false; public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotSupportedException(); diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReserializeJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReserializeJsonConverter.cs index 12f0233a1f6..6bee77714c3 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReserializeJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/ReserializeJsonConverter.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using Newtonsoft.Json; namespace Nest @@ -8,54 +7,54 @@ internal class ReserializeJsonConverter : JsonConverter where TReadAs : class, TInterface where TInterface : class { - protected ReadAsTypeJsonConverter Reader { get; } = new ReadAsTypeJsonConverter(); - public override bool CanRead => true; public override bool CanWrite => true; + protected ReadAsTypeJsonConverter Reader { get; } = new ReadAsTypeJsonConverter(); public override bool CanConvert(Type objectType) => typeof(TInterface).IsAssignableFrom(objectType); public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) return null; + var depth = reader.Depth; - var deserialized = this.DeserializeJson(reader, objectType, existingValue, serializer); + var deserialized = DeserializeJson(reader, objectType, existingValue, serializer); return reader.ReadToEnd(depth, deserialized); } - protected TReadAs ReadAs(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return this.Reader.ReadJson(reader, objectType, existingValue, serializer) as TReadAs; - } + protected TReadAs ReadAs(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => + Reader.ReadJson(reader, objectType, existingValue, serializer) as TReadAs; protected virtual object DeserializeJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => - this.ReadAs(reader, objectType, existingValue, serializer); + ReadAs(reader, objectType, existingValue, serializer); public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (!(value is TInterface v)) return; - this.SerializeJson(writer, value, v, serializer); - } - protected virtual void SerializeJson(JsonWriter writer, object value, TInterface castValue, JsonSerializer serializer) - { - this.Reserialize(writer, value, serializer); + SerializeJson(writer, value, v, serializer); } + protected virtual void SerializeJson(JsonWriter writer, object value, TInterface castValue, JsonSerializer serializer) => + Reserialize(writer, value, serializer); + protected virtual bool SkipWriteProperty(string propertyName) => false; protected void Reserialize(JsonWriter writer, object value, JsonSerializer serializer, Action inlineWriter = null) { var properties = value.GetType().GetCachedObjectProperties(); if (properties.Count == 0) return; + writer.WriteStartObject(); inlineWriter?.Invoke(writer); foreach (var p in properties) { if (p.Ignored || SkipWriteProperty(p.PropertyName)) continue; + var vv = p.ValueProvider.GetValue(value); if (vv == null) continue; + writer.WritePropertyName(p.PropertyName); if (p.Converter?.GetType() == typeof(SourceValueWriteConverter)) SourceValueWriteConverter.Write(writer, vv, serializer); diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/TimeSpanToStringConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/TimeSpanToStringConverter.cs index a66c2d2d871..21265fde70c 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/TimeSpanToStringConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/TimeSpanToStringConverter.cs @@ -11,7 +11,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s writer.WriteNull(); else { - var timeSpan = (TimeSpan) value; + var timeSpan = (TimeSpan)value; writer.WriteValue(timeSpan.Ticks); } } @@ -21,12 +21,12 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist switch (reader.TokenType) { case JsonToken.Null: return null; - case JsonToken.String: return TimeSpan.Parse((string) reader.Value); - case JsonToken.Integer: return new TimeSpan((long) reader.Value); + case JsonToken.String: return TimeSpan.Parse((string)reader.Value); + case JsonToken.Integer: return new TimeSpan((long)reader.Value); } throw new JsonSerializationException($"Cannot convert token of type {reader.TokenType} to {objectType}."); } - public override bool CanConvert(Type objectType) => objectType == typeof (TimeSpan) || objectType == typeof (TimeSpan?); + public override bool CanConvert(Type objectType) => objectType == typeof(TimeSpan) || objectType == typeof(TimeSpan?); } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/VerbatimDictionaryKeysConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/VerbatimDictionaryKeysConverter.cs index d8c207d81f5..1855783b398 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/VerbatimDictionaryKeysConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/VerbatimDictionaryKeysConverter.cs @@ -1,8 +1,8 @@ using System; -using System.Linq; using System.Collections; using System.Collections.Generic; using System.Globalization; +using System.Linq; using Newtonsoft.Json; namespace Nest @@ -13,14 +13,12 @@ namespace Nest /// internal class VerbatimDictionaryKeysJsonConverter : JsonConverter { - public override bool CanConvert(Type t) => typeof(IDictionary).IsAssignableFrom(t); - public override bool CanRead => false; - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { + public override bool CanConvert(Type t) => typeof(IDictionary).IsAssignableFrom(t); + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => throw new NotSupportedException(); - } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { @@ -38,37 +36,30 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s { if (entry.Value == null && serializer.NullValueHandling == NullValueHandling.Ignore) continue; + string key; if (settings == null) key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture); else { if (AsType(entry.Key, out Field fieldName)) - { key = settings.Inferrer.Field(fieldName); - } else { if (AsType(entry.Key, out PropertyName propertyName)) { - if (propertyName?.Property != null && - (settings.PropertyMappings.TryGetValue(propertyName.Property, out var mapping) && mapping.Ignore)) + if (propertyName?.Property != null && settings.PropertyMappings.TryGetValue(propertyName.Property, out var mapping) + && mapping.Ignore) continue; key = settings.Inferrer.PropertyName(propertyName); } else if (AsType(entry.Key, out IndexName indexName)) - { key = settings.Inferrer.IndexName(indexName); - } else if (AsType(entry.Key, out TypeName typeName)) - { key = settings.Inferrer.TypeName(typeName); - } else if (AsType(entry.Key, out RelationName relationName)) - { key = settings.Inferrer.RelationName(relationName); - } else key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture); } @@ -101,19 +92,19 @@ private static bool AsType(object value, out T convertedValue) where T : clas /// internal class VerbatimDictionaryKeysJsonConverter : JsonConverter { - private readonly bool _keyIsString = typeof(TKey) == typeof(string); private readonly bool _keyIsField = typeof(TKey) == typeof(Field); - private readonly bool _keyIsPropertyName = typeof(TKey) == typeof(PropertyName); private readonly bool _keyIsIndexName = typeof(TKey) == typeof(IndexName); - private readonly bool _keyIsTypeName = typeof(TKey) == typeof(TypeName); + private readonly bool _keyIsPropertyName = typeof(TKey) == typeof(PropertyName); private readonly bool _keyIsRelationName = typeof(TKey) == typeof(RelationName); + private readonly bool _keyIsString = typeof(TKey) == typeof(string); + private readonly bool _keyIsTypeName = typeof(TKey) == typeof(TypeName); + + public override bool CanRead => false; public override bool CanConvert(Type t) => typeof(IDictionary).IsAssignableFrom(t) || typeof(IReadOnlyDictionary).IsAssignableFrom(t); - public override bool CanRead => false; - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) => throw new NotSupportedException(); @@ -133,6 +124,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s { if (SkipValue(serializer, entry)) continue; + string key; if (_keyIsString) key = entry.Key?.ToString(); @@ -146,8 +138,8 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s else if (_keyIsPropertyName) { var propertyName = entry.Key as PropertyName; - if (propertyName?.Property != null && - (settings.PropertyMappings.TryGetValue(propertyName.Property, out var mapping) && mapping.Ignore)) + if (propertyName?.Property != null && settings.PropertyMappings.TryGetValue(propertyName.Property, out var mapping) + && mapping.Ignore) continue; key = settings.Inferrer.PropertyName(propertyName); @@ -175,7 +167,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s } writer.WriteStartObject(); - foreach(var entry in seenEntries) + foreach (var entry in seenEntries) { writer.WritePropertyName(entry.Key); serializer.Serialize(writer, entry.Value); @@ -183,19 +175,17 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s writer.WriteEndObject(); } - protected virtual bool SkipValue(JsonSerializer serializer, KeyValuePair entry) - { - return entry.Value == null && serializer.NullValueHandling == NullValueHandling.Ignore; - } + protected virtual bool SkipValue(JsonSerializer serializer, KeyValuePair entry) => + entry.Value == null && serializer.NullValueHandling == NullValueHandling.Ignore; } internal class VerbatimDictionaryKeysJsonConverter : VerbatimDictionaryKeysJsonConverter where TIsADictionary : IIsADictionary { - public override bool CanConvert(Type t) => true; - public override bool CanRead => true; + public override bool CanConvert(Type t) => true; + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var dictionary = serializer.Deserialize>(reader); diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/InternalSerializer.cs b/src/Nest/CommonAbstractions/SerializationBehavior/InternalSerializer.cs index ae7c5551ab8..7f28a6a9d06 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/InternalSerializer.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/InternalSerializer.cs @@ -11,20 +11,28 @@ namespace Nest /// The built in internal serializer that the high level client NEST uses. internal class InternalSerializer : IElasticsearchSerializer { - // Default buffer size of StreamWriter, which is private :( internal const int DefaultBufferSize = 1024; - + private static readonly Task CompletedTask = Task.CompletedTask; internal static readonly Encoding ExpectedEncoding = new UTF8Encoding(false); + private readonly JsonSerializer _indentedSerializer; - private static readonly Task CompletedTask = Task.CompletedTask; + public InternalSerializer(IConnectionSettingsValues settings) : this(settings, null) { } - private readonly JsonSerializer _indentedSerializer; - internal JsonSerializer Serializer { get; } + /// + /// this constructor is only here for stateful (de)serialization + /// + protected internal InternalSerializer(IConnectionSettingsValues settings, JsonConverter statefulConverter) + { + Settings = settings; + var piggyBackState = statefulConverter == null ? null : new JsonConverterPiggyBackState { ActualJsonConverter = statefulConverter }; + ContractResolver = new ElasticContractResolver(Settings) { PiggyBackState = piggyBackState }; - protected IConnectionSettingsValues Settings { get; } + var collapsed = CreateSettings(SerializationFormatting.None); + var indented = CreateSettings(SerializationFormatting.Indented); - /// Resolves JsonContracts for types - private ElasticContractResolver ContractResolver { get; } + Serializer = JsonSerializer.Create(collapsed); + _indentedSerializer = JsonSerializer.Create(indented); + } /// /// The size of the buffer to use when writing the serialized request @@ -34,22 +42,28 @@ internal class InternalSerializer : IElasticsearchSerializer // to be a good compromise buffer size for performance throughput and bytes allocated. protected virtual int BufferSize => DefaultBufferSize; - public InternalSerializer(IConnectionSettingsValues settings) : this(settings, null) { } + protected IConnectionSettingsValues Settings { get; } + internal JsonSerializer Serializer { get; } - /// - /// this constructor is only here for stateful (de)serialization - /// - protected internal InternalSerializer(IConnectionSettingsValues settings, JsonConverter statefulConverter) + /// Resolves JsonContracts for types + private ElasticContractResolver ContractResolver { get; } + + public T Deserialize(Stream stream) { - this.Settings = settings; - var piggyBackState = statefulConverter == null ? null : new JsonConverterPiggyBackState { ActualJsonConverter = statefulConverter }; - this.ContractResolver = new ElasticContractResolver(this.Settings) { PiggyBackState = piggyBackState }; + if (stream == null || stream.CanSeek && stream.Length == 0) return default(T); - var collapsed = this.CreateSettings(SerializationFormatting.None); - var indented = this.CreateSettings(SerializationFormatting.Indented); + using (var streamReader = new StreamReader(stream)) + using (var jsonTextReader = new JsonTextReader(streamReader)) + return Serializer.Deserialize(jsonTextReader); + } - this.Serializer = JsonSerializer.Create(collapsed); - this._indentedSerializer = JsonSerializer.Create(indented); + public object Deserialize(Type type, Stream stream) + { + if (stream == null || stream.CanSeek && stream.Length == 0) return type.DefaultValue(); + + using (var streamReader = new StreamReader(stream)) + using (var jsonTextReader = new JsonTextReader(streamReader)) + return Serializer.Deserialize(jsonTextReader, type); } public virtual void Serialize(T data, Stream writableStream, SerializationFormatting formatting = SerializationFormatting.Indented) @@ -61,7 +75,7 @@ public virtual void Serialize(T data, Stream writableStream, SerializationFor //this leaveOpen is most likely here because in PostData when we serialize IEnumerable as multi json //we call this multiple times, it would be better to have a dedicated Serialize(IEnumerable) on the //IElasticsearchSerializer interface more explicitly - using (var writer = new StreamWriter(writableStream, ExpectedEncoding, BufferSize, leaveOpen: true)) + using (var writer = new StreamWriter(writableStream, ExpectedEncoding, BufferSize, true)) using (var jsonWriter = new JsonTextWriter(writer)) { serializer.Serialize(jsonWriter, data); @@ -71,42 +85,28 @@ public virtual void Serialize(T data, Stream writableStream, SerializationFor } public Task SerializeAsync(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.Indented, - CancellationToken cancellationToken = default(CancellationToken)) + CancellationToken cancellationToken = default(CancellationToken) + ) { //This makes no sense now but we need the async method on the interface in 6.x so we can start swapping this out //for an implementation that does make sense without having to wait for 7.x - this.Serialize(data, stream, formatting); + Serialize(data, stream, formatting); return CompletedTask; } - public T Deserialize(JsonReader reader) => this.Serializer.Deserialize(reader); - - public object Deserialize(JsonReader reader, Type objectType) => this.Serializer.Deserialize(reader, objectType); - - public T Deserialize(Stream stream) - { - if (stream == null || stream.CanSeek && stream.Length == 0) return default(T); - using (var streamReader = new StreamReader(stream)) - using (var jsonTextReader = new JsonTextReader(streamReader)) - return this.Serializer.Deserialize(jsonTextReader); - } - - public object Deserialize(Type type, Stream stream) - { - if (stream == null || stream.CanSeek && stream.Length == 0) return type.DefaultValue(); - using (var streamReader = new StreamReader(stream)) - using (var jsonTextReader = new JsonTextReader(streamReader)) - return this.Serializer.Deserialize(jsonTextReader, type); - } + public T Deserialize(JsonReader reader) => Serializer.Deserialize(reader); + public object Deserialize(JsonReader reader, Type objectType) => Serializer.Deserialize(reader, objectType); + // Default buffer size of StreamWriter, which is private :( #pragma warning disable 1998 // we know this is not an async operation public async Task DeserializeAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken)) #pragma warning restore 1998 { if (stream == null || stream.CanSeek && stream.Length == 0) return default(T); - using (var sr = new StreamReader(stream)) - using (var jtr = new JsonTextReader(sr)) - return this.Serializer.Deserialize(jtr); + + using (var sr = new StreamReader(stream)) + using (var jtr = new JsonTextReader(sr)) + return Serializer.Deserialize(jtr); } #pragma warning disable 1998 // we know this is not an async operation @@ -114,9 +114,10 @@ public object Deserialize(Type type, Stream stream) #pragma warning restore 1998 { if (stream == null || stream.CanSeek && stream.Length == 0) return type.DefaultValue(); - using (var sr = new StreamReader(stream)) - using (var jtr = new JsonTextReader(sr)) - return this.Serializer.Deserialize(jtr, type); + + using (var sr = new StreamReader(stream)) + using (var jtr = new JsonTextReader(sr)) + return Serializer.Deserialize(jtr, type); } private JsonSerializerSettings CreateSettings(SerializationFormatting formatting) @@ -124,7 +125,7 @@ private JsonSerializerSettings CreateSettings(SerializationFormatting formatting var settings = new JsonSerializerSettings { Formatting = formatting == SerializationFormatting.Indented ? Formatting.Indented : Formatting.None, - ContractResolver = this.ContractResolver, + ContractResolver = ContractResolver, DefaultValueHandling = DefaultValueHandling.Include, NullValueHandling = NullValueHandling.Ignore }; diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/JTokenExtensions.cs b/src/Nest/CommonAbstractions/SerializationBehavior/JTokenExtensions.cs index 0e993ec17fc..7ce15551638 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/JTokenExtensions.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/JTokenExtensions.cs @@ -1,7 +1,5 @@ -using System; -using System.IO; +using System.IO; using System.Runtime.CompilerServices; -using System.Text; using System.Threading; using System.Threading.Tasks; using Elasticsearch.Net; @@ -13,15 +11,16 @@ namespace Nest internal static class JTokenExtensions { /// - /// Writes a to a using + /// Writes a to a using /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static MemoryStream ToStream( this JToken token, - IMemoryStreamFactory memoryStreamFactory = null) + IMemoryStreamFactory memoryStreamFactory = null + ) { var ms = memoryStreamFactory?.Create() ?? new MemoryStream(); - using (var streamWriter = new StreamWriter(ms, InternalSerializer.ExpectedEncoding, InternalSerializer.DefaultBufferSize, leaveOpen: true)) + using (var streamWriter = new StreamWriter(ms, InternalSerializer.ExpectedEncoding, InternalSerializer.DefaultBufferSize, true)) using (var writer = new JsonTextWriter(streamWriter)) { token.WriteTo(writer); @@ -32,16 +31,17 @@ public static MemoryStream ToStream( } /// - /// Writes a asynchronously to a using + /// Writes a asynchronously to a using /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static async Task ToStreamAsync( this JToken token, IMemoryStreamFactory memoryStreamFactory = null, - CancellationToken cancellationToken = default(CancellationToken)) + CancellationToken cancellationToken = default(CancellationToken) + ) { var ms = memoryStreamFactory?.Create() ?? new MemoryStream(); - using (var streamWriter = new StreamWriter(ms, InternalSerializer.ExpectedEncoding, InternalSerializer.DefaultBufferSize, leaveOpen: true)) + using (var streamWriter = new StreamWriter(ms, InternalSerializer.ExpectedEncoding, InternalSerializer.DefaultBufferSize, true)) using (var writer = new JsonTextWriter(streamWriter)) { await token.WriteToAsync(writer, cancellationToken).ConfigureAwait(false); diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/JsonReaderExtensions.cs b/src/Nest/CommonAbstractions/SerializationBehavior/JsonReaderExtensions.cs index 2536de619ca..ebe592661d3 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/JsonReaderExtensions.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/JsonReaderExtensions.cs @@ -21,10 +21,10 @@ public static T ReadToEnd(this JsonReader reader, int depth, T r = null) where T : class { if (reader.Depth <= depth) return r; + do - { reader.Read(); - } while (reader.Depth >= depth && reader.TokenType != JsonToken.EndObject); + while (reader.Depth >= depth && reader.TokenType != JsonToken.EndObject); return r; } @@ -32,18 +32,18 @@ public static T ExhaustTo(this JsonReader reader, int depth, T r = null, Json where T : class { if (reader.Depth < depth) return r; + while (reader.Depth >= depth) { - if (reader.Depth == depth && reader.TokenType == endType) - { - break; - } + if (reader.Depth == depth && reader.TokenType == endType) break; + var readAnything = reader.Read(); if (!readAnything || reader.Depth < depth) break; } return r; } - public static object ExhaustTo(this JsonReader reader, int depth, JsonToken endType = JsonToken.EndObject) => reader.ExhaustTo(depth, null, endType); + public static object ExhaustTo(this JsonReader reader, int depth, JsonToken endType = JsonToken.EndObject) => + reader.ExhaustTo(depth, null, endType); } } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/PropertyMapping.cs b/src/Nest/CommonAbstractions/SerializationBehavior/PropertyMapping.cs index b72febddd4e..cea17eab878 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/PropertyMapping.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/PropertyMapping.cs @@ -8,26 +8,27 @@ namespace Nest /// Determines how a POCO property maps to the property on a JSON object when serialized public interface IPropertyMapping { - /// Override the property name serialized to JSON for this property - string Name { get; set; } /// /// Ignore this property completely - /// - When mapping automatically using + /// - When mapping automatically using /// - When Indexing this type do not serialize this property and its value /// bool Ignore { get; set; } + + /// Override the property name serialized to JSON for this property + string Name { get; set; } } - /// + /// public class PropertyMapping : IPropertyMapping { public static PropertyMapping Ignored = new PropertyMapping { Ignore = true }; /// - public string Name { get; set; } + public bool Ignore { get; set; } /// - public bool Ignore { get; set; } + public string Name { get; set; } } /// @@ -36,24 +37,24 @@ public class PropertyMapping : IPropertyMapping public interface IPropertyMappingProvider { /// - /// Creates an for a + /// Creates an for a /// IPropertyMapping CreatePropertyMapping(MemberInfo memberInfo); } - /// + /// public class PropertyMappingProvider : IPropertyMappingProvider { protected readonly ConcurrentDictionary Properties = new ConcurrentDictionary(); - /// + /// public virtual IPropertyMapping CreatePropertyMapping(MemberInfo memberInfo) { var memberInfoString = $"{memberInfo.DeclaringType?.FullName}.{memberInfo.Name}"; if (Properties.TryGetValue(memberInfoString, out var mapping)) return mapping; mapping = PropertyMappingFromAttributes(memberInfo); - this.Properties.TryAdd(memberInfoString, mapping); + Properties.TryAdd(memberInfoString, mapping); return mapping; } @@ -64,9 +65,9 @@ private static IPropertyMapping PropertyMappingFromAttributes(MemberInfo memberI var propertyName = memberInfo.GetCustomAttribute(true); var ignore = memberInfo.GetCustomAttribute(true); if (jsonProperty == null && ignore == null && propertyName == null && dataMemberProperty == null) return null; - return new PropertyMapping {Name = propertyName?.Name ?? jsonProperty?.PropertyName ?? dataMemberProperty?.Name, Ignore = ignore != null}; + + return new PropertyMapping + { Name = propertyName?.Name ?? jsonProperty?.PropertyName ?? dataMemberProperty?.Name, Ignore = ignore != null }; } } - - } diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/SourceConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/SourceConverter.cs index e789c4fb0aa..5fb4f1838a6 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/SourceConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/SourceConverter.cs @@ -1,9 +1,6 @@ using System; -using System.IO; -using System.Text; using Elasticsearch.Net; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using static Elasticsearch.Net.SerializationFormatting; namespace Nest @@ -12,10 +9,11 @@ internal class SourceConverter : JsonConverter { public override bool CanRead => true; public override bool CanWrite => true; - public override bool CanConvert(Type objectType) => true; public virtual SerializationFormatting? ForceFormatting { get; } = null; + public override bool CanConvert(Type objectType) => true; + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var sourceSerializer = serializer.GetConnectionSettings().SourceSerializer; diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/SourceValueWriteConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/SourceValueWriteConverter.cs index 32256e5d365..a69b879409b 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/SourceValueWriteConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/SourceValueWriteConverter.cs @@ -8,12 +8,10 @@ internal class SourceValueWriteConverter : JsonConverter { public override bool CanRead => false; public override bool CanWrite => true; + public override bool CanConvert(Type objectType) => true; - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - Write(writer, value, serializer); - } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => Write(writer, value, serializer); public static void Write(JsonWriter writer, object value, JsonSerializer serializer) { diff --git a/src/Nest/CommonAbstractions/Static/Infer.cs b/src/Nest/CommonAbstractions/Static/Infer.cs index 1f45a7c0a94..f123460d473 100644 --- a/src/Nest/CommonAbstractions/Static/Infer.cs +++ b/src/Nest/CommonAbstractions/Static/Infer.cs @@ -8,38 +8,49 @@ namespace Nest { public static class Infer { + public static Indices AllIndices = Nest.Indices.All; + public static Types AllTypes = Types.All; + public static IndexName Index(IndexName index) => index; + public static IndexName Index() => typeof(T); + public static IndexName Index(string clusterName) => IndexName.From(clusterName); public static Indices Indices() => typeof(T); + public static Indices Indices(params IndexName[] indices) => indices; + public static Indices Indices(IEnumerable indices) => indices.ToArray(); - public static Indices AllIndices = Nest.Indices.All; public static TypeName Type(TypeName type) => type; + public static TypeName Type() => typeof(T); + public static Types Type(IEnumerable types) => new Types.ManyTypes(types); + public static Types Type(params TypeName[] types) => new Types.ManyTypes(types); - public static Types AllTypes = Nest.Types.All; public static RelationName Relation(string type) => type; + public static RelationName Relation(Type type) => type; + public static RelationName Relation() => typeof(T); - public static Routing Route(T instance) where T : class => Nest.Routing.From(instance); + public static Routing Route(T instance) where T : class => Routing.From(instance); public static Names Names(params string[] names) => string.Join(",", names); + public static Names Names(IEnumerable names) => string.Join(",", names); public static Id Id(T document) where T : class => Nest.Id.From(document); public static Fields Fields(params Expression>[] fields) where T : class => - new Fields(fields.Select(f=>(Field)f)); + new Fields(fields.Select(f => (Field)f)); - public static Fields Fields(params string[] fields) => new Fields(fields.Select(f=>(Field)f)); + public static Fields Fields(params string[] fields) => new Fields(fields.Select(f => (Field)f)); - public static Fields Fields(params PropertyInfo[] properties) => new Fields(properties.Select(f=>(Field)f)); + public static Fields Fields(params PropertyInfo[] properties) => new Fields(properties.Select(f => (Field)f)); /// /// Create a strongly typed string field name representation of the path to a property diff --git a/src/Nest/CommonAbstractions/Union/Union.cs b/src/Nest/CommonAbstractions/Union/Union.cs index de74bcda625..dfa196c6534 100644 --- a/src/Nest/CommonAbstractions/Union/Union.cs +++ b/src/Nest/CommonAbstractions/Union/Union.cs @@ -4,7 +4,7 @@ namespace Nest { /// - /// Represents the union of two types, and . Used + /// Represents the union of two types, and . Used /// in scenarios where an Elasticsearch API may accept more than one different input data structure. /// /// The first type @@ -12,27 +12,35 @@ namespace Nest [JsonConverter(typeof(UnionJsonConverter))] public class Union { + internal readonly int _tag; internal readonly TFirst Item1; internal readonly TSecond Item2; - internal readonly int _tag; /// - /// Creates an new instance of that encapsulates value + /// Creates an new instance of that encapsulates value /// /// The value to encapsulate - public Union(TFirst item) { Item1 = item; _tag = 0; } + public Union(TFirst item) + { + Item1 = item; + _tag = 0; + } /// - /// Creates an new instance of that encapsulates value + /// Creates an new instance of that encapsulates value /// /// The value to encapsulate - public Union(TSecond item) { Item2 = item; _tag = 1; } + public Union(TSecond item) + { + Item2 = item; + _tag = 1; + } /// - /// Runs an delegate against the encapsulated value + /// Runs an delegate against the encapsulated value /// - /// The delegate to run when this instance encapsulates an instance of - /// The delegate to run when this instance encapsulates an instance of + /// The delegate to run when this instance encapsulates an instance of + /// The delegate to run when this instance encapsulates an instance of public void Match(Action first, Action second) { switch (_tag) @@ -48,10 +56,10 @@ public void Match(Action first, Action second) } /// - /// Runs a delegate against the encapsulated value + /// Runs a delegate against the encapsulated value /// - /// The delegate to run when this instance encapsulates an instance of - /// The delegate to run when this instance encapsulates an instance of + /// The delegate to run when this instance encapsulates an instance of + /// The delegate to run when this instance encapsulates an instance of public T Match(Func first, Func second) { switch (_tag) @@ -63,6 +71,7 @@ public T Match(Func first, Func second) } public static implicit operator Union(TFirst first) => new Union(first); + public static implicit operator Union(TSecond second) => new Union(second); } } diff --git a/src/Nest/CommonAbstractions/Union/UnionJsonConverter.cs b/src/Nest/CommonAbstractions/Union/UnionJsonConverter.cs index 38d46c576ba..77abef76bf7 100644 --- a/src/Nest/CommonAbstractions/Union/UnionJsonConverter.cs +++ b/src/Nest/CommonAbstractions/Union/UnionJsonConverter.cs @@ -1,15 +1,14 @@ using System; using System.Collections.Concurrent; -using System.Linq; using System.Reflection; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Nest { internal class UnionJsonConverter : JsonConverter { - private static readonly ConcurrentDictionary KnownTypes = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary KnownTypes = + new ConcurrentDictionary(); public override bool CanConvert(Type objectType) => true; @@ -22,11 +21,10 @@ public static UnionJsonConverterBase CreateConverter(Type t) switch (genericArguments.Length) { case 2: - conversion = typeof (UnionJsonConverter<,>).CreateGenericInstance(genericArguments) as UnionJsonConverterBase; + conversion = typeof(UnionJsonConverter<,>).CreateGenericInstance(genericArguments) as UnionJsonConverterBase; break; default: throw new Exception($"No union converter registered that takes {genericArguments.Length} type arguments for {t.Name}"); - } KnownTypes.TryAdd(t, conversion); return conversion; @@ -62,6 +60,7 @@ public bool TryRead(JsonReader reader, JsonSerializer serializer, out T v) } public abstract void WriteJson(JsonWriter writer, object v, JsonSerializer serializer); + public abstract object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer); } @@ -86,11 +85,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist Union u = null; using (var r = reader.ReadTokenWithDateParseHandlingNone().CreateReader()) { - if (this.TryRead(r, serializer, out TFirst first)) u = first; - else if (this.TryRead(r, serializer, out TSecond second)) u = second; + if (TryRead(r, serializer, out TFirst first)) u = first; + else if (TryRead(r, serializer, out TSecond second)) u = second; } return u; } - } } diff --git a/src/Nest/CommonOptions/Attributes/AlternativeEnumMemberAttribute.cs b/src/Nest/CommonOptions/Attributes/AlternativeEnumMemberAttribute.cs index 5516d9f0732..1e552b67a9c 100644 --- a/src/Nest/CommonOptions/Attributes/AlternativeEnumMemberAttribute.cs +++ b/src/Nest/CommonOptions/Attributes/AlternativeEnumMemberAttribute.cs @@ -3,7 +3,7 @@ namespace Nest { /// - /// Similar to , but allows an alternative string + /// Similar to , but allows an alternative string /// value to be specified for an enum field value. /// [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)] diff --git a/src/Nest/CommonOptions/DateFormat/DateFormat.cs b/src/Nest/CommonOptions/DateFormat/DateFormat.cs index 50da3c61a06..ebfa10ddf06 100644 --- a/src/Nest/CommonOptions/DateFormat/DateFormat.cs +++ b/src/Nest/CommonOptions/DateFormat/DateFormat.cs @@ -4,159 +4,307 @@ //these const reflect their output on purpose public static class DateFormat { - ///A formatter for the number of milliseconds since the epoch. Note, that this timestamp is subject to the limits of a Java Long.MIN_VALUE and Long.MAX_VALUE. - public const string epoch_millis = "epoch_millis"; - ///A formatter for the number of seconds since the epoch. Note, that this timestamp is subject to the limits of a Java Long.MIN_VALUE and Long. MAX_VALUE divided by 1000 (the number of milliseconds in a second). - public const string epoch_second = "epoch_second"; - ///A basic formatter for a full date as four digit year, two digit month of year, and two digit day of month: yyyyMMdd. - public const string date_optional_time = "date_optional_time"; ///A basic formatter that combines a basic date and time, separated by a T: yyyyMMdd'T'HHmmss.SSSZ. public const string basic_date = "basic_date"; + ///A basic formatter that combines a basic date and time, separated by a T: yyyyMMdd'T'HHmmss.SSSZ. public const string basic_date_time = "basic_date_time"; + ///A basic formatter that combines a basic date and time without millis, separated by a T: yyyyMMdd'T'HHmmssZ. public const string basic_date_time_no_millis = "basic_date_time_no_millis"; + ///A formatter for a full ordinal date, using a four digit year and three digit dayOfYear: yyyyDDD. public const string basic_ordinal_date = "basic_ordinal_date"; + ///A formatter for a full ordinal date and time, using a four digit year and three digit dayOfYear: yyyyDDD'T'HHmmss.SSSZ. public const string basic_ordinal_date_time = "basic_ordinal_date_time"; + ///A formatter for a full ordinal date and time without millis, using a four digit year and three digit dayOfYear: yyyyDDD'T'HHmmssZ. public const string basic_ordinal_date_time_no_millis = "basic_ordinal_date_time_no_millis"; - ///A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit millis, and time zone offset: HHmmss.SSSZ. - public const string basic_time = "basic_time"; - ///A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset: HHmmssZ. - public const string basic_time_no_millis = "basic_time_no_millis"; - ///A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit millis, and time zone off set prefixed by T: 'T'HHmmss.SSSZ. + + /// + /// A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit millis, and time + /// zone off set prefixed by T: 'T'HHmmss.SSSZ. + /// public const string basic_t_time = "basic_t_time"; - ///A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset prefixed by T: 'T'HHmmssZ. + + /// + /// A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset prefixed + /// by T: 'T'HHmmssZ. + /// public const string basic_t_time_no_millis = "basic_t_time_no_millis"; + + /// + /// A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit millis, and time + /// zone offset: HHmmss.SSSZ. + /// + public const string basic_time = "basic_time"; + + /// + /// A basic formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset: + /// HHmmssZ. + /// + public const string basic_time_no_millis = "basic_time_no_millis"; + ///A basic formatter for a full date as four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx'W'wwe. public const string basic_week_date = "basic_week_date"; - ///A basic formatter for a full date as four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx'W'wwe. - public const string strict_basic_week_date = "strict_basic_week_date"; + ///A basic formatter that combines a basic weekyear date and time, separated by a T: xxxx'W'wwe'T'HHmmss.SSSZ. public const string basic_week_date_time = "basic_week_date_time"; - ///A basic formatter that combines a basic weekyear date and time, separated by a T: xxxx'W'wwe'T'HHmmss.SSSZ. - public const string strict_basic_week_date_time = "strict_basic_week_date_time"; + ///A basic formatter that combines a basic weekyear date and time without millis, separated by a T: xxxx'W'wwe'T'HHmmssZ. public const string basic_week_date_time_no_millis = "basic_week_date_time_no_millis"; - ///A basic formatter that combines a basic weekyear date and time without millis, separated by a T: xxxx'W'wwe'T'HHmmssZ. - public const string strict_basic_week_date_time_no_millis = "strict_basic_week_date_time_no_millis"; + ///A formatter for a full date as four digit year, two digit month of year, and two digit day of month: yyyy-MM-dd. public const string date = "date"; - ///A formatter for a full date as four digit year, two digit month of year, and two digit day of month: yyyy-MM-dd. - public const string strict_date = "strict_date"; + ///A formatter that combines a full date and two digit hour of day: yyyy-MM-dd'T'HH. public const string date_hour = "date_hour"; - ///A formatter that combines a full date and two digit hour of day: yyyy-MM-dd'T'HH. - public const string strict_date_hour = "strict_date_hour"; + ///A formatter that combines a full date, two digit hour of day, and two digit minute of hour: yyyy-MM-dd'T'HH:mm. public const string date_hour_minute = "date_hour_minute"; - ///A formatter that combines a full date, two digit hour of day, and two digit minute of hour: yyyy-MM-dd'T'HH:mm. - public const string strict_date_hour_minute = "strict_date_hour_minute"; - ///A formatter that combines a full date, two digit hour of day, two digit minute of hour, and two digit second of minute: yyyy-MM-dd'T'HH:mm:ss. + + /// + /// A formatter that combines a full date, two digit hour of day, two digit minute of hour, and two digit second of minute: + /// yyyy-MM-dd'T'HH:mm:ss. + /// public const string date_hour_minute_second = "date_hour_minute_second"; - ///A formatter that combines a full date, two digit hour of day, two digit minute of hour, and two digit second of minute: yyyy-MM-dd'T'HH:mm:ss. - public const string strict_date_hour_minute_second = "strict_date_hour_minute_second"; - ///A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: yyyy-MM-dd'T'HH:mm:ss.SSS. + + /// + /// A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three + /// digit fraction of second: yyyy-MM-dd'T'HH:mm:ss.SSS. + /// public const string date_hour_minute_second_fraction = "date_hour_minute_second_fraction"; - ///A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: yyyy-MM-dd'T'HH:mm:ss.SSS. - public const string strict_date_hour_minute_second_fraction = "strict_date_hour_minute_second_fraction"; - ///A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: yyyy-MM-dd'T'HH:mm:ss.SSS. + + /// + /// A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three + /// digit fraction of second: yyyy-MM-dd'T'HH:mm:ss.SSS. + /// public const string date_hour_minute_second_millis = "date_hour_minute_second_millis"; - ///A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: yyyy-MM-dd'T'HH:mm:ss.SSS. - public const string strict_date_hour_minute_second_millis = "strict_date_hour_minute_second_millis"; + + ///A basic formatter for a full date as four digit year, two digit month of year, and two digit day of month: yyyyMMdd. + public const string date_optional_time = "date_optional_time"; + ///A formatter that combines a full date and time, separated by a T: yyyy-MM-dd'T'HH:mm:ss.SSSZZ. public const string date_time = "date_time"; - ///A formatter that combines a full date and time, separated by a T: yyyy-MM-dd'T'HH:mm:ss.SSSZZ. - public const string strict_date_time = "strict_date_time"; + ///A formatter that combines a full date and time without millis, separated by a T: yyyy-MM-dd'T'HH:mm:ssZZ. public const string date_time_no_millis = "date_time_no_millis"; - ///A formatter that combines a full date and time without millis, separated by a T: yyyy-MM-dd'T'HH:mm:ssZZ. - public const string strict_date_time_no_millis = "strict_date_time_no_millis"; + + /// + /// A formatter for the number of milliseconds since the epoch. Note, that this timestamp is subject to the limits of a Java + /// Long.MIN_VALUE and Long.MAX_VALUE. + /// + public const string epoch_millis = "epoch_millis"; + + /// + /// A formatter for the number of seconds since the epoch. Note, that this timestamp is subject to the limits of a Java Long.MIN_VALUE + /// and Long. MAX_VALUE divided by 1000 (the number of milliseconds in a second). + /// + public const string epoch_second = "epoch_second"; + ///A formatter for a two digit hour of day: HH public const string hour = "hour"; - ///A formatter for a two digit hour of day: HH - public const string strict_hour = "strict_hour"; + ///A formatter for a two digit hour of day and two digit minute of hour: HH:mm. public const string hour_minute = "hour_minute"; - ///A formatter for a two digit hour of day and two digit minute of hour: HH:mm. - public const string strict_hour_minute = "strict_hour_minute"; + ///A formatter for a two digit hour of day, two digit minute of hour, and two digit second of minute: HH:mm:ss. public const string hour_minute_second = "hour_minute_second"; - ///A formatter for a two digit hour of day, two digit minute of hour, and two digit second of minute: HH:mm:ss. - public const string strict_hour_minute_second = "strict_hour_minute_second"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: HH:mm:ss.SSS. + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: + /// HH:mm:ss.SSS. + /// public const string hour_minute_second_fraction = "hour_minute_second_fraction"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: HH:mm:ss.SSS. - public const string strict_hour_minute_second_fraction = "strict_hour_minute_second_fraction"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: HH:mm:ss.SSS. + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: + /// HH:mm:ss.SSS. + /// public const string hour_minute_second_millis = "hour_minute_second_millis"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: HH:mm:ss.SSS. - public const string strict_hour_minute_second_millis = "strict_hour_minute_second_millis"; + ///A formatter for a full ordinal date, using a four digit year and three digit dayOfYear: yyyy-DDD. public const string ordinal_date = "ordinal_date"; - ///A formatter for a full ordinal date, using a four digit year and three digit dayOfYear: yyyy-DDD. - public const string strict_ordinal_date = "strict_ordinal_date"; + ///A formatter for a full ordinal date and time, using a four digit year and three digit dayOfYear: yyyy-DDD'T'HH:mm:ss.SSSZZ. public const string ordinal_date_time = "ordinal_date_time"; + + /// + /// A formatter for a full ordinal date and time without millis, using a four digit year and three digit dayOfYear: + /// yyyy-DDD'T'HH:mm:ssZZ. + /// + public const string ordinal_date_time_no_millis = "ordinal_date_time_no_millis"; + + ///A basic formatter for a full date as four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx'W'wwe. + public const string strict_basic_week_date = "strict_basic_week_date"; + + ///A basic formatter that combines a basic weekyear date and time, separated by a T: xxxx'W'wwe'T'HHmmss.SSSZ. + public const string strict_basic_week_date_time = "strict_basic_week_date_time"; + + ///A basic formatter that combines a basic weekyear date and time without millis, separated by a T: xxxx'W'wwe'T'HHmmssZ. + public const string strict_basic_week_date_time_no_millis = "strict_basic_week_date_time_no_millis"; + + ///A formatter for a full date as four digit year, two digit month of year, and two digit day of month: yyyy-MM-dd. + public const string strict_date = "strict_date"; + + ///A formatter that combines a full date and two digit hour of day: yyyy-MM-dd'T'HH. + public const string strict_date_hour = "strict_date_hour"; + + ///A formatter that combines a full date, two digit hour of day, and two digit minute of hour: yyyy-MM-dd'T'HH:mm. + public const string strict_date_hour_minute = "strict_date_hour_minute"; + + /// + /// A formatter that combines a full date, two digit hour of day, two digit minute of hour, and two digit second of minute: + /// yyyy-MM-dd'T'HH:mm:ss. + /// + public const string strict_date_hour_minute_second = "strict_date_hour_minute_second"; + + /// + /// A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three + /// digit fraction of second: yyyy-MM-dd'T'HH:mm:ss.SSS. + /// + public const string strict_date_hour_minute_second_fraction = "strict_date_hour_minute_second_fraction"; + + /// + /// A formatter that combines a full date, two digit hour of day, two digit minute of hour, two digit second of minute, and three + /// digit fraction of second: yyyy-MM-dd'T'HH:mm:ss.SSS. + /// + public const string strict_date_hour_minute_second_millis = "strict_date_hour_minute_second_millis"; + + ///A formatter that combines a full date and time, separated by a T: yyyy-MM-dd'T'HH:mm:ss.SSSZZ. + public const string strict_date_time = "strict_date_time"; + + ///A formatter that combines a full date and time without millis, separated by a T: yyyy-MM-dd'T'HH:mm:ssZZ. + public const string strict_date_time_no_millis = "strict_date_time_no_millis"; + + ///A formatter for a two digit hour of day: HH + public const string strict_hour = "strict_hour"; + + ///A formatter for a two digit hour of day and two digit minute of hour: HH:mm. + public const string strict_hour_minute = "strict_hour_minute"; + + ///A formatter for a two digit hour of day, two digit minute of hour, and two digit second of minute: HH:mm:ss. + public const string strict_hour_minute_second = "strict_hour_minute_second"; + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: + /// HH:mm:ss.SSS. + /// + public const string strict_hour_minute_second_fraction = "strict_hour_minute_second_fraction"; + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and three digit fraction of second: + /// HH:mm:ss.SSS. + /// + public const string strict_hour_minute_second_millis = "strict_hour_minute_second_millis"; + + ///A formatter for a full ordinal date, using a four digit year and three digit dayOfYear: yyyy-DDD. + public const string strict_ordinal_date = "strict_ordinal_date"; + ///A formatter for a full ordinal date and time, using a four digit year and three digit dayOfYear: yyyy-DDD'T'HH:mm:ss.SSSZZ. public const string strict_ordinal_date_time = "strict_ordinal_date_time"; - ///A formatter for a full ordinal date and time without millis, using a four digit year and three digit dayOfYear: yyyy-DDD'T'HH:mm:ssZZ. - public const string ordinal_date_time_no_millis = "ordinal_date_time_no_millis"; - ///A formatter for a full ordinal date and time without millis, using a four digit year and three digit dayOfYear: yyyy-DDD'T'HH:mm:ssZZ. + + /// + /// A formatter for a full ordinal date and time without millis, using a four digit year and three digit dayOfYear: + /// yyyy-DDD'T'HH:mm:ssZZ. + /// public const string strict_ordinal_date_time_no_millis = "strict_ordinal_date_time_no_millis"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and time zone offset: HH:mm:ss.SSSZZ. - public const string time = "time"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and time zone offset: HH:mm:ss.SSSZZ. + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and + /// time zone offset prefixed by T: 'T'HH:mm:ss.SSSZZ. + /// + public const string strict_t_time = "strict_t_time"; + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset prefixed by T: + /// 'T'HH:mm:ssZZ. + /// + public const string strict_t_time_no_millis = "strict_t_time_no_millis"; + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and + /// time zone offset: HH:mm:ss.SSSZZ. + /// public const string strict_time = "strict_time"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset: HH:mm:ssZZ. - public const string time_no_millis = "time_no_millis"; + ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset: HH:mm:ssZZ. public const string strict_time_no_millis = "strict_time_no_millis"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and time zone offset prefixed by T: 'T'HH:mm:ss.SSSZZ. + + ///A formatter for a full date as four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx-'W'ww-e. + public const string strict_week_date = "strict_week_date"; + + ///A formatter that combines a full weekyear date and time, separated by a T: xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ. + public const string strict_week_date_time = "strict_week_date_time"; + + ///A formatter that combines a full weekyear date and time without millis, separated by a T: xxxx-'W'ww-e'T'HH:mm:ssZZ. + public const string strict_week_date_time_no_millis = "strict_week_date_time_no_millis"; + + ///A formatter for a four digit weekyear: xxxx. + public const string strict_weekyear = "strict_weekyear"; + + ///A formatter for a four digit weekyear and two digit week of weekyear: xxxx-'W'ww. + public const string strict_weekyear_week = "strict_weekyear_week"; + + ///A formatter for a four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx-'W'ww-e. + public const string strict_weekyear_week_day = "strict_weekyear_week_day"; + + ///A formatter for a four digit year: yyyy. + public const string strict_year = "strict_year"; + + ///A formatter for a four digit year and two digit month of year: yyyy-MM. + public const string strict_year_month = "strict_year_month"; + + ///A formatter for a four digit year, two digit month of year, and two digit day of month: yyyy-MM-dd. + public const string strict_year_month_day = "strict_year_month_day"; + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and + /// time zone offset prefixed by T: 'T'HH:mm:ss.SSSZZ. + /// public const string t_time = "t_time"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and time zone offset prefixed by T: 'T'HH:mm:ss.SSSZZ. - public const string strict_t_time = "strict_t_time"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset prefixed by T: 'T'HH:mm:ssZZ. + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset prefixed by T: + /// 'T'HH:mm:ssZZ. + /// public const string t_time_no_millis = "t_time_no_millis"; - ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset prefixed by T: 'T'HH:mm:ssZZ. - public const string strict_t_time_no_millis = "strict_t_time_no_millis"; + + /// + /// A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, three digit fraction of second, and + /// time zone offset: HH:mm:ss.SSSZZ. + /// + public const string time = "time"; + + ///A formatter for a two digit hour of day, two digit minute of hour, two digit second of minute, and time zone offset: HH:mm:ssZZ. + public const string time_no_millis = "time_no_millis"; + ///A formatter for a full date as four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx-'W'ww-e. public const string week_date = "week_date"; - ///A formatter for a full date as four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx-'W'ww-e. - public const string strict_week_date = "strict_week_date"; + ///A formatter that combines a full weekyear date and time, separated by a T: xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ. public const string week_date_time = "week_date_time"; - ///A formatter that combines a full weekyear date and time, separated by a T: xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ. - public const string strict_week_date_time = "strict_week_date_time"; + ///A formatter that combines a full weekyear date and time without millis, separated by a T: xxxx-'W'ww-e'T'HH:mm:ssZZ. public const string week_date_time_no_millis = "week_date_time_no_millis"; - ///A formatter that combines a full weekyear date and time without millis, separated by a T: xxxx-'W'ww-e'T'HH:mm:ssZZ. - public const string strict_week_date_time_no_millis = "strict_week_date_time_no_millis"; + ///A formatter for a four digit weekyear: xxxx. public const string weekyear = "weekyear"; - ///A formatter for a four digit weekyear: xxxx. - public const string strict_weekyear = "strict_weekyear"; + ///A formatter for a four digit weekyear and two digit week of weekyear: xxxx-'W'ww. public const string weekyear_week = "weekyear_week"; - ///A formatter for a four digit weekyear and two digit week of weekyear: xxxx-'W'ww. - public const string strict_weekyear_week = "strict_weekyear_week"; + ///A formatter for a four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx-'W'ww-e. public const string weekyear_week_day = "weekyear_week_day"; - ///A formatter for a four digit weekyear, two digit week of weekyear, and one digit day of week: xxxx-'W'ww-e. - public const string strict_weekyear_week_day = "strict_weekyear_week_day"; + ///A formatter for a four digit year: yyyy. public const string year = "year"; - ///A formatter for a four digit year: yyyy. - public const string strict_year = "strict_year"; + ///A formatter for a four digit year and two digit month of year: yyyy-MM. public const string year_month = "year_month"; - ///A formatter for a four digit year and two digit month of year: yyyy-MM. - public const string strict_year_month = "strict_year_month"; + ///A formatter for a four digit year, two digit month of year, and two digit day of month: yyyy-MM-dd. public const string year_month_day = "year_month_day"; - ///A formatter for a four digit year, two digit month of year, and two digit day of month: yyyy-MM-dd. - public const string strict_year_month_day = "strict_year_month_day"; } } diff --git a/src/Nest/CommonOptions/DateMath/DateMath.cs b/src/Nest/CommonOptions/DateMath/DateMath.cs index 08f9680afe7..8a2986f20e6 100644 --- a/src/Nest/CommonOptions/DateMath/DateMath.cs +++ b/src/Nest/CommonOptions/DateMath/DateMath.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; -using Elasticsearch.Net; using Newtonsoft.Json; namespace Nest @@ -14,30 +13,31 @@ public interface IDateMath DateMathTimeUnit? Round { get; } } - [JsonConverter(typeof(DateMath.Json))] + [JsonConverter(typeof(Json))] public abstract class DateMath : IDateMath { private static readonly Regex DateMathRegex = new Regex(@"^(?now|.+(?:\|\||$))(?(?:(?:\+|\-)[^\/]*))?(?\/(?:y|M|w|d|h|m|s))?$"); - Union IDateMath.Anchor => Anchor; - DateMathTimeUnit? IDateMath.Round => Round; - IList> IDateMath.Ranges { get; } = new List>(); - - protected IDateMath Self => this; - protected Union Anchor; protected DateMathTimeUnit? Round; public static DateMathExpression Now => new DateMathExpression("now"); + protected IDateMath Self => this; + + Union IDateMath.Anchor => Anchor; + IList> IDateMath.Ranges { get; } = new List>(); + DateMathTimeUnit? IDateMath.Round => Round; + public static DateMathExpression Anchored(DateTime anchor) => new DateMathExpression(anchor); public static DateMathExpression Anchored(string dateAnchor) => new DateMathExpression(dateAnchor); - public static implicit operator DateMath(DateTime dateTime) => DateMath.Anchored(dateTime); - public static implicit operator DateMath(string dateMath) => DateMath.FromString(dateMath); + public static implicit operator DateMath(DateTime dateTime) => Anchored(dateTime); + + public static implicit operator DateMath(string dateMath) => FromString(dateMath); public static DateMath FromString(string dateMath) { @@ -112,11 +112,12 @@ public override void WriteJson(JsonWriter writer, DateMath value, JsonSerializer public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.String) - return DateMath.FromString(reader.Value as string); + return FromString(reader.Value as string); + if (reader.TokenType == JsonToken.Date) { var d = reader.Value as DateTime?; - return d.HasValue ? DateMath.Anchored(d.Value) : null; + return d.HasValue ? Anchored(d.Value) : null; } return null; } diff --git a/src/Nest/CommonOptions/DateMath/DateMathExpression.cs b/src/Nest/CommonOptions/DateMath/DateMathExpression.cs index f3057b37db8..daefa90e92f 100644 --- a/src/Nest/CommonOptions/DateMath/DateMathExpression.cs +++ b/src/Nest/CommonOptions/DateMath/DateMathExpression.cs @@ -4,15 +4,16 @@ namespace Nest { public class DateMathExpression : DateMath { - public DateMathExpression(string anchor) { this.Anchor = anchor; } - public DateMathExpression(DateTime anchor) { this.Anchor = anchor; } + public DateMathExpression(string anchor) => Anchor = anchor; + + public DateMathExpression(DateTime anchor) => Anchor = anchor; public DateMathExpression(Union anchor, DateMathTime range, DateMathOperation operation) { anchor.ThrowIfNull(nameof(anchor)); range.ThrowIfNull(nameof(range)); operation.ThrowIfNull(nameof(operation)); - this.Anchor = anchor; + Anchor = anchor; Self.Ranges.Add(Tuple.Create(operation, range)); } @@ -36,7 +37,7 @@ public DateMathExpression Operation(DateMathTime expression, DateMathOperation o public DateMath RoundTo(DateMathTimeUnit round) { - this.Round = round; + Round = round; return this; } } diff --git a/src/Nest/CommonOptions/DateMath/DateMathOperation.cs b/src/Nest/CommonOptions/DateMath/DateMathOperation.cs index 64ab47aa05e..e440720022e 100644 --- a/src/Nest/CommonOptions/DateMath/DateMathOperation.cs +++ b/src/Nest/CommonOptions/DateMath/DateMathOperation.cs @@ -10,6 +10,7 @@ public enum DateMathOperation { [EnumMember(Value = "+")] Add, + [EnumMember(Value = "-")] Subtract } @@ -27,7 +28,6 @@ public static string GetStringValue(this DateMathOperation value) default: throw new ArgumentOutOfRangeException(nameof(value), value, null); } - } } } diff --git a/src/Nest/CommonOptions/DateMath/DateMathTime.cs b/src/Nest/CommonOptions/DateMath/DateMathTime.cs index 6da281169f7..cfcb9398205 100644 --- a/src/Nest/CommonOptions/DateMath/DateMathTime.cs +++ b/src/Nest/CommonOptions/DateMath/DateMathTime.cs @@ -1,24 +1,22 @@ using System; -using System.Diagnostics; using System.Globalization; using System.Text.RegularExpressions; -using Newtonsoft.Json; namespace Nest { /// - /// A time representation for use within expressions. + /// A time representation for use within expressions. /// public class DateMathTime : IComparable, IEquatable { - private const int MonthsInAYear = 12; - private const double MillisecondsInAYearApproximate = MillisecondsInADay * 365; - private const double MillisecondsInAMonthApproximate = MillisecondsInAYearApproximate / MonthsInAYear; - private const double MillisecondsInAWeek = MillisecondsInADay * 7; private const double MillisecondsInADay = MillisecondsInAnHour * 24; - private const double MillisecondsInAnHour = MillisecondsInAMinute * 60; private const double MillisecondsInAMinute = MillisecondsInASecond * 60; + private const double MillisecondsInAMonthApproximate = MillisecondsInAYearApproximate / MonthsInAYear; + private const double MillisecondsInAnHour = MillisecondsInAMinute * 60; private const double MillisecondsInASecond = 1000; + private const double MillisecondsInAWeek = MillisecondsInADay * 7; + private const double MillisecondsInAYearApproximate = MillisecondsInADay * 365; + private const int MonthsInAYear = 12; private static readonly Regex ExpressionRegex = new Regex(@"^ @@ -34,41 +32,27 @@ public class DateMathTime : IComparable, IEquatable private double _approximateSeconds; /// - /// The numeric time factor - /// - public int Factor { get; private set; } - - /// - /// The time units - /// - public DateMathTimeUnit Interval { get; private set; } - - public static implicit operator DateMathTime(TimeSpan span) => new DateMathTime(span); - public static implicit operator DateMathTime(double milliseconds) => new DateMathTime(milliseconds); - public static implicit operator DateMathTime(string expression) => new DateMathTime(expression); - - /// - /// Instantiates a new instance of from a TimeSpan. + /// Instantiates a new instance of from a TimeSpan. /// Rounding can be specified to determine how fractional second values should be rounded. /// public DateMathTime(TimeSpan timeSpan, MidpointRounding rounding = MidpointRounding.AwayFromZero) : this(timeSpan.TotalMilliseconds, rounding) { } /// - /// Instantiates a new instance of from a milliseconds value. + /// Instantiates a new instance of from a milliseconds value. /// Rounding can be specified to determine how fractional second values should be rounded. /// public DateMathTime(double milliseconds, MidpointRounding rounding = MidpointRounding.AwayFromZero) => SetWholeFactorIntervalAndSeconds(milliseconds, rounding); /// - /// Instantiates a new instance of from a factor and interval. + /// Instantiates a new instance of from a factor and interval. /// public DateMathTime(int factor, DateMathTimeUnit interval) => SetWholeFactorIntervalAndSeconds(factor, interval, MidpointRounding.AwayFromZero); /// - /// Instantiates a new instance of from the timeUnit string expression. + /// Instantiates a new instance of from the timeUnit string expression. /// Rounding can be specified to determine how fractional second values should be rounded. /// public DateMathTime(string timeUnit, MidpointRounding rounding = MidpointRounding.AwayFromZero) @@ -80,7 +64,7 @@ public DateMathTime(string timeUnit, MidpointRounding rounding = MidpointRoundin if (!match.Success) throw new ArgumentException($"Expression '{timeUnit}' string is invalid", nameof(timeUnit)); var factor = match.Groups["factor"].Value; - if (!double.TryParse(factor, NumberStyles.Any ,CultureInfo.InvariantCulture, out double fraction)) + if (!double.TryParse(factor, NumberStyles.Any, CultureInfo.InvariantCulture, out var fraction)) throw new ArgumentException($"Expression '{timeUnit}' contains invalid factor: {factor}", nameof(timeUnit)); var intervalValue = match.Groups["interval"].Value; @@ -89,7 +73,7 @@ public DateMathTime(string timeUnit, MidpointRounding rounding = MidpointRoundin switch (intervalValue) { case "M": - interval= DateMathTimeUnit.Month; + interval = DateMathTimeUnit.Month; break; case "m": interval = DateMathTimeUnit.Minute; @@ -102,6 +86,39 @@ public DateMathTime(string timeUnit, MidpointRounding rounding = MidpointRoundin SetWholeFactorIntervalAndSeconds(fraction, interval, rounding); } + /// + /// The numeric time factor + /// + public int Factor { get; private set; } + + /// + /// The time units + /// + public DateMathTimeUnit Interval { get; private set; } + + public int CompareTo(DateMathTime other) + { + if (other == null) return 1; + if (_approximateSeconds == other._approximateSeconds) return 0; + if (_approximateSeconds < other._approximateSeconds) return -1; + + return 1; + } + + public bool Equals(DateMathTime other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return _approximateSeconds == other._approximateSeconds; + } + + public static implicit operator DateMathTime(TimeSpan span) => new DateMathTime(span); + + public static implicit operator DateMathTime(double milliseconds) => new DateMathTime(milliseconds); + + public static implicit operator DateMathTime(string expression) => new DateMathTime(expression); + private void SetWholeFactorIntervalAndSeconds(double factor, DateMathTimeUnit interval, MidpointRounding rounding) { var fraction = factor; @@ -110,30 +127,30 @@ private void SetWholeFactorIntervalAndSeconds(double factor, DateMathTimeUnit in // if the factor is already a whole number then use it if (TryGetIntegerGreaterThanZero(fraction, out var whole)) { - this.Factor = whole; - this.Interval = interval; + Factor = whole; + Interval = interval; switch (interval) { case DateMathTimeUnit.Second: - this._approximateSeconds = whole; + _approximateSeconds = whole; break; case DateMathTimeUnit.Minute: - this._approximateSeconds = whole * (MillisecondsInAMinute / MillisecondsInASecond); + _approximateSeconds = whole * (MillisecondsInAMinute / MillisecondsInASecond); break; case DateMathTimeUnit.Hour: - this._approximateSeconds = whole * (MillisecondsInAnHour / MillisecondsInASecond); + _approximateSeconds = whole * (MillisecondsInAnHour / MillisecondsInASecond); break; case DateMathTimeUnit.Day: - this._approximateSeconds = whole * (MillisecondsInADay / MillisecondsInASecond); + _approximateSeconds = whole * (MillisecondsInADay / MillisecondsInASecond); break; case DateMathTimeUnit.Week: - this._approximateSeconds = whole * (MillisecondsInAWeek / MillisecondsInASecond); + _approximateSeconds = whole * (MillisecondsInAWeek / MillisecondsInASecond); break; case DateMathTimeUnit.Month: - this._approximateSeconds = whole * (MillisecondsInAMonthApproximate / MillisecondsInASecond); + _approximateSeconds = whole * (MillisecondsInAMonthApproximate / MillisecondsInASecond); break; case DateMathTimeUnit.Year: - this._approximateSeconds = whole * (MillisecondsInAYearApproximate / MillisecondsInASecond); + _approximateSeconds = whole * (MillisecondsInAYearApproximate / MillisecondsInASecond); break; default: throw new ArgumentOutOfRangeException(nameof(interval), interval, null); @@ -161,9 +178,9 @@ private void SetWholeFactorIntervalAndSeconds(double factor, DateMathTimeUnit in case DateMathTimeUnit.Month: if (TryGetIntegerGreaterThanZero(fraction, out whole)) { - this.Factor = whole; - this.Interval = interval; - this._approximateSeconds = whole * (MillisecondsInAMonthApproximate / MillisecondsInASecond); + Factor = whole; + Interval = interval; + _approximateSeconds = whole * (MillisecondsInAMonthApproximate / MillisecondsInASecond); return; } @@ -172,18 +189,18 @@ private void SetWholeFactorIntervalAndSeconds(double factor, DateMathTimeUnit in case DateMathTimeUnit.Year: if (TryGetIntegerGreaterThanZero(fraction, out whole)) { - this.Factor = whole; - this.Interval = interval; - this._approximateSeconds = whole * (MillisecondsInAYearApproximate / MillisecondsInASecond); + Factor = whole; + Interval = interval; + _approximateSeconds = whole * (MillisecondsInAYearApproximate / MillisecondsInASecond); return; } fraction = fraction * MonthsInAYear; if (TryGetIntegerGreaterThanZero(fraction, out whole)) { - this.Factor = whole; - this.Interval = DateMathTimeUnit.Month; - this._approximateSeconds = whole * (MillisecondsInAMonthApproximate / MillisecondsInASecond); + Factor = whole; + Interval = DateMathTimeUnit.Month; + _approximateSeconds = whole * (MillisecondsInAMonthApproximate / MillisecondsInASecond); return; } milliseconds = factor * MillisecondsInAYearApproximate; @@ -205,9 +222,9 @@ private void SetWholeFactorIntervalAndSeconds(double milliseconds, MidpointRound fraction = milliseconds / MillisecondsInAWeek; if (TryGetIntegerGreaterThanZero(fraction, out whole)) { - this.Factor = whole; - this.Interval = DateMathTimeUnit.Week; - this._approximateSeconds = Factor * (MillisecondsInAWeek / MillisecondsInASecond); + Factor = whole; + Interval = DateMathTimeUnit.Week; + _approximateSeconds = Factor * (MillisecondsInAWeek / MillisecondsInASecond); return; } } @@ -216,9 +233,9 @@ private void SetWholeFactorIntervalAndSeconds(double milliseconds, MidpointRound fraction = milliseconds / MillisecondsInADay; if (TryGetIntegerGreaterThanZero(fraction, out whole)) { - this.Factor = whole; - this.Interval = DateMathTimeUnit.Day; - this._approximateSeconds = Factor * (MillisecondsInADay / MillisecondsInASecond); + Factor = whole; + Interval = DateMathTimeUnit.Day; + _approximateSeconds = Factor * (MillisecondsInADay / MillisecondsInASecond); return; } } @@ -227,9 +244,9 @@ private void SetWholeFactorIntervalAndSeconds(double milliseconds, MidpointRound fraction = milliseconds / MillisecondsInAnHour; if (TryGetIntegerGreaterThanZero(fraction, out whole)) { - this.Factor = whole; - this.Interval = DateMathTimeUnit.Hour; - this._approximateSeconds = Factor * (MillisecondsInAnHour / MillisecondsInASecond); + Factor = whole; + Interval = DateMathTimeUnit.Hour; + _approximateSeconds = Factor * (MillisecondsInAnHour / MillisecondsInASecond); return; } } @@ -238,9 +255,9 @@ private void SetWholeFactorIntervalAndSeconds(double milliseconds, MidpointRound fraction = milliseconds / MillisecondsInAMinute; if (TryGetIntegerGreaterThanZero(fraction, out whole)) { - this.Factor = whole; - this.Interval = DateMathTimeUnit.Minute; - this._approximateSeconds = Factor * (MillisecondsInAMinute / MillisecondsInASecond); + Factor = whole; + Interval = DateMathTimeUnit.Minute; + _approximateSeconds = Factor * (MillisecondsInAMinute / MillisecondsInASecond); return; } } @@ -249,25 +266,17 @@ private void SetWholeFactorIntervalAndSeconds(double milliseconds, MidpointRound fraction = milliseconds / MillisecondsInASecond; if (TryGetIntegerGreaterThanZero(fraction, out whole)) { - this.Factor = whole; - this.Interval = DateMathTimeUnit.Second; - this._approximateSeconds = Factor; + Factor = whole; + Interval = DateMathTimeUnit.Second; + _approximateSeconds = Factor; return; } } // round to nearest second, using specified rounding - this.Factor = Convert.ToInt32(Math.Round(milliseconds / MillisecondsInASecond, rounding)); - this.Interval = DateMathTimeUnit.Second; - this._approximateSeconds = Factor; - } - - public int CompareTo(DateMathTime other) - { - if (other == null) return 1; - if (this._approximateSeconds == other._approximateSeconds) return 0; - if (this._approximateSeconds < other._approximateSeconds) return -1; - return 1; + Factor = Convert.ToInt32(Math.Round(milliseconds / MillisecondsInASecond, rounding)); + Interval = DateMathTimeUnit.Second; + _approximateSeconds = Factor; } private static bool TryGetIntegerGreaterThanZero(double d, out int value) @@ -283,9 +292,11 @@ private static bool TryGetIntegerGreaterThanZero(double d, out int value) } public static bool operator <(DateMathTime left, DateMathTime right) => left.CompareTo(right) < 0; + public static bool operator <=(DateMathTime left, DateMathTime right) => left.CompareTo(right) < 0 || left.Equals(right); public static bool operator >(DateMathTime left, DateMathTime right) => left.CompareTo(right) > 0; + public static bool operator >=(DateMathTime left, DateMathTime right) => left.CompareTo(right) > 0 || left.Equals(right); public static bool operator ==(DateMathTime left, DateMathTime right) => @@ -293,23 +304,17 @@ private static bool TryGetIntegerGreaterThanZero(double d, out int value) public static bool operator !=(DateMathTime left, DateMathTime right) => !(left == right); - public override string ToString() => this.Factor + this.Interval.GetStringValue(); - - public bool Equals(DateMathTime other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return this._approximateSeconds == other._approximateSeconds; - } + public override string ToString() => Factor + Interval.GetStringValue(); public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; - return Equals((DateMathTime) obj); + if (obj.GetType() != GetType()) return false; + + return Equals((DateMathTime)obj); } - public override int GetHashCode() => this._approximateSeconds.GetHashCode(); + public override int GetHashCode() => _approximateSeconds.GetHashCode(); } } diff --git a/src/Nest/CommonOptions/DateMath/DateMathTimeUnit.cs b/src/Nest/CommonOptions/DateMath/DateMathTimeUnit.cs index f3cba059615..b190b18600c 100644 --- a/src/Nest/CommonOptions/DateMath/DateMathTimeUnit.cs +++ b/src/Nest/CommonOptions/DateMath/DateMathTimeUnit.cs @@ -9,16 +9,22 @@ public enum DateMathTimeUnit { [EnumMember(Value = "s")] Second, + [EnumMember(Value = "m")] Minute, + [EnumMember(Value = "h")] Hour, + [EnumMember(Value = "d")] Day, + [EnumMember(Value = "w")] Week, + [EnumMember(Value = "M")] Month, + [EnumMember(Value = "y")] Year } diff --git a/src/Nest/CommonOptions/Failures/BulkError.cs b/src/Nest/CommonOptions/Failures/BulkError.cs index 09dee1933e9..0e7036dd71f 100644 --- a/src/Nest/CommonOptions/Failures/BulkError.cs +++ b/src/Nest/CommonOptions/Failures/BulkError.cs @@ -7,15 +7,13 @@ namespace Nest [ContractJsonConverter(typeof(ErrorCauseJsonConverter))] public class BulkError : Error { - public string Index => this.Metadata?.Index; + public string Index => Metadata?.Index; - public int Shard => this.Metadata.Shard.GetValueOrDefault(); + public int Shard => Metadata.Shard.GetValueOrDefault(); public override string ToString() { - var cause = (CausedBy != null) ? - $" CausedBy:\n{CausedBy}" : - string.Empty; + var cause = CausedBy != null ? $" CausedBy:\n{CausedBy}" : string.Empty; return $"Type: {Type} Reason: \"{Reason}\"{cause}"; } diff --git a/src/Nest/CommonOptions/Fuzziness/Fuzziness.cs b/src/Nest/CommonOptions/Fuzziness/Fuzziness.cs index b005701838d..1e38b0548c1 100644 --- a/src/Nest/CommonOptions/Fuzziness/Fuzziness.cs +++ b/src/Nest/CommonOptions/Fuzziness/Fuzziness.cs @@ -6,12 +6,12 @@ public class Fuzziness : IFuzziness private int? _editDistance; private double? _ratio; - bool IFuzziness.Auto => this._auto; - int? IFuzziness.EditDistance => this._editDistance; - double? IFuzziness.Ratio => this._ratio; - public static Fuzziness Auto => new Fuzziness { _auto = true }; + bool IFuzziness.Auto => _auto; + int? IFuzziness.EditDistance => _editDistance; + double? IFuzziness.Ratio => _ratio; + public static Fuzziness EditDistance(int distance) => new Fuzziness { _editDistance = distance }; public static Fuzziness Ratio(double ratio) => new Fuzziness { _ratio = ratio }; diff --git a/src/Nest/CommonOptions/Fuzziness/FuzzinessJsonConverter.cs b/src/Nest/CommonOptions/Fuzziness/FuzzinessJsonConverter.cs index a284bfae6f9..e0f2c9fa2dd 100644 --- a/src/Nest/CommonOptions/Fuzziness/FuzzinessJsonConverter.cs +++ b/src/Nest/CommonOptions/Fuzziness/FuzzinessJsonConverter.cs @@ -5,23 +5,25 @@ namespace Nest { internal class FuzzinessJsonConverter : JsonConverter { + public override bool CanRead => true; public override bool CanWrite => true; + public override bool CanConvert(Type objectType) => true; - public override bool CanRead => true; public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var v = value as IFuzziness; - if (v.Auto) writer.WriteValue("AUTO"); - else if (v.EditDistance.HasValue) writer.WriteValue(v.EditDistance.Value); + if (v.Auto) writer.WriteValue("AUTO"); + else if (v.EditDistance.HasValue) writer.WriteValue(v.EditDistance.Value); else if (v.Ratio.HasValue) writer.WriteValue(v.Ratio.Value); - else writer.WriteNull(); + else writer.WriteNull(); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.String) return Fuzziness.Auto; + if (reader.TokenType == JsonToken.Integer) { var editDistance = Convert.ToInt32(reader.Value); @@ -34,6 +36,5 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } return null; } - } } diff --git a/src/Nest/CommonOptions/Fuzziness/IFuzziness.cs b/src/Nest/CommonOptions/Fuzziness/IFuzziness.cs index ab283986a76..61d7148e7f1 100644 --- a/src/Nest/CommonOptions/Fuzziness/IFuzziness.cs +++ b/src/Nest/CommonOptions/Fuzziness/IFuzziness.cs @@ -1,13 +1,12 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { [JsonConverter(typeof(FuzzinessJsonConverter))] public interface IFuzziness { - bool Auto { get; } - int? EditDistance { get; } - double? Ratio { get; } + bool Auto { get; } + int? EditDistance { get; } + double? Ratio { get; } } } diff --git a/src/Nest/CommonOptions/Geo/Distance.cs b/src/Nest/CommonOptions/Geo/Distance.cs index ed6edad5d38..5e8b61afde8 100644 --- a/src/Nest/CommonOptions/Geo/Distance.cs +++ b/src/Nest/CommonOptions/Geo/Distance.cs @@ -8,17 +8,15 @@ namespace Nest [JsonConverter(typeof(DistanceJsonConverter))] public class Distance { - private static readonly Regex _distanceUnitRegex = new Regex(@"^(?\d+(?:\.\d+)?)(?\D+)?$", RegexOptions.Compiled | RegexOptions.ExplicitCapture); - - public double Precision { get; private set; } - public DistanceUnit Unit { get; private set; } + private static readonly Regex _distanceUnitRegex = + new Regex(@"^(?\d+(?:\.\d+)?)(?\D+)?$", RegexOptions.Compiled | RegexOptions.ExplicitCapture); public Distance(double distance) : this(distance, DistanceUnit.Meters) { } - public Distance(double distance, DistanceUnit unit) + public Distance(double distance, DistanceUnit unit) { - this.Precision = distance; - this.Unit = unit; + Precision = distance; + Unit = unit; } public Distance(string distanceUnit) @@ -32,35 +30,39 @@ public Distance(string distanceUnit) var precision = double.Parse(match.Groups["precision"].Value, NumberStyles.Any, CultureInfo.InvariantCulture); var unit = match.Groups["unit"].Value; - this.Precision = precision; + Precision = precision; if (string.IsNullOrEmpty(unit)) { - this.Unit = DistanceUnit.Meters; + Unit = DistanceUnit.Meters; return; } var unitMeasure = unit.ToEnum(); - if (unitMeasure == null) - { - throw new InvalidCastException($"cannot parse {typeof(DistanceUnit).Name} from string '{unit}'"); - } + if (unitMeasure == null) throw new InvalidCastException($"cannot parse {typeof(DistanceUnit).Name} from string '{unit}'"); - this.Unit = unitMeasure.Value; + Unit = unitMeasure.Value; } + public double Precision { get; private set; } + public DistanceUnit Unit { get; private set; } + public static Distance Inches(double inches) => new Distance(inches, DistanceUnit.Inch); + public static Distance Yards(double yards) => new Distance(yards, DistanceUnit.Yards); + public static Distance Miles(double miles) => new Distance(miles, DistanceUnit.Miles); + public static Distance Kilometers(double kilometers) => new Distance(kilometers, DistanceUnit.Kilometers); + public static Distance Meters(double meters) => new Distance(meters, DistanceUnit.Meters); + public static Distance Centimeters(double centimeters) => new Distance(centimeters, DistanceUnit.Centimeters); + public static Distance Millimeters(double millimeter) => new Distance(millimeter, DistanceUnit.Millimeters); + public static Distance NauticalMiles(double nauticalMiles) => new Distance(nauticalMiles, DistanceUnit.NauticalMiles); - - public static implicit operator Distance(string distanceUnit) - { - return new Distance(distanceUnit); - } + + public static implicit operator Distance(string distanceUnit) => new Distance(distanceUnit); } } diff --git a/src/Nest/CommonOptions/Geo/DistanceJsonConverter.cs b/src/Nest/CommonOptions/Geo/DistanceJsonConverter.cs index 9aa43bb19e3..21b810fe131 100644 --- a/src/Nest/CommonOptions/Geo/DistanceJsonConverter.cs +++ b/src/Nest/CommonOptions/Geo/DistanceJsonConverter.cs @@ -29,15 +29,13 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.String) return null; + var v = reader.Value as string; if (v == null) return null; return new Distance(v); } - public override bool CanConvert(Type objectType) - { - return true; - } + public override bool CanConvert(Type objectType) => true; } } diff --git a/src/Nest/CommonOptions/Geo/DistanceUnit.cs b/src/Nest/CommonOptions/Geo/DistanceUnit.cs index 2a1113eaeb4..5d3d90147ed 100644 --- a/src/Nest/CommonOptions/Geo/DistanceUnit.cs +++ b/src/Nest/CommonOptions/Geo/DistanceUnit.cs @@ -9,21 +9,29 @@ public enum DistanceUnit { [EnumMember(Value = "in")] Inch, + [EnumMember(Value = "ft")] Feet, + [EnumMember(Value = "yd")] Yards, + [EnumMember(Value = "mi")] Miles, + [EnumMember(Value = "nmi")] [AlternativeEnumMember("NM")] NauticalMiles, + [EnumMember(Value = "km")] Kilometers, + [EnumMember(Value = "m")] Meters, + [EnumMember(Value = "cm")] Centimeters, + [EnumMember(Value = "mm")] Millimeters } diff --git a/src/Nest/CommonOptions/Geo/GeoDistanceType.cs b/src/Nest/CommonOptions/Geo/GeoDistanceType.cs index fdd56c2ef57..0d31bb76ee8 100644 --- a/src/Nest/CommonOptions/Geo/GeoDistanceType.cs +++ b/src/Nest/CommonOptions/Geo/GeoDistanceType.cs @@ -9,6 +9,7 @@ public enum GeoDistanceType { [EnumMember(Value = "arc")] Arc, + [EnumMember(Value = "plane")] Plane } diff --git a/src/Nest/CommonOptions/Geo/GeoShapeRelation.cs b/src/Nest/CommonOptions/Geo/GeoShapeRelation.cs index 7a6be8b61de..d109d943898 100644 --- a/src/Nest/CommonOptions/Geo/GeoShapeRelation.cs +++ b/src/Nest/CommonOptions/Geo/GeoShapeRelation.cs @@ -9,10 +9,13 @@ public enum GeoShapeRelation { [EnumMember(Value = "intersects")] Intersects, + [EnumMember(Value = "disjoint")] Disjoint, + [EnumMember(Value = "within")] Within, + [EnumMember(Value = "contains")] Contains } diff --git a/src/Nest/CommonOptions/Hit/ShardStatistics.cs b/src/Nest/CommonOptions/Hit/ShardStatistics.cs index 3d5d034ffb1..43a14b165ac 100644 --- a/src/Nest/CommonOptions/Hit/ShardStatistics.cs +++ b/src/Nest/CommonOptions/Hit/ShardStatistics.cs @@ -7,17 +7,16 @@ namespace Nest [JsonObject] public class ShardStatistics { - [JsonProperty] - public int Total { get; internal set; } - - [JsonProperty] - public int Successful { get; internal set; } - [JsonProperty] public int Failed { get; internal set; } [JsonProperty("failures")] public IReadOnlyCollection Failures { get; internal set; } = EmptyReadOnly.Collection; + [JsonProperty] + public int Successful { get; internal set; } + + [JsonProperty] + public int Total { get; internal set; } } } diff --git a/src/Nest/CommonOptions/MinimumShouldMatch/MinimumShouldMatch.cs b/src/Nest/CommonOptions/MinimumShouldMatch/MinimumShouldMatch.cs index 88ff4f01fe6..5523a9af4cb 100644 --- a/src/Nest/CommonOptions/MinimumShouldMatch/MinimumShouldMatch.cs +++ b/src/Nest/CommonOptions/MinimumShouldMatch/MinimumShouldMatch.cs @@ -11,31 +11,32 @@ public MinimumShouldMatch(int count) : base(count) { } public MinimumShouldMatch(string percentage) : base(percentage) { } public static MinimumShouldMatch Fixed(int count) => count; + public static MinimumShouldMatch Percentage(double percentage) => $"{percentage}%"; public static implicit operator MinimumShouldMatch(string first) => new MinimumShouldMatch(first); + public static implicit operator MinimumShouldMatch(int second) => new MinimumShouldMatch(second); + public static implicit operator MinimumShouldMatch(double second) => Percentage(second); } - internal class MinimumShouldMatchJsonConverter :JsonConverter + internal class MinimumShouldMatchJsonConverter : JsonConverter { + public static UnionJsonConverter Unionconverter = new UnionJsonConverter(); public override bool CanRead => true; public override bool CanWrite => true; - public static UnionJsonConverter Unionconverter = new UnionJsonConverter(); - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var union = Unionconverter.ReadJson(reader, objectType, existingValue, serializer) as Union; if (union.Item1.HasValue) return new MinimumShouldMatch(union.Item1.Value); + return new MinimumShouldMatch(union.Item2); } - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => Unionconverter.WriteJson(writer, value, serializer); - } public override bool CanConvert(Type objectType) => true; } diff --git a/src/Nest/CommonOptions/Range/AggregationRange.cs b/src/Nest/CommonOptions/Range/AggregationRange.cs index e0a8adb08a2..ade6e0e16f3 100644 --- a/src/Nest/CommonOptions/Range/AggregationRange.cs +++ b/src/Nest/CommonOptions/Range/AggregationRange.cs @@ -1,11 +1,10 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Nest { /// - /// Range that defines a bucket for either the or - /// . If you are looking to store ranges as + /// Range that defines a bucket for either the or + /// . If you are looking to store ranges as /// part of your document please use explicit range class e.g DateRange, FloatRange etc /// [JsonObject(MemberSerialization = MemberSerialization.OptIn)] @@ -15,22 +14,22 @@ public interface IAggregationRange [JsonProperty("from")] double? From { get; set; } - [JsonProperty("to")] - double? To { get; set; } - [JsonProperty("key")] string Key { get; set; } + + [JsonProperty("to")] + double? To { get; set; } } - /// + /// public class AggregationRange : IAggregationRange { public double? From { get; set; } - public double? To { get; set; } public string Key { get; set; } + public double? To { get; set; } } - /// + /// public class AggregationRangeDescriptor : DescriptorBase, IAggregationRange { double? IAggregationRange.From { get; set; } @@ -38,7 +37,9 @@ public class AggregationRangeDescriptor : DescriptorBase Assign(a => a.Key = key); + public AggregationRangeDescriptor From(double? from) => Assign(a => a.From = from); + public AggregationRangeDescriptor To(double? to) => Assign(a => a.To = to); } } diff --git a/src/Nest/CommonOptions/Range/Ranges.cs b/src/Nest/CommonOptions/Range/Ranges.cs index d44d4edfad2..e023bdb0589 100644 --- a/src/Nest/CommonOptions/Range/Ranges.cs +++ b/src/Nest/CommonOptions/Range/Ranges.cs @@ -5,86 +5,91 @@ namespace Nest { public class DateRange { - [JsonProperty("gte")] - public DateTimeOffset? GreaterThanOrEqualTo { get; set; } - - [JsonProperty("lte")] - public DateTimeOffset? LessThanOrEqualTo { get; set; } - [JsonProperty("gt")] public DateTimeOffset? GreaterThan { get; set; } + [JsonProperty("gte")] + public DateTimeOffset? GreaterThanOrEqualTo { get; set; } + [JsonProperty("lt")] public DateTimeOffset? LessThan { get; set; } - } - public class DoubleRange - { - [JsonProperty("gte")] - public double? GreaterThanOrEqualTo { get; set; } [JsonProperty("lte")] - public double? LessThanOrEqualTo { get; set; } + public DateTimeOffset? LessThanOrEqualTo { get; set; } + } + public class DoubleRange + { [JsonProperty("gt")] public double? GreaterThan { get; set; } + [JsonProperty("gte")] + public double? GreaterThanOrEqualTo { get; set; } + [JsonProperty("lt")] public double? LessThan { get; set; } - } - public class FloatRange - { - [JsonProperty("gte")] - public float? GreaterThanOrEqualTo { get; set; } [JsonProperty("lte")] - public float? LessThanOrEqualTo { get; set; } + public double? LessThanOrEqualTo { get; set; } + } + public class FloatRange + { [JsonProperty("gt")] public float? GreaterThan { get; set; } + [JsonProperty("gte")] + public float? GreaterThanOrEqualTo { get; set; } + [JsonProperty("lt")] public float? LessThan { get; set; } - } - public class IntegerRange - { - [JsonProperty("gte")] - public int? GreaterThanOrEqualTo { get; set; } [JsonProperty("lte")] - public int? LessThanOrEqualTo { get; set; } + public float? LessThanOrEqualTo { get; set; } + } + public class IntegerRange + { [JsonProperty("gt")] public int? GreaterThan { get; set; } + [JsonProperty("gte")] + public int? GreaterThanOrEqualTo { get; set; } + [JsonProperty("lt")] public int? LessThan { get; set; } - } - public class LongRange - { - [JsonProperty("gte")] - public long? GreaterThanOrEqualTo { get; set; } [JsonProperty("lte")] - public long? LessThanOrEqualTo { get; set; } + public int? LessThanOrEqualTo { get; set; } + } + public class LongRange + { [JsonProperty("gt")] public long? GreaterThan { get; set; } + [JsonProperty("gte")] + public long? GreaterThanOrEqualTo { get; set; } + [JsonProperty("lt")] public long? LessThan { get; set; } - } - public class IpAddressRange - { - [JsonProperty("gte")] - public string GreaterThanOrEqualTo { get; set; } [JsonProperty("lte")] - public string LessThanOrEqualTo { get; set; } + public long? LessThanOrEqualTo { get; set; } + } + public class IpAddressRange + { [JsonProperty("gt")] public string GreaterThan { get; set; } + [JsonProperty("gte")] + public string GreaterThanOrEqualTo { get; set; } + [JsonProperty("lt")] public string LessThan { get; set; } + + [JsonProperty("lte")] + public string LessThanOrEqualTo { get; set; } } } diff --git a/src/Nest/CommonOptions/Scripting/IndexedScript.cs b/src/Nest/CommonOptions/Scripting/IndexedScript.cs index d43d5e9b78d..0376790e25d 100644 --- a/src/Nest/CommonOptions/Scripting/IndexedScript.cs +++ b/src/Nest/CommonOptions/Scripting/IndexedScript.cs @@ -11,10 +11,7 @@ public interface IIndexedScript : IScript public class IndexedScript : ScriptBase, IIndexedScript { - public IndexedScript(string id) - { - this.Id = id; - } + public IndexedScript(string id) => Id = id; public string Id { get; set; } } @@ -22,14 +19,11 @@ public IndexedScript(string id) public class IndexedScriptDescriptor : ScriptDescriptorBase, IIndexedScript { - string IIndexedScript.Id { get; set; } + public IndexedScriptDescriptor() { } - public IndexedScriptDescriptor() {} + public IndexedScriptDescriptor(string id) => Self.Id = id; - public IndexedScriptDescriptor(string id) - { - Self.Id = id; - } + string IIndexedScript.Id { get; set; } public IndexedScriptDescriptor Id(string id) => Assign(a => a.Id = id); } diff --git a/src/Nest/CommonOptions/Scripting/InlineScript.cs b/src/Nest/CommonOptions/Scripting/InlineScript.cs index 663b2621e70..c37fdbe8262 100644 --- a/src/Nest/CommonOptions/Scripting/InlineScript.cs +++ b/src/Nest/CommonOptions/Scripting/InlineScript.cs @@ -6,20 +6,25 @@ namespace Nest [JsonObject(MemberSerialization = MemberSerialization.OptIn)] public interface IInlineScript : IScript { - [JsonProperty("source")] - string Source { get; set; } - [Obsolete("Use Source. Inline is deprecated and scheduled to be removed in Elasticsearch 7.0")] [JsonIgnore] string Inline { get; set; } + + [JsonProperty("source")] + string Source { get; set; } } public class InlineScript : ScriptBase, IInlineScript { - public InlineScript(string script) => this.Source = script; + public InlineScript(string script) => Source = script; + + public string Inline + { + get => Source; + set => Source = value; + } public string Source { get; set; } - public string Inline { get => this.Source; set => this.Source = value; } public static implicit operator InlineScript(string script) => new InlineScript(script); } @@ -27,13 +32,18 @@ public class InlineScript : ScriptBase, IInlineScript public class InlineScriptDescriptor : ScriptDescriptorBase, IInlineScript { - string IInlineScript.Inline { get => Self.Source; set => Self.Source = value; } - string IInlineScript.Source { get; set; } - public InlineScriptDescriptor() { } public InlineScriptDescriptor(string script) => Self.Source = script; + string IInlineScript.Inline + { + get => Self.Source; + set => Self.Source = value; + } + + string IInlineScript.Source { get; set; } + [Obsolete("Use Source(). Inline() is deprecated and scheduled to be removed in Elasticsearch 7.0")] public InlineScriptDescriptor Inline(string script) => Assign(a => a.Source = script); diff --git a/src/Nest/CommonOptions/Scripting/ScriptBase.cs b/src/Nest/CommonOptions/Scripting/ScriptBase.cs index d313511b229..afb5c8403e5 100644 --- a/src/Nest/CommonOptions/Scripting/ScriptBase.cs +++ b/src/Nest/CommonOptions/Scripting/ScriptBase.cs @@ -10,33 +10,31 @@ namespace Nest public interface IScript { /// - /// Scripts are compiled and cached for faster execution. - /// If the same script can be used, just with different parameters provided, - /// it is preferable to use the ability to pass parameters to the script itself. + /// Language of script. + /// + /// language + /// this + [JsonProperty("lang")] + string Lang { get; set; } + + /// + /// Scripts are compiled and cached for faster execution. + /// If the same script can be used, just with different parameters provided, + /// it is preferable to use the ability to pass parameters to the script itself. /// /// - /// script: "doc['num1'].value > param1" - /// param: "param1" = 5 + /// script: "doc['num1'].value > param1" + /// param: "param1" = 5 /// /// param /// this [JsonProperty("params")] [JsonConverter(typeof(VerbatimDictionaryKeysPreservingNullJsonConverter))] Dictionary Params { get; set; } - - /// - /// Language of script. - /// - /// language - /// this - [JsonProperty("lang")] - string Lang { get; set; } } public abstract class ScriptBase : IScript { - public Dictionary Params { get; set; } - /// /// Language of script. /// @@ -44,8 +42,10 @@ public abstract class ScriptBase : IScript /// this public string Lang { get; set; } + public Dictionary Params { get; set; } + /// - /// Implicit conversion from to + /// Implicit conversion from to /// public static implicit operator ScriptBase(string script) => new InlineScript(script); } @@ -54,30 +54,30 @@ public abstract class ScriptDescriptorBase : Descriptor where TDescriptor : ScriptDescriptorBase, TInterface, IScript where TInterface : class, IScript { - Dictionary IScript.Params { get; set; } string IScript.Lang { get; set; } + Dictionary IScript.Params { get; set; } /// - /// Scripts are compiled and cached for faster execution. - /// If the same script can be used, just with different parameters provided, - /// it is preferable to use the ability to pass parameters to the script itself. + /// Scripts are compiled and cached for faster execution. + /// If the same script can be used, just with different parameters provided, + /// it is preferable to use the ability to pass parameters to the script itself. /// /// - /// script: "doc['num1'].value > param1" - /// param: "param1" = 5 + /// script: "doc['num1'].value > param1" + /// param: "param1" = 5 /// /// param /// this public TDescriptor Params(Dictionary scriptParams) => Assign(a => a.Params = scriptParams); /// - /// Scripts are compiled and cached for faster execution. - /// If the same script can be used, just with different parameters provided, - /// it is preferable to use the ability to pass parameters to the script itself. + /// Scripts are compiled and cached for faster execution. + /// If the same script can be used, just with different parameters provided, + /// it is preferable to use the ability to pass parameters to the script itself. /// /// - /// script: "doc['num1'].value > param1" - /// param: "param1" = 5 + /// script: "doc['num1'].value > param1" + /// param: "param1" = 5 /// /// param /// this diff --git a/src/Nest/CommonOptions/Scripting/ScriptFields.cs b/src/Nest/CommonOptions/Scripting/ScriptFields.cs index 0b5a042eedf..55f16872c9c 100644 --- a/src/Nest/CommonOptions/Scripting/ScriptFields.cs +++ b/src/Nest/CommonOptions/Scripting/ScriptFields.cs @@ -32,14 +32,16 @@ public interface IScriptFields : IIsADictionary { } public class ScriptFields : IsADictionaryBase, IScriptFields { - public ScriptFields() {} + public ScriptFields() { } + public ScriptFields(IDictionary container) : base(container) { } + public ScriptFields(Dictionary container) - : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) - {} + : base(container.Select(kv => kv).ToDictionary(kv => kv.Key, kv => kv.Value)) { } + + public void Add(string name, IScriptField script) => BackingDictionary.Add(name, script); - public void Add(string name, IScriptField script) => this.BackingDictionary.Add(name, script); - public void Add(string name, IScript script) => this.BackingDictionary.Add(name, new ScriptField { Script = script }); + public void Add(string name, IScript script) => BackingDictionary.Add(name, new ScriptField { Script = script }); } public class ScriptFieldsDescriptor : IsADictionaryDescriptorBase diff --git a/src/Nest/CommonOptions/Scripting/ScriptJsonConverter.cs b/src/Nest/CommonOptions/Scripting/ScriptJsonConverter.cs index 5dc1cae788b..227ca471cf1 100644 --- a/src/Nest/CommonOptions/Scripting/ScriptJsonConverter.cs +++ b/src/Nest/CommonOptions/Scripting/ScriptJsonConverter.cs @@ -8,10 +8,11 @@ namespace Nest { internal class ScriptJsonConverter : JsonConverter { - public override bool CanConvert(Type objectType) => typeof(IScript).IsAssignableFrom(objectType); public override bool CanRead => true; public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => typeof(IScript).IsAssignableFrom(objectType); + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var o = JObject.Load(reader); diff --git a/src/Nest/CommonOptions/Sorting/SortJsonConverter.cs b/src/Nest/CommonOptions/Sorting/SortJsonConverter.cs index f1b8df00523..c964b28ae4b 100644 --- a/src/Nest/CommonOptions/Sorting/SortJsonConverter.cs +++ b/src/Nest/CommonOptions/Sorting/SortJsonConverter.cs @@ -10,6 +10,7 @@ internal class SortJsonConverter : ReserializeJsonConverter { public override bool CanRead => true; public override bool CanWrite => true; + public override bool CanConvert(Type objectType) => typeof(ISort).IsAssignableFrom(objectType); public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) @@ -28,7 +29,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist var s = FromJson.ReadAs(r, serializer); s.Field = geoLocationProp.Name; using (var rr = geoLocationProp.Value.CreateReader()) - s.Points =FromJson.ReadAs>(rr, serializer); + s.Points = FromJson.ReadAs>(rr, serializer); sort = s; } } @@ -61,12 +62,12 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s { case "_script": writer.WritePropertyName("_script"); - base.Reserialize(writer, s, serializer); + Reserialize(writer, s, serializer); break; case "_geo_distance": var geo = s as IGeoDistanceSort; writer.WritePropertyName(geo.SortKey.Name); - base.Reserialize(writer, s, serializer, w => + Reserialize(writer, s, serializer, w => { writer.WritePropertyName(settings.Inferrer.Field(geo.Field)); serializer.Serialize(writer, geo.Points); @@ -74,7 +75,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s break; default: writer.WritePropertyName(settings.Inferrer.Field(s.SortKey)); - base.Reserialize(writer, s, serializer); + Reserialize(writer, s, serializer); break; } writer.WriteEndObject(); diff --git a/src/Nest/CommonOptions/Stats/FieldDataStats.cs b/src/Nest/CommonOptions/Stats/FieldDataStats.cs index 1ff2306ab1d..1bcb570c7b4 100644 --- a/src/Nest/CommonOptions/Stats/FieldDataStats.cs +++ b/src/Nest/CommonOptions/Stats/FieldDataStats.cs @@ -10,8 +10,8 @@ public class FielddataStats [JsonProperty("memory_size")] public string MemorySize { get; set; } + [JsonProperty("memory_size_in_bytes")] public long MemorySizeInBytes { get; set; } - } } diff --git a/src/Nest/CommonOptions/Stats/FlushStats.cs b/src/Nest/CommonOptions/Stats/FlushStats.cs index f2527ff5d15..5e5f0b62db4 100644 --- a/src/Nest/CommonOptions/Stats/FlushStats.cs +++ b/src/Nest/CommonOptions/Stats/FlushStats.cs @@ -5,16 +5,15 @@ namespace Nest [JsonObject] public class FlushStats { - - [JsonProperty("total")] - public long Total { get; set; } - /// /// The number of flushes that were periodically triggered when translog exceeded the flush threshold. /// [JsonProperty("periodic")] public long Periodic { get; set; } + [JsonProperty("total")] + public long Total { get; set; } + /// /// The total time merges have been executed. /// @@ -26,6 +25,5 @@ public class FlushStats /// [JsonProperty("total_time_in_millis")] public long TotalTimeInMilliseconds { get; set; } - } } diff --git a/src/Nest/CommonOptions/Stats/GetStats.cs b/src/Nest/CommonOptions/Stats/GetStats.cs index 4985a9f4036..19ecbcd3851 100644 --- a/src/Nest/CommonOptions/Stats/GetStats.cs +++ b/src/Nest/CommonOptions/Stats/GetStats.cs @@ -10,6 +10,7 @@ public class GetStats [JsonProperty("exists_time")] public string ExistsTime { get; set; } + [JsonProperty("exists_time_in_millis")] public long ExistsTimeInMilliseconds { get; set; } @@ -18,6 +19,7 @@ public class GetStats [JsonProperty("missing_time")] public string MissingTime { get; set; } + [JsonProperty("missing_time_in_millis")] public long MissingTimeInMilliseconds { get; set; } @@ -26,11 +28,11 @@ public class GetStats [JsonProperty("time")] public string Time { get; set; } + [JsonProperty("time_in_millis")] public long TimeInMilliseconds { get; set; } [JsonProperty("total")] public long Total { get; set; } - } } diff --git a/src/Nest/CommonOptions/Stats/IndexingStats.cs b/src/Nest/CommonOptions/Stats/IndexingStats.cs index 9d6d8a22750..98134c7b6af 100644 --- a/src/Nest/CommonOptions/Stats/IndexingStats.cs +++ b/src/Nest/CommonOptions/Stats/IndexingStats.cs @@ -6,6 +6,9 @@ namespace Nest [JsonObject] public class IndexingStats { + [JsonProperty("index_current")] + public long Current { get; set; } + [JsonProperty("delete_current")] public long DeleteCurrent { get; set; } @@ -18,18 +21,6 @@ public class IndexingStats [JsonProperty("delete_total")] public long DeleteTotal { get; set; } - [JsonProperty("index_current")] - public long Current { get; set; } - - [JsonProperty("index_time")] - public string Time { get; set; } - - [JsonProperty("index_time_in_millis")] - public long TimeInMilliseconds { get; set; } - - [JsonProperty("index_total")] - public long Total { get; set; } - [JsonProperty("is_throttled")] public bool IsThrottled { get; set; } @@ -42,6 +33,15 @@ public class IndexingStats [JsonProperty("throttle_time_in_millis")] public long ThrottleTimeInMilliseconds { get; set; } + [JsonProperty("index_time")] + public string Time { get; set; } + + [JsonProperty("index_time_in_millis")] + public long TimeInMilliseconds { get; set; } + + [JsonProperty("index_total")] + public long Total { get; set; } + [JsonProperty("types")] [JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))] public IReadOnlyDictionary Types { get; set; } diff --git a/src/Nest/CommonOptions/Stats/MergesStats.cs b/src/Nest/CommonOptions/Stats/MergesStats.cs index 3cd6d182bc8..1e37d52fe23 100644 --- a/src/Nest/CommonOptions/Stats/MergesStats.cs +++ b/src/Nest/CommonOptions/Stats/MergesStats.cs @@ -5,7 +5,6 @@ namespace Nest [JsonObject] public class MergesStats { - [JsonProperty("current")] public long Current { get; set; } @@ -14,6 +13,7 @@ public class MergesStats [JsonProperty("current_size")] public string CurrentSize { get; set; } + [JsonProperty("current_size_in_bytes")] public long CurrentSizeInBytes { get; set; } @@ -22,6 +22,7 @@ public class MergesStats [JsonProperty("total_auto_throttle")] public string TotalAutoThrottle { get; set; } + [JsonProperty("total_auto_throttle_in_bytes")] public long TotalAutoThrottleInBytes { get; set; } @@ -30,21 +31,25 @@ public class MergesStats [JsonProperty("total_size")] public string TotalSize { get; set; } + [JsonProperty("total_size_in_bytes")] public string TotalSizeInBytes { get; set; } [JsonProperty("total_stopped_time")] public string TotalStoppedTime { get; set; } + [JsonProperty("total__stopped_time_in_millis")] public long TotalStoppedTimeInMilliseconds { get; set; } [JsonProperty("total_throttled_time")] public string TotalThrottledTime { get; set; } + [JsonProperty("total_throttled_time_in_millis")] public long TotalThrottledTimeInMilliseconds { get; set; } [JsonProperty("total_time")] public string TotalTime { get; set; } + [JsonProperty("total_time_in_millis")] public long TotalTimeInMilliseconds { get; set; } } diff --git a/src/Nest/CommonOptions/Stats/PluginStats.cs b/src/Nest/CommonOptions/Stats/PluginStats.cs index 0bbd718d1b9..388a47890d1 100644 --- a/src/Nest/CommonOptions/Stats/PluginStats.cs +++ b/src/Nest/CommonOptions/Stats/PluginStats.cs @@ -5,25 +5,25 @@ namespace Nest [JsonObject] public class PluginStats { - [JsonProperty("name")] - public string Name { get; set; } - - [JsonProperty("version")] - public string Version { get; set; } + [JsonProperty("classname")] + public string ClassName { get; set; } [JsonProperty("description")] public string Description { get; set; } - [JsonProperty("classname")] - public string ClassName { get; set; } + [JsonProperty("isolated")] + public bool Isolated { get; set; } [JsonProperty("jvm")] public bool Jvm { get; set; } - [JsonProperty("isolated")] - public bool Isolated { get; set; } + [JsonProperty("name")] + public string Name { get; set; } [JsonProperty("site")] public bool Site { get; set; } + + [JsonProperty("version")] + public string Version { get; set; } } } diff --git a/src/Nest/CommonOptions/Stats/QueryCacheStats.cs b/src/Nest/CommonOptions/Stats/QueryCacheStats.cs index 2c8037ed1d1..90e83128367 100644 --- a/src/Nest/CommonOptions/Stats/QueryCacheStats.cs +++ b/src/Nest/CommonOptions/Stats/QueryCacheStats.cs @@ -5,28 +5,28 @@ namespace Nest [JsonObject] public class QueryCacheStats { - [JsonProperty("memory_size")] - public string MemorySize { get; set; } - [JsonProperty("memory_size_in_bytes")] - public long MemorySizeInBytes { get; set; } + [JsonProperty("cache_count")] + public long CacheCount { get; set; } - [JsonProperty("total_count")] - public long TotalCount { get; set; } + [JsonProperty("cache_size")] + public long CacheSize { get; set; } + + [JsonProperty("evictions")] + public long Evictions { get; set; } [JsonProperty("hit_count")] public long HitCount { get; set; } - [JsonProperty("miss_count")] - public long MissCount { get; set; } - - [JsonProperty("cache_size")] - public long CacheSize { get; set; } + [JsonProperty("memory_size")] + public string MemorySize { get; set; } - [JsonProperty("cache_count")] - public long CacheCount { get; set; } + [JsonProperty("memory_size_in_bytes")] + public long MemorySizeInBytes { get; set; } - [JsonProperty("evictions")] - public long Evictions { get; set; } + [JsonProperty("miss_count")] + public long MissCount { get; set; } + [JsonProperty("total_count")] + public long TotalCount { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonOptions/Stats/RecoveryStats.cs b/src/Nest/CommonOptions/Stats/RecoveryStats.cs index db2ea812c46..62d82deedcc 100644 --- a/src/Nest/CommonOptions/Stats/RecoveryStats.cs +++ b/src/Nest/CommonOptions/Stats/RecoveryStats.cs @@ -16,6 +16,5 @@ public class RecoveryStats [JsonProperty("throttle_time_in_millis")] public long ThrottleTimeInMilliseconds { get; set; } - } } diff --git a/src/Nest/CommonOptions/Stats/RefreshStats.cs b/src/Nest/CommonOptions/Stats/RefreshStats.cs index 148a85982c6..f59a92d85d6 100644 --- a/src/Nest/CommonOptions/Stats/RefreshStats.cs +++ b/src/Nest/CommonOptions/Stats/RefreshStats.cs @@ -5,14 +5,13 @@ namespace Nest [JsonObject] public class RefreshStats { - [JsonProperty("total")] public long Total { get; set; } [JsonProperty("total_time")] public string TotalTime { get; set; } + [JsonProperty("total_time_in_millis")] public long TotalTimeInMilliseconds { get; set; } - } } diff --git a/src/Nest/CommonOptions/Stats/RequestCacheStats.cs b/src/Nest/CommonOptions/Stats/RequestCacheStats.cs index 3e5f3a8907f..fcc606c6529 100644 --- a/src/Nest/CommonOptions/Stats/RequestCacheStats.cs +++ b/src/Nest/CommonOptions/Stats/RequestCacheStats.cs @@ -12,13 +12,12 @@ public class RequestCacheStats public long HitCount { get; set; } [JsonProperty("memory_size")] - public string MemorySize{ get; set; } + public string MemorySize { get; set; } [JsonProperty("memory_size_in_bytes")] public long MemorySizeInBytes { get; set; } [JsonProperty("miss_count")] public long MissCount { get; set; } - } -} \ No newline at end of file +} diff --git a/src/Nest/CommonOptions/Stats/SearchStats.cs b/src/Nest/CommonOptions/Stats/SearchStats.cs index 24dce92911b..92c8270ada0 100644 --- a/src/Nest/CommonOptions/Stats/SearchStats.cs +++ b/src/Nest/CommonOptions/Stats/SearchStats.cs @@ -5,9 +5,6 @@ namespace Nest [JsonObject] public class SearchStats { - [JsonProperty("open_contexts")] - public long OpenContexts { get; set; } - [JsonProperty("fetch_current")] public long FetchCurrent { get; set; } @@ -17,6 +14,9 @@ public class SearchStats [JsonProperty("fetch_total")] public long FetchTotal { get; set; } + [JsonProperty("open_contexts")] + public long OpenContexts { get; set; } + [JsonProperty("query_current")] public long QueryCurrent { get; set; } diff --git a/src/Nest/CommonOptions/Stats/SegmentsStats.cs b/src/Nest/CommonOptions/Stats/SegmentsStats.cs index b269e55a98c..6c954401e62 100644 --- a/src/Nest/CommonOptions/Stats/SegmentsStats.cs +++ b/src/Nest/CommonOptions/Stats/SegmentsStats.cs @@ -10,58 +10,68 @@ public class SegmentsStats [JsonProperty("doc_values_memory")] public string DocValuesMemory { get; set; } + [JsonProperty("doc_values_memory_in_bytes")] public long DocValuesMemoryInBytes { get; set; } [JsonProperty("fixed_bit_set_memory")] public string FixedBitSetMemory { get; set; } + [JsonProperty("fixed_bit_set_memory_in_bytes")] public long FixedBitSetMemoryInBytes { get; set; } [JsonProperty("index_writer_max_memory")] public string IndexWriterMaxMemory { get; set; } + [JsonProperty("index_writer_max_memory_in_bytes")] public long IndexWriterMaxMemoryInBytes { get; set; } [JsonProperty("index_writer_memory")] public string IndexWriterMemory { get; set; } + [JsonProperty("index_writer_memory_in_bytes")] public long IndexWriterMemoryInBytes { get; set; } [JsonProperty("memory")] public string Memory { get; set; } + [JsonProperty("memory_in_bytes")] public long MemoryInBytes { get; set; } [JsonProperty("norms_memory")] public string NormsMemory { get; set; } + [JsonProperty("norms_memory_in_bytes")] public long NormsMemoryInBytes { get; set; } [JsonProperty("points_memory")] public string PointsMemory { get; set; } + [JsonProperty("points_memory_in_bytes")] public long PointsMemoryInBytes { get; set; } [JsonProperty("stored_fields_memory")] public string StoredFieldsMemory { get; set; } + [JsonProperty("stored_fields_memory_in_bytes")] public long StoredFieldsMemoryInBytes { get; set; } - [JsonProperty("term_vectors_memory")] - public string TermVectorsMemory { get; set; } - [JsonProperty("term_vectors_memory_in_bytes")] - public long TermVectorsMemoryInBytes { get; set; } - [JsonProperty("terms_memory")] public string TermsMemory { get; set; } + [JsonProperty("terms_memory_in_bytes")] public long TermsMemoryInBytes { get; set; } + [JsonProperty("term_vectors_memory")] + public string TermVectorsMemory { get; set; } + + [JsonProperty("term_vectors_memory_in_bytes")] + public long TermVectorsMemoryInBytes { get; set; } + [JsonProperty("version_map_memory")] public string VersionMapMemory { get; set; } + [JsonProperty("version_map_memory_in_bytes")] public long VersionMapMemoryInBytes { get; set; } - } } diff --git a/src/Nest/CommonOptions/Stats/StoreStats.cs b/src/Nest/CommonOptions/Stats/StoreStats.cs index e64bf2fae02..3df530d5ff4 100644 --- a/src/Nest/CommonOptions/Stats/StoreStats.cs +++ b/src/Nest/CommonOptions/Stats/StoreStats.cs @@ -10,7 +10,5 @@ public class StoreStats [JsonProperty("size_in_bytes")] public double SizeInBytes { get; set; } - } - } diff --git a/src/Nest/CommonOptions/Stats/TranslogStats.cs b/src/Nest/CommonOptions/Stats/TranslogStats.cs index ebb4ee93f37..f941ead2e91 100644 --- a/src/Nest/CommonOptions/Stats/TranslogStats.cs +++ b/src/Nest/CommonOptions/Stats/TranslogStats.cs @@ -5,28 +5,28 @@ namespace Nest [JsonObject] public class TranslogStats { - [JsonProperty("operations")] - public long Operations { get; set; } + /// + /// Valid only for Elasticsearch 6.3.0+ + /// + [JsonProperty("earliest_last_modified_age")] + public long EarliestLastModifiedAge { get; set; } - [JsonProperty("uncommitted_operations")] - public int UncommittedOperations { get; set; } + [JsonProperty("operations")] + public long Operations { get; set; } [JsonProperty("size")] public string Size { get; set; } [JsonProperty("size_in_bytes")] - public long SizeInBytes { get; set; } + public long SizeInBytes { get; set; } + + [JsonProperty("uncommitted_operations")] + public int UncommittedOperations { get; set; } [JsonProperty("uncommitted_size")] public string UncommittedSize { get; set; } [JsonProperty("uncommitted_size_in_bytes")] - public long UncommittedSizeInBytes { get; set; } - - /// - /// Valid only for Elasticsearch 6.3.0+ - /// - [JsonProperty("earliest_last_modified_age")] - public long EarliestLastModifiedAge { get; set; } + public long UncommittedSizeInBytes { get; set; } } } diff --git a/src/Nest/CommonOptions/Stats/WarmerStats.cs b/src/Nest/CommonOptions/Stats/WarmerStats.cs index 561ff91630a..3defd5a8546 100644 --- a/src/Nest/CommonOptions/Stats/WarmerStats.cs +++ b/src/Nest/CommonOptions/Stats/WarmerStats.cs @@ -17,4 +17,4 @@ public class WarmerStats [JsonProperty("total_time_in_millis")] public long TotalTimeInMilliseconds { get; set; } } -} \ No newline at end of file +} diff --git a/src/Nest/CommonOptions/TimeUnit/Time.cs b/src/Nest/CommonOptions/TimeUnit/Time.cs index 2d80a88156b..afded2dcfb4 100644 --- a/src/Nest/CommonOptions/TimeUnit/Time.cs +++ b/src/Nest/CommonOptions/TimeUnit/Time.cs @@ -12,18 +12,16 @@ namespace Nest [JsonConverter(typeof(TimeJsonConverter))] public class Time : IComparable