From 54bfe83aea205473c9dec4473f446e30ebc8be83 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Fri, 21 Feb 2020 10:22:10 +0100 Subject: [PATCH] Update documentation on 7.6 (#4399) * add IntervalsFuzzy as known replace (cherry picked from commit 0a59eb9b4d65d6c4ff9b5cd07b63dea9905259d5) * update docs on 7.6 --- docs/aggregations.asciidoc | 4 ++ .../metric/min/min-aggregation-usage.asciidoc | 6 +- .../string-stats-aggregation-usage.asciidoc | 60 +++++++++++++++++++ .../extending-nest-types.asciidoc | 1 + .../serialization/formatters.asciidoc | 54 +++++++++++++++++ .../intervals/intervals-usage.asciidoc | 58 ++++++++++++++++++ src/DocGenerator/StringExtensions.cs | 1 + 7 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 docs/aggregations/metric/string-stats/string-stats-aggregation-usage.asciidoc diff --git a/docs/aggregations.asciidoc b/docs/aggregations.asciidoc index 5940f19b27c..4310c3c92ca 100644 --- a/docs/aggregations.asciidoc +++ b/docs/aggregations.asciidoc @@ -58,6 +58,8 @@ The values are typically extracted from the fields of the document (using the fi * <> +* <> + * <> * <> @@ -94,6 +96,8 @@ include::aggregations/metric/scripted-metric/scripted-metric-aggregation-usage.a include::aggregations/metric/stats/stats-aggregation-usage.asciidoc[] +include::aggregations/metric/string-stats/string-stats-aggregation-usage.asciidoc[] + include::aggregations/metric/sum/sum-aggregation-usage.asciidoc[] include::aggregations/metric/top-hits/top-hits-aggregation-usage.asciidoc[] diff --git a/docs/aggregations/metric/min/min-aggregation-usage.asciidoc b/docs/aggregations/metric/min/min-aggregation-usage.asciidoc index 68937d819e3..5a2ff62f7ec 100644 --- a/docs/aggregations/metric/min/min-aggregation-usage.asciidoc +++ b/docs/aggregations/metric/min/min-aggregation-usage.asciidoc @@ -22,6 +22,7 @@ please modify the original csharp file found at the link and submit the PR with a => a .Min("min_last_activity", m => m .Field(p => p.LastActivity) + .Format("yyyy") ) ---- @@ -29,7 +30,7 @@ a => a [source,csharp] ---- -new MinAggregation("min_last_activity", Field(p => p.LastActivity)) +new MinAggregation("min_last_activity", Field(p => p.LastActivity)) { Format = "yyyy" } ---- [source,javascript] @@ -38,7 +39,8 @@ new MinAggregation("min_last_activity", Field(p => p.LastActivity)) { "min_last_activity": { "min": { - "field": "lastActivity" + "field": "lastActivity", + "format": "yyyy" } } } diff --git a/docs/aggregations/metric/string-stats/string-stats-aggregation-usage.asciidoc b/docs/aggregations/metric/string-stats/string-stats-aggregation-usage.asciidoc new file mode 100644 index 00000000000..f676dd11d1f --- /dev/null +++ b/docs/aggregations/metric/string-stats/string-stats-aggregation-usage.asciidoc @@ -0,0 +1,60 @@ +:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/7.5 + +:github: https://github.com/elastic/elasticsearch-net + +:nuget: https://www.nuget.org/packages + +//// +IMPORTANT NOTE +============== +This file has been generated from https://github.com/elastic/elasticsearch-net/tree/7.x/src/Tests/Tests/Aggregations/Metric/StringStats/StringStatsAggregationUsageTests.cs. +If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file, +please modify the original csharp file found at the link and submit the PR with that change. Thanks! +//// + +[[string-stats-aggregation-usage]] +=== String Stats Aggregation Usage + +==== Fluent DSL example + +[source,csharp] +---- +a => a +.StringStats("name_stats", st => st + .Field(p => p.Name) +) +---- + +==== Object Initializer syntax example + +[source,csharp] +---- +new StringStatsAggregation("name_stats", Field(p => p.Name)) +---- + +[source,javascript] +.Example json output +---- +{ + "name_stats": { + "string_stats": { + "field": "name" + } + } +} +---- + +==== Handling Responses + +[source,csharp] +---- +response.ShouldBeValid(); +var commitStats = response.Aggregations.StringStats("name_stats"); +commitStats.Should().NotBeNull(); +commitStats.AverageLength.Should().BeGreaterThan(0); +commitStats.MaxLength.Should().BeGreaterThan(0); +commitStats.MinLength.Should().BeGreaterThan(0); +commitStats.Count.Should().BeGreaterThan(0); +commitStats.Distribution.Should().NotBeNull().And.BeEmpty(); +---- + diff --git a/docs/client-concepts/high-level/serialization/extending-nest-types.asciidoc b/docs/client-concepts/high-level/serialization/extending-nest-types.asciidoc index c4cda1b30ba..53fa684f4c7 100644 --- a/docs/client-concepts/high-level/serialization/extending-nest-types.asciidoc +++ b/docs/client-concepts/high-level/serialization/extending-nest-types.asciidoc @@ -31,6 +31,7 @@ type with NEST. public class MyPluginProperty : IProperty { IDictionary IProperty.LocalMetadata { get; set; } + IDictionary IProperty.Meta { get; set; } public string Type { get; set; } = "my_plugin_property"; public PropertyName Name { get; set; } diff --git a/docs/code-standards/serialization/formatters.asciidoc b/docs/code-standards/serialization/formatters.asciidoc index cc89de492c0..f5114d83405 100644 --- a/docs/code-standards/serialization/formatters.asciidoc +++ b/docs/code-standards/serialization/formatters.asciidoc @@ -28,5 +28,59 @@ foreach (var formatter in formatters) visible.Add(formatter.Name); } visible.Should().BeEmpty(); + +Type GetFormatterTargetType(Type t) +{ + var attribute = t.GetCustomAttribute(); + + if (attribute == null) + return null; + + var formatterType = attribute.FormatterType; + + if (formatterType.IsGenericType && !formatterType.IsConstructedGenericType) + return null; + + return formatterType.GetInterfaces() + .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IJsonFormatter<>)) + .Select(i => i.GetGenericArguments()[0]) + .Single(); +} + +var typesAndProperties = + from t in typeof(IElasticClient).Assembly.GetTypes().Concat(typeof(IElasticLowLevelClient).Assembly.GetTypes()) + let p = t.GetProperties() + let typeHasFormatter = t.GetCustomAttribute(false) != null + let propertiesHaveFormatter = p.Any(pp => pp.GetCustomAttribute(false) != null) + where typeHasFormatter || propertiesHaveFormatter + select new { Type = t, TypeHasFormatter = typeHasFormatter, Properties = p, PropertiesHaveFormatter = propertiesHaveFormatter }; + +var invalid = new List(); + +foreach (var typeAndProperties in typesAndProperties) +{ + if (typeAndProperties.TypeHasFormatter) + { + var t = typeAndProperties.Type; + var f = GetFormatterTargetType(t); + + if (f != null && t != f) + invalid.Add($"{t.FullName} has IJsonFormatter<{f.FullName}>"); + } + + if (typeAndProperties.PropertiesHaveFormatter) + { + foreach (var property in typeAndProperties.Properties) + { + var t = property.PropertyType; + var f = GetFormatterTargetType(t); + + if (f != null && t != f) + invalid.Add($"property {property.Name} on {typeAndProperties.Type.FullName} has IJsonFormatter<{f.FullName}>"); + } + } +} + +invalid.Should().BeEmpty(); ---- diff --git a/docs/query-dsl/full-text/intervals/intervals-usage.asciidoc b/docs/query-dsl/full-text/intervals/intervals-usage.asciidoc index 2cc3c2712fe..e8779ef8263 100644 --- a/docs/query-dsl/full-text/intervals/intervals-usage.asciidoc +++ b/docs/query-dsl/full-text/intervals/intervals-usage.asciidoc @@ -249,3 +249,61 @@ new IntervalsQuery } ---- +[float] +=== Fuzzy rules + +Fuzzy rules can be used to match terms that are similar to the provided term, within an edit distance defined by Fuzziness. +If the fuzzy expansion matches more than 128 terms, Elasticsearch returns an error. + +NOTE: Only available in Elasticsearch 7.6.0+ + +==== Fluent DSL example + +[source,csharp] +---- +q +.Intervals(c => c + .Field(p => p.Description) + .Name("named_query") + .Boost(1.1) + .Fuzzy(m => m + .Term(IntervalsFuzzy) + .Fuzziness(Fuzziness.Auto) + ) +) +---- + +==== Object Initializer syntax example + +[source,csharp] +---- +new IntervalsQuery +{ + Field = Field(p => p.Description), + Name = "named_query", + Boost = 1.1, + Fuzzy = new IntervalsFuzzy + { + Term = IntervalsFuzzy, + Fuzziness = Fuzziness.Auto + } +} +---- + +[source,javascript] +.Example json output +---- +{ + "intervals": { + "description": { + "_name": "named_query", + "boost": 1.1, + "fuzzy": { + "term": "lorem", + "fuzziness": "AUTO" + } + } + } +} +---- + diff --git a/src/DocGenerator/StringExtensions.cs b/src/DocGenerator/StringExtensions.cs index ceb0ad536ba..a9340404704 100644 --- a/src/DocGenerator/StringExtensions.cs +++ b/src/DocGenerator/StringExtensions.cs @@ -39,6 +39,7 @@ public static class StringExtensions { "Project.First.Name", "\"Lesch Group\"" }, { "Project.First.NumberOfCommits", "775" }, { "IntervalsPrefix", "\"lorem\"" }, + { "IntervalsFuzzy", "\"lorem\"" }, { "LastNameSearch", "\"Stokes\"" }, { "_first.Language", "\"painless\"" }, { "_first.Init", "\"state.map = [:]\"" },