diff --git a/docs/client-concepts/high-level/mapping/fluent-mapping.asciidoc b/docs/client-concepts/high-level/mapping/fluent-mapping.asciidoc index 578f9dcdb95..f34898067f1 100644 --- a/docs/client-concepts/high-level/mapping/fluent-mapping.asciidoc +++ b/docs/client-concepts/high-level/mapping/fluent-mapping.asciidoc @@ -405,7 +405,6 @@ var createIndexResponse = _client.Indices.Create("myindex", c => c "birthDayOfWeek": { "type": "keyword", "script": { - "lang": "painless", "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))" } } @@ -427,3 +426,38 @@ createIndexResponse = _client.Indices.Create("myindex", c => c ); ---- +One may also include and use parameters in the script. + +[source,csharp] +---- +createIndexResponse = _client.Indices.Create("myindex", c => c + .Map(m => m + .RuntimeFields(rtf => rtf + .RuntimeField("birthDayOfWeek", FieldType.Keyword, f => f + .Script(s => s + .Source("emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT) + params.suffix)") + .Params(p => p.Add("suffix", " with a suffix.")) + ))) + ) +); +---- + +[source,javascript] +---- +{ + "mappings": { + "runtime": { + "birthDayOfWeek": { + "type": "keyword", + "script": { + "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT) + params.suffix)", + "params": { + "suffix": " with a suffix." + } + } + } + } + } +} +---- + diff --git a/docs/query-dsl.asciidoc b/docs/query-dsl.asciidoc index be9da05bd0e..fcb263ebaba 100644 --- a/docs/query-dsl.asciidoc +++ b/docs/query-dsl.asciidoc @@ -45,6 +45,8 @@ NEST exposes all of the full text queries available in Elasticsearch :anchor-list: query-dsl/full-text +* <> + * <> * <> @@ -67,6 +69,8 @@ See the Elasticsearch documentation on {ref_current}/full-text-queries.html[Full :includes-from-dirs: query-dsl/full-text +include::query-dsl/full-text/combined-fields/combined-fields-usage.asciidoc[] + include::query-dsl/full-text/common-terms/common-terms-usage.asciidoc[] include::query-dsl/full-text/intervals/intervals-usage.asciidoc[] diff --git a/docs/query-dsl/full-text/combined-fields/combined-fields-usage.asciidoc b/docs/query-dsl/full-text/combined-fields/combined-fields-usage.asciidoc new file mode 100644 index 00000000000..a214521225e --- /dev/null +++ b/docs/query-dsl/full-text/combined-fields/combined-fields-usage.asciidoc @@ -0,0 +1,115 @@ +:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/master + +: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/master/src/Tests/Tests/QueryDsl/FullText/CombinedFields/CombinedFieldsUsageTests.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! +//// + +[[combined-fields-usage]] +=== Combined Fields Usage + +The `combined_fields` query supports searching multiple text fields as if their contents had been indexed into one combined field. It takes a +term-centric view of the query: first it analyzes the query string into individual terms, then looks for each term in any of the fields. + +See the Elasticsearch documentation on {ref_current}/query-dsl-combined-fields-query.html[combined fields query] for more details. + +==== Fluent DSL example + +[source,csharp] +---- +q +.CombinedFields(c => c + .Fields(f => f.Field(p => p.Description).Field("myOtherField")) + .Query("hello world") + .Boost(1.1) + .Operator(Operator.Or) + .MinimumShouldMatch("2") + .ZeroTermsQuery(ZeroTermsQuery.All) + .Name("combined_fields") + .AutoGenerateSynonymsPhraseQuery(false) +) +---- + +==== Object Initializer syntax example + +[source,csharp] +---- +new CombinedFieldsQuery +{ + Fields = Field(p => p.Description).And("myOtherField"), + Query = "hello world", + Boost = 1.1, + Operator = Operator.Or, + MinimumShouldMatch = "2", + ZeroTermsQuery = ZeroTermsQuery.All, + Name = "combined_fields", + AutoGenerateSynonymsPhraseQuery = false +} +---- + +[source,javascript] +.Example json output +---- +{ + "combined_fields": { + "_name": "combined_fields", + "boost": 1.1, + "query": "hello world", + "minimum_should_match": "2", + "operator": "or", + "fields": [ + "description", + "myOtherField" + ], + "zero_terms_query": "all", + "auto_generate_synonyms_phrase_query": false + } +} +---- + +[float] +=== Combined fields with boost usage + +==== Fluent DSL example + +[source,csharp] +---- +q +.CombinedFields(c => c + .Fields(Field(p => p.Description, 2.2).And("myOtherField^1.2")) + .Query("hello world") +) +---- + +==== Object Initializer syntax example + +[source,csharp] +---- +new CombinedFieldsQuery +{ + Fields = Field(p => p.Description, 2.2).And("myOtherField^1.2"), + Query = "hello world", +} +---- + +[source,javascript] +.Example json output +---- +{ + "combined_fields": { + "query": "hello world", + "fields": [ + "description^2.2", + "myOtherField^1.2" + ] + } +} +---- + diff --git a/docs/query-dsl/geo/bounding-box/geo-bounding-box-query-usage.asciidoc b/docs/query-dsl/geo/bounding-box/geo-bounding-box-query-usage.asciidoc index 58de48e21ed..eb3b683077e 100644 --- a/docs/query-dsl/geo/bounding-box/geo-bounding-box-query-usage.asciidoc +++ b/docs/query-dsl/geo/bounding-box/geo-bounding-box-query-usage.asciidoc @@ -29,7 +29,6 @@ q .BottomRight(-34, 34) ) .ValidationMethod(GeoValidationMethod.Strict) - .Type(GeoExecution.Indexed) ) ---- @@ -47,7 +46,6 @@ new GeoBoundingBoxQuery TopLeft = new GeoLocation(34, -34), BottomRight = new GeoLocation(-34, 34), }, - Type = GeoExecution.Indexed, ValidationMethod = GeoValidationMethod.Strict } ---- @@ -57,7 +55,6 @@ new GeoBoundingBoxQuery ---- { "geo_bounding_box": { - "type": "indexed", "validation_method": "strict", "_name": "named_query", "boost": 1.1, @@ -88,7 +85,6 @@ q .WellKnownText("BBOX (-34, 34, 34, -34)") ) .ValidationMethod(GeoValidationMethod.Strict) - .Type(GeoExecution.Indexed) ) ---- @@ -105,7 +101,6 @@ new GeoBoundingBoxQuery { WellKnownText = "BBOX (-34, 34, 34, -34)" }, - Type = GeoExecution.Indexed, ValidationMethod = GeoValidationMethod.Strict } ---- @@ -115,7 +110,6 @@ new GeoBoundingBoxQuery ---- { "geo_bounding_box": { - "type": "indexed", "validation_method": "strict", "_name": "named_query", "boost": 1.1, diff --git a/docs/search/request/search-after-usage.asciidoc b/docs/search/request/search-after-usage.asciidoc index b246dbd6658..fa50b985437 100644 --- a/docs/search/request/search-after-usage.asciidoc +++ b/docs/search/request/search-after-usage.asciidoc @@ -36,7 +36,7 @@ s => s [source,csharp] ---- -new SearchRequest +new SearchRequest() { Sort = new List { @@ -92,7 +92,7 @@ s => s [source,csharp] ---- -new SearchRequest +new SearchRequest() { Sort = new List { diff --git a/docs/search/searching-runtime-fields.asciidoc b/docs/search/searching-runtime-fields.asciidoc index 261c2ecc8de..bbf76693596 100644 --- a/docs/search/searching-runtime-fields.asciidoc +++ b/docs/search/searching-runtime-fields.asciidoc @@ -114,7 +114,6 @@ which yields the following query JSON "runtime_mappings": { "search_runtime_field": { "script": { - "lang": "painless", "source": "if (doc['type'].size() != 0) {emit(doc['type'].value.toUpperCase())}" }, "type": "keyword" @@ -139,7 +138,7 @@ var searchRequest = new SearchRequest { "search_runtime_field", new RuntimeField { Type = FieldType.Keyword, - Script = new PainlessScript("if (doc['type'].size() != 0) {emit(doc['type'].value.toUpperCase())}") + Script = new InlineScript("if (doc['type'].size() != 0) {emit(doc['type'].value.toUpperCase())}") } } } diff --git a/src/Nest/Indices/MappingManagement/GetMapping/GetMappingResponse.cs b/src/Nest/Indices/MappingManagement/GetMapping/GetMappingResponse.cs index 36a6300094c..757a3a7f117 100644 --- a/src/Nest/Indices/MappingManagement/GetMapping/GetMappingResponse.cs +++ b/src/Nest/Indices/MappingManagement/GetMapping/GetMappingResponse.cs @@ -24,7 +24,7 @@ public void Accept(IMappingVisitor visitor) public class IndexMappings { - [Obsolete("Mapping are no longer grouped by type, this indexer is ignored and simply returns Mapppings")] + [Obsolete("Mapping are no longer grouped by type, this indexer is ignored and simply returns Mappings")] public TypeMapping this[string type] => Mappings; [DataMember(Name = "mappings")] diff --git a/src/Nest/Mapping/DynamicTemplate/SingleMapping.cs b/src/Nest/Mapping/DynamicTemplate/SingleMapping.cs index 03c164cbcad..734ecd753d2 100644 --- a/src/Nest/Mapping/DynamicTemplate/SingleMapping.cs +++ b/src/Nest/Mapping/DynamicTemplate/SingleMapping.cs @@ -22,6 +22,10 @@ public IProperty Boolean(Func, IBooleanProperty> se public IProperty Completion(Func, ICompletionProperty> selector) => selector?.Invoke(new CompletionPropertyDescriptor()); + /// + public IProperty ConstantKeyword(Func, IConstantKeywordProperty> selector) => + selector?.Invoke(new ConstantKeywordPropertyDescriptor()); + /// public IProperty Date(Func, IDateProperty> selector) => selector?.Invoke(new DatePropertyDescriptor()); @@ -38,6 +42,14 @@ public IProperty DateRange(Func, IDateRangeProper public IProperty DoubleRange(Func, IDoubleRangeProperty> selector) => selector?.Invoke(new DoubleRangePropertyDescriptor()); + /// + public IProperty FieldAlias(Func, IFieldAliasProperty> selector) => + selector?.Invoke(new FieldAliasPropertyDescriptor()); + + /// + public IProperty Flattened(Func, IFlattenedProperty> selector) => + selector?.Invoke(new FlattenedPropertyDescriptor()); + /// public IProperty FloatRange(Func, IFloatRangeProperty> selector) => selector?.Invoke(new FloatRangePropertyDescriptor()); @@ -51,12 +63,8 @@ public IProperty GeoShape(Func, IGeoShapeProperty> selector?.Invoke(new GeoShapePropertyDescriptor()); /// - public IProperty Shape(Func, IShapeProperty> selector) => - selector?.Invoke(new ShapePropertyDescriptor()); - - /// - public IProperty Point(Func, IPointProperty> selector) => - selector?.Invoke(new PointPropertyDescriptor()); + public IProperty Histogram(Func, IHistogramProperty> selector) => + selector?.Invoke(new HistogramPropertyDescriptor()); /// public IProperty IntegerRange(Func, IIntegerRangeProperty> selector) => @@ -74,26 +82,6 @@ public IProperty IpRange(Func, IIpRangeProperty> se public IProperty Join(Func, IJoinProperty> selector) => selector?.Invoke(new JoinPropertyDescriptor()); - /// - public IProperty Histogram(Func, IHistogramProperty> selector) => - selector?.Invoke(new HistogramPropertyDescriptor()); - - /// - public IProperty FieldAlias(Func, IFieldAliasProperty> selector) => - selector?.Invoke(new FieldAliasPropertyDescriptor()); - - /// - public IProperty RankFeature(Func, IRankFeatureProperty> selector) => - selector?.Invoke(new RankFeaturePropertyDescriptor()); - - /// - public IProperty RankFeatures(Func, IRankFeaturesProperty> selector) => - selector?.Invoke(new RankFeaturesPropertyDescriptor()); - - /// - public IProperty Flattened(Func, IFlattenedProperty> selector) => - selector?.Invoke(new FlattenedPropertyDescriptor()); - /// public IProperty Keyword(Func, IKeywordProperty> selector) => selector?.Invoke(new KeywordPropertyDescriptor()); @@ -126,33 +114,49 @@ public IProperty Percolator(Func, IPercolatorPro selector?.Invoke(new PercolatorPropertyDescriptor()); /// - public IProperty Text(Func, ITextProperty> selector) => - selector?.Invoke(new TextPropertyDescriptor()); + public IProperty Point(Func, IPointProperty> selector) => + selector?.Invoke(new PointPropertyDescriptor()); /// - public IProperty TokenCount(Func, ITokenCountProperty> selector) => - selector?.Invoke(new TokenCountPropertyDescriptor()); + public IProperty RankFeature(Func, IRankFeatureProperty> selector) => + selector?.Invoke(new RankFeaturePropertyDescriptor()); /// - public IProperty Generic(Func, IGenericProperty> selector) => - selector?.Invoke(new GenericPropertyDescriptor()); + public IProperty RankFeatures(Func, IRankFeaturesProperty> selector) => + selector?.Invoke(new RankFeaturesPropertyDescriptor()); /// public IProperty SearchAsYouType(Func, ISearchAsYouTypeProperty> selector) => selector?.Invoke(new SearchAsYouTypePropertyDescriptor()); /// - public IProperty ConstantKeyword(Func, IConstantKeywordProperty> selector) => - selector?.Invoke(new ConstantKeywordPropertyDescriptor()); + public IProperty Shape(Func, IShapeProperty> selector) => + selector?.Invoke(new ShapePropertyDescriptor()); /// - public IProperty Wildcard(Func, IWildcardProperty> selector) => - selector?.Invoke(new WildcardPropertyDescriptor()); - + public IProperty Text(Func, ITextProperty> selector) => + selector?.Invoke(new TextPropertyDescriptor()); + + /// + public IProperty TokenCount(Func, ITokenCountProperty> selector) => + selector?.Invoke(new TokenCountPropertyDescriptor()); + /// public IProperty Version(Func, IVersionProperty> selector) => selector?.Invoke(new VersionPropertyDescriptor()); + /// + public IProperty Wildcard(Func, IWildcardProperty> selector) => + selector?.Invoke(new WildcardPropertyDescriptor()); + + /// + public IProperty Generic(Func, IGenericProperty> selector) => + selector?.Invoke(new GenericPropertyDescriptor()); + + /// + public IProperty DenseVector(Func, IDenseVectorProperty> selector) => + selector?.Invoke(new DenseVectorPropertyDescriptor()); + #pragma warning disable CS3001 // Argument type is not CLS-compliant public IProperty Scalar(Expression> field, Func, INumberProperty> selector = null) => selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer)); diff --git a/src/Nest/Mapping/Types/Core/DenseVector/DenseVectorAttribute.cs b/src/Nest/Mapping/Types/Core/DenseVector/DenseVectorAttribute.cs new file mode 100644 index 00000000000..fb9338f8b84 --- /dev/null +++ b/src/Nest/Mapping/Types/Core/DenseVector/DenseVectorAttribute.cs @@ -0,0 +1,23 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +namespace Nest +{ + /// + public class DenseVectorAttribute : ElasticsearchPropertyAttributeBase, IDenseVectorProperty + { + public DenseVectorAttribute() : base(FieldType.DenseVector) {} + + /// + public int Dimensions + { + get => Self.Dimensions.GetValueOrDefault(); + set => Self.Dimensions = value; + } + + int? IDenseVectorProperty.Dimensions { get; set; } + + private IDenseVectorProperty Self => this; + } +} diff --git a/src/Nest/Mapping/Types/Core/DenseVector/DenseVectorProperty.cs b/src/Nest/Mapping/Types/Core/DenseVector/DenseVectorProperty.cs new file mode 100644 index 00000000000..25dc5412e8c --- /dev/null +++ b/src/Nest/Mapping/Types/Core/DenseVector/DenseVectorProperty.cs @@ -0,0 +1,48 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using System.Diagnostics; +using System.Runtime.Serialization; +using Nest.Utf8Json; + +namespace Nest +{ + /// + /// A dense_vector field stores dense vectors of float values. The maximum number of dimensions + /// that can be in a vector should not exceed 2048. A dense_vector field is a single-valued field. + /// + [InterfaceDataContract] + public interface IDenseVectorProperty : IProperty + { + /// + /// The number of dimensions in the vector. + /// + [DataMember(Name = "dims")] + int? Dimensions { get; set; } + } + + /// + public class DenseVectorProperty : PropertyBase, IDenseVectorProperty + { + public DenseVectorProperty() : base(FieldType.DenseVector) { } + + /// + public int? Dimensions { get; set; } + } + + /// + [DebuggerDisplay("{" + nameof(DebugDisplay) + "}")] + public class DenseVectorPropertyDescriptor + : PropertyDescriptorBase, IDenseVectorProperty, T>, IDenseVectorProperty + where T : class + { + public DenseVectorPropertyDescriptor() : base(FieldType.DenseVector) { } + + int? IDenseVectorProperty.Dimensions { get; set; } + + /// + public DenseVectorPropertyDescriptor Dimensions(int? dimensions) => + Assign(dimensions, (a, v) => a.Dimensions = v); + } +} diff --git a/src/Nest/Mapping/Types/FieldType.cs b/src/Nest/Mapping/Types/FieldType.cs index 841e42a4478..4cf096e6fa4 100644 --- a/src/Nest/Mapping/Types/FieldType.cs +++ b/src/Nest/Mapping/Types/FieldType.cs @@ -26,7 +26,8 @@ public enum FieldType GeoShape, /// - /// An ip mapping type allows to store ipv4 addresses in a numeric form allowing to easily sort, and range query it (using ip values). + /// An ip mapping type allows to store ipv4 addresses in a numeric form allowing to easily sort, and range query it (using + /// ip values). /// [EnumMember(Value = "ip")] Ip, @@ -44,7 +45,8 @@ public enum FieldType Text, /// - /// A text-like field that is optimized to provide out-of-the-box support for queries that serve an as-you-type completion use case. + /// A text-like field that is optimized to provide out-of-the-box support for queries that serve an as-you-type completion + /// use case. /// [EnumMember(Value = "search_as_you_type")] SearchAsYouType, @@ -162,6 +164,12 @@ public enum FieldType /// Version field type for storing semver compatible version numbers. /// [EnumMember(Value = "version")] - Version + Version, + + /// + /// A dense_vector field stores dense vectors of float values. + /// + [EnumMember(Value = "dense_vector")] + DenseVector } } diff --git a/src/Nest/Mapping/Types/Properties.cs b/src/Nest/Mapping/Types/Properties.cs index ad45cec2397..38087c6be36 100644 --- a/src/Nest/Mapping/Types/Properties.cs +++ b/src/Nest/Mapping/Types/Properties.cs @@ -48,10 +48,10 @@ public partial interface IPropertiesDescriptor where T : class where TReturnType : class { - /// + /// TReturnType Text(Func, ITextProperty> selector); - /// + /// TReturnType Keyword(Func, IKeywordProperty> selector); /// @@ -60,100 +60,103 @@ public partial interface IPropertiesDescriptor /// TReturnType Number(Func, INumberProperty> selector); - /// + /// TReturnType TokenCount(Func, ITokenCountProperty> selector); - /// + /// TReturnType Date(Func, IDateProperty> selector); - /// + /// TReturnType DateNanos(Func, IDateNanosProperty> selector); - /// + /// TReturnType Boolean(Func, IBooleanProperty> selector); - /// + /// TReturnType Binary(Func, IBinaryProperty> selector); - /// + /// TReturnType Object(Func, IObjectProperty> selector) where TChild : class; - /// + /// TReturnType Nested(Func, INestedProperty> selector) where TChild : class; - /// + /// TReturnType Ip(Func, IIpProperty> selector); - /// + /// TReturnType GeoPoint(Func, IGeoPointProperty> selector); - /// + /// TReturnType GeoShape(Func, IGeoShapeProperty> selector); - /// + /// TReturnType Shape(Func, IShapeProperty> selector); - /// + /// TReturnType Point(Func, IPointProperty> selector); - /// + /// TReturnType Completion(Func, ICompletionProperty> selector); - /// + /// TReturnType Murmur3Hash(Func, IMurmur3HashProperty> selector); - /// + /// TReturnType Percolator(Func, IPercolatorProperty> selector); - /// + /// TReturnType DateRange(Func, IDateRangeProperty> selector); - /// + /// TReturnType DoubleRange(Func, IDoubleRangeProperty> selector); - /// + /// TReturnType FloatRange(Func, IFloatRangeProperty> selector); - /// + /// TReturnType IntegerRange(Func, IIntegerRangeProperty> selector); - /// + /// TReturnType LongRange(Func, ILongRangeProperty> selector); - /// + /// TReturnType IpRange(Func, IIpRangeProperty> selector); - /// + /// TReturnType Join(Func, IJoinProperty> selector); - /// + /// TReturnType Histogram(Func, IHistogramProperty> selector); - /// + /// TReturnType FieldAlias(Func, IFieldAliasProperty> selector); - /// + /// TReturnType RankFeature(Func, IRankFeatureProperty> selector); - /// + /// TReturnType RankFeatures(Func, IRankFeaturesProperty> selector); - /// + /// TReturnType Flattened(Func, IFlattenedProperty> selector); - /// + /// TReturnType SearchAsYouType(Func, ISearchAsYouTypeProperty> selector); - /// + /// TReturnType ConstantKeyword(Func, IConstantKeywordProperty> selector); - /// + /// TReturnType Wildcard(Func, IWildcardProperty> selector); - /// + /// TReturnType Version(Func, IVersionProperty> selector); + + /// + TReturnType DenseVector(Func, IDenseVectorProperty> selector); } public partial class PropertiesDescriptor where T : class @@ -162,64 +165,74 @@ public PropertiesDescriptor() : base(new Properties()) { } public PropertiesDescriptor(IProperties properties) : base(properties ?? new Properties()) { } - /// + /// public PropertiesDescriptor Binary(Func, IBinaryProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Boolean(Func, IBooleanProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Completion(Func, ICompletionProperty> selector) => SetProperty(selector); - /// + /// + public PropertiesDescriptor ConstantKeyword(Func, IConstantKeywordProperty> selector) => + SetProperty(selector); + + /// public PropertiesDescriptor Date(Func, IDateProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor DateNanos(Func, IDateNanosProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor DateRange(Func, IDateRangeProperty> selector) => SetProperty(selector); - /// + /// + public PropertiesDescriptor DenseVector(Func, IDenseVectorProperty> selector) => SetProperty(selector); + + /// public PropertiesDescriptor DoubleRange(Func, IDoubleRangeProperty> selector) => SetProperty(selector); - /// + /// + public PropertiesDescriptor FieldAlias(Func, IFieldAliasProperty> selector) => SetProperty(selector); + + /// + public PropertiesDescriptor Flattened(Func, IFlattenedProperty> selector) => SetProperty(selector); + + /// public PropertiesDescriptor FloatRange(Func, IFloatRangeProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor GeoPoint(Func, IGeoPointProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor GeoShape(Func, IGeoShapeProperty> selector) => SetProperty(selector); - /// - public PropertiesDescriptor Shape(Func, IShapeProperty> selector) => SetProperty(selector); - - /// - public PropertiesDescriptor Point(Func, IPointProperty> selector) => SetProperty(selector); + /// + public PropertiesDescriptor Histogram(Func, IHistogramProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor IntegerRange(Func, IIntegerRangeProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Ip(Func, IIpProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor IpRange(Func, IIpRangeProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Join(Func, IJoinProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Keyword(Func, IKeywordProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor LongRange(Func, ILongRangeProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Murmur3Hash(Func, IMurmur3HashProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Nested(Func, INestedProperty> selector) where TChild : class => SetProperty(selector); @@ -230,47 +243,41 @@ public PropertiesDescriptor Nested(Func public PropertiesDescriptor Number(Func, INumberProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Object(Func, IObjectProperty> selector) where TChild : class => SetProperty(selector); - /// + /// public PropertiesDescriptor Percolator(Func, IPercolatorProperty> selector) => SetProperty(selector); - /// - public PropertiesDescriptor Text(Func, ITextProperty> selector) => SetProperty(selector); - - /// - public PropertiesDescriptor SearchAsYouType(Func, ISearchAsYouTypeProperty> selector) => SetProperty(selector); - - /// - public PropertiesDescriptor TokenCount(Func, ITokenCountProperty> selector) => SetProperty(selector); - - /// - public PropertiesDescriptor FieldAlias(Func, IFieldAliasProperty> selector) => SetProperty(selector); + /// + public PropertiesDescriptor Point(Func, IPointProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor RankFeature(Func, IRankFeatureProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor RankFeatures(Func, IRankFeaturesProperty> selector) => SetProperty(selector); - /// - public PropertiesDescriptor Flattened(Func, IFlattenedProperty> selector) => SetProperty(selector); + /// + public PropertiesDescriptor SearchAsYouType(Func, ISearchAsYouTypeProperty> selector) => + SetProperty(selector); - /// - public PropertiesDescriptor Histogram(Func, IHistogramProperty> selector) => SetProperty(selector); + /// + public PropertiesDescriptor Shape(Func, IShapeProperty> selector) => SetProperty(selector); - /// - public PropertiesDescriptor ConstantKeyword(Func, IConstantKeywordProperty> selector) => - SetProperty(selector); + /// + public PropertiesDescriptor Text(Func, ITextProperty> selector) => SetProperty(selector); - /// - public PropertiesDescriptor Wildcard(Func, IWildcardProperty> selector) => SetProperty(selector); + /// + public PropertiesDescriptor TokenCount(Func, ITokenCountProperty> selector) => SetProperty(selector); - /// + /// public PropertiesDescriptor Version(Func, IVersionProperty> selector) => SetProperty(selector); + /// + public PropertiesDescriptor Wildcard(Func, IWildcardProperty> selector) => SetProperty(selector); + /// /// Map a custom property. /// diff --git a/src/Nest/Mapping/Types/PropertyFormatter.cs b/src/Nest/Mapping/Types/PropertyFormatter.cs index 629029bdfcd..1540508c7cb 100644 --- a/src/Nest/Mapping/Types/PropertyFormatter.cs +++ b/src/Nest/Mapping/Types/PropertyFormatter.cs @@ -4,15 +4,12 @@ using System; using Nest.Utf8Json; + namespace Nest { internal class PropertyFormatter : IJsonFormatter { - private static readonly AutomataDictionary AutomataDictionary = new AutomataDictionary - { - { "type", 0 }, - { "properties", 1 } - }; + private static readonly AutomataDictionary AutomataDictionary = new AutomataDictionary { { "type", 0 }, { "properties", 1 } }; public IProperty Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) { @@ -99,6 +96,7 @@ public IProperty Deserialize(ref JsonReader reader, IJsonFormatterResolver forma case FieldType.ConstantKeyword: return Deserialize(ref segmentReader, formatterResolver); case FieldType.Wildcard: return Deserialize(ref segmentReader, formatterResolver); case FieldType.Version: return Deserialize(ref segmentReader, formatterResolver); + case FieldType.DenseVector: return Deserialize(ref segmentReader, formatterResolver); case FieldType.None: // no "type" field in the property mapping, or FieldType enum could not be parsed from typeString return Deserialize(ref segmentReader, formatterResolver); @@ -222,6 +220,9 @@ public void Serialize(ref JsonWriter writer, IProperty value, IJsonFormatterReso case IVersionProperty versionProperty: Serialize(ref writer, versionProperty, formatterResolver); break; + case IDenseVectorProperty denseVectorProperty: + Serialize(ref writer, denseVectorProperty, formatterResolver); + break; default: var formatter = formatterResolver.GetFormatter(); formatter.Serialize(ref writer, value, formatterResolver); diff --git a/src/Nest/Mapping/Visitor/IMappingVisitor.cs b/src/Nest/Mapping/Visitor/IMappingVisitor.cs index b5b8816df4d..265e983689b 100644 --- a/src/Nest/Mapping/Visitor/IMappingVisitor.cs +++ b/src/Nest/Mapping/Visitor/IMappingVisitor.cs @@ -73,6 +73,8 @@ public interface IMappingVisitor void Visit(IConstantKeywordProperty property); void Visit(IVersionProperty property); + + void Visit(IDenseVectorProperty property); } public class NoopMappingVisitor : IMappingVisitor @@ -144,5 +146,7 @@ public virtual void Visit(IHistogramProperty property) { } public virtual void Visit(IConstantKeywordProperty property) { } public virtual void Visit(IVersionProperty property) { } + + public virtual void Visit(IDenseVectorProperty property) { } } } diff --git a/src/Nest/Mapping/Visitor/IPropertyVisitor.cs b/src/Nest/Mapping/Visitor/IPropertyVisitor.cs index f557c7420a4..838ffabf3a3 100644 --- a/src/Nest/Mapping/Visitor/IPropertyVisitor.cs +++ b/src/Nest/Mapping/Visitor/IPropertyVisitor.cs @@ -78,6 +78,8 @@ public interface IPropertyVisitor void Visit(IVersionProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute); + void Visit(IDenseVectorProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute); + IProperty Visit(PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute); bool SkipProperty(PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute); diff --git a/src/Nest/Mapping/Visitor/MappingWalker.cs b/src/Nest/Mapping/Visitor/MappingWalker.cs index 3ad5bd2d481..532634e83a2 100644 --- a/src/Nest/Mapping/Visitor/MappingWalker.cs +++ b/src/Nest/Mapping/Visitor/MappingWalker.cs @@ -279,6 +279,12 @@ public void Accept(IProperties properties) _visitor.Visit(t); }); break; + case FieldType.DenseVector: + Visit(field, t => + { + _visitor.Visit(t); + }); + break; case FieldType.None: continue; } diff --git a/src/Nest/Mapping/Visitor/NoopPropertyVisitor.cs b/src/Nest/Mapping/Visitor/NoopPropertyVisitor.cs index c8bbabf2a65..e8c6a686e76 100644 --- a/src/Nest/Mapping/Visitor/NoopPropertyVisitor.cs +++ b/src/Nest/Mapping/Visitor/NoopPropertyVisitor.cs @@ -78,6 +78,8 @@ public virtual void Visit(IWildcardProperty type, PropertyInfo propertyInfo, Ela public virtual void Visit(IVersionProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute) { } + public virtual void Visit(IDenseVectorProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute) { } + public virtual IProperty Visit(PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute) => null; public virtual void Visit(IProperty type, PropertyInfo propertyInfo, ElasticsearchPropertyAttributeBase attribute) @@ -183,6 +185,9 @@ public virtual void Visit(IProperty type, PropertyInfo propertyInfo, Elasticsear case IVersionProperty version: Visit(version, propertyInfo, attribute); break; + case IDenseVectorProperty version: + Visit(version, propertyInfo, attribute); + break; } } } diff --git a/src/Nest/Search/FieldCapabilities/FieldCapabilitiesResponse.cs b/src/Nest/Search/FieldCapabilities/FieldCapabilitiesResponse.cs index 3ac15cff956..d552da55a42 100644 --- a/src/Nest/Search/FieldCapabilities/FieldCapabilitiesResponse.cs +++ b/src/Nest/Search/FieldCapabilities/FieldCapabilitiesResponse.cs @@ -39,6 +39,7 @@ public class FieldTypes : IsADictionaryBase public FieldCapabilities Date => BackingDictionary.TryGetValue("date", out var f) ? f : null; public FieldCapabilities DateNanos => BackingDictionary.TryGetValue("date_nanos", out var f) ? f : null; public FieldCapabilities DateRange => BackingDictionary.TryGetValue("date_range", out var f) ? f : null; + public FieldCapabilities DenseVector => BackingDictionary.TryGetValue("dense_vector", out var f) ? f : null; public FieldCapabilities Double => BackingDictionary.TryGetValue("double", out var f) ? f : null; public FieldCapabilities DoubleRange => BackingDictionary.TryGetValue("double_range", out var f) ? f : null; public FieldCapabilities FieldNames => BackingDictionary.TryGetValue("_field_names", out var f) ? f : null; @@ -46,7 +47,6 @@ public class FieldTypes : IsADictionaryBase public FieldCapabilities FloatRange => BackingDictionary.TryGetValue("float_range", out var f) ? f : null; public FieldCapabilities GeoPoint => BackingDictionary.TryGetValue("geo_point", out var f) ? f : null; public FieldCapabilities GeoShape => BackingDictionary.TryGetValue("geo_shape", out var f) ? f : null; - public FieldCapabilities Shape => BackingDictionary.TryGetValue("shape", out var f) ? f : null; public FieldCapabilities HalfFloat => BackingDictionary.TryGetValue("half_float", out var f) ? f : null; public FieldCapabilities Id => BackingDictionary.TryGetValue("_id", out var f) ? f : null; public FieldCapabilities Index => BackingDictionary.TryGetValue("_index", out var f) ? f : null; @@ -58,10 +58,12 @@ public class FieldTypes : IsADictionaryBase public FieldCapabilities LongRange => BackingDictionary.TryGetValue("long_range", out var f) ? f : null; public FieldCapabilities Murmur3 => BackingDictionary.TryGetValue("murmur3", out var f) ? f : null; public FieldCapabilities Parent => BackingDictionary.TryGetValue("_parent", out var f) ? f : null; + public FieldCapabilities ParentJoin => BackingDictionary.TryGetValue("_parent_join", out var f) ? f : null; public FieldCapabilities Percolator => BackingDictionary.TryGetValue("percolator", out var f) ? f : null; public FieldCapabilities Routing => BackingDictionary.TryGetValue("_routing", out var f) ? f : null; public FieldCapabilities ScaledFloat => BackingDictionary.TryGetValue("scaled_float", out var f) ? f : null; public FieldCapabilities SearchAsYouType => BackingDictionary.TryGetValue("search_as_you_type", out var f) ? f : null; + public FieldCapabilities Shape => BackingDictionary.TryGetValue("shape", out var f) ? f : null; public FieldCapabilities Short => BackingDictionary.TryGetValue("short", out var f) ? f : null; public FieldCapabilities Source => BackingDictionary.TryGetValue("_source", out var f) ? f : null; public FieldCapabilities Text => BackingDictionary.TryGetValue("text", out var f) ? f : null; @@ -69,7 +71,6 @@ public class FieldTypes : IsADictionaryBase public FieldCapabilities TokenCount => BackingDictionary.TryGetValue("token_count", out var f) ? f : null; public FieldCapabilities Type => BackingDictionary.TryGetValue("_type", out var f) ? f : null; public FieldCapabilities Uid => BackingDictionary.TryGetValue("_uid", out var f) ? f : null; - public FieldCapabilities ParentJoin => BackingDictionary.TryGetValue("_parent_join", out var f) ? f : null; public FieldCapabilities Version => BackingDictionary.TryGetValue("_version", out var f) ? f : null; public FieldCapabilities VersionField => BackingDictionary.TryGetValue("version", out var f) ? f : null; } @@ -83,6 +84,9 @@ public class FieldCapabilities [JsonFormatter(typeof(IndicesFormatter))] public Indices Indices { get; internal set; } + [DataMember(Name = "meta")] + public IReadOnlyDictionary Meta { get; internal set; } = EmptyReadOnly.Dictionary; + [DataMember(Name = "non_aggregatable_indices")] [JsonFormatter(typeof(IndicesFormatter))] public Indices NonAggregatableIndices { get; internal set; } @@ -93,8 +97,5 @@ public class FieldCapabilities [DataMember(Name = "searchable")] public bool Searchable { get; internal set; } - - [DataMember(Name = "meta")] - public IReadOnlyDictionary Meta { get; internal set; } = EmptyReadOnly.Dictionary; } } diff --git a/tests/Tests/Indices/MappingManagement/GetMapping/GetMappingApiTest.cs b/tests/Tests/Indices/MappingManagement/GetMapping/GetMappingApiTest.cs index b2990df5cdc..281cf93909b 100644 --- a/tests/Tests/Indices/MappingManagement/GetMapping/GetMappingApiTest.cs +++ b/tests/Tests/Indices/MappingManagement/GetMapping/GetMappingApiTest.cs @@ -34,10 +34,7 @@ public GetMappingApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(c protected override HttpMethod HttpMethod => HttpMethod.GET; - protected override GetMappingRequest Initializer => new GetMappingRequest(Index()) - { - IgnoreUnavailable = true - }; + protected override GetMappingRequest Initializer => new GetMappingRequest(Index()) { IgnoreUnavailable = true }; protected override string UrlPath => "/project/_mapping?ignore_unavailable=true"; @@ -81,7 +78,6 @@ private static void AssertExtensionMethods(GetMappingResponse response) /** The `GetMappingFor` extension method can be used to get a type mapping easily and safely */ response.GetMappingFor().Should().NotBeNull(); response.GetMappingFor(typeof(Project)).Should().NotBeNull(); - } //hide @@ -101,7 +97,7 @@ private static void AssertVisitedProperties(GetMappingResponse response) visitor.CountsShouldContainKeyAndCountBe("type", 1); visitor.CountsShouldContainKeyAndCountBe("text", b ? 18 : 17); visitor.CountsShouldContainKeyAndCountBe("keyword", keywordCount); - visitor.CountsShouldContainKeyAndCountBe("object", supportsFlattenedType? 8 : 9); + visitor.CountsShouldContainKeyAndCountBe("object", supportsFlattenedType ? 8 : 9); visitor.CountsShouldContainKeyAndCountBe("number", 9); visitor.CountsShouldContainKeyAndCountBe("ip", 2); visitor.CountsShouldContainKeyAndCountBe("geo_point", 3); @@ -231,6 +227,8 @@ internal class TestVisitor : IMappingVisitor public void Visit(IVersionProperty property) => Increment("version"); + public void Visit(IDenseVectorProperty property) => Increment("dense_vector"); + private void Increment(string key) { if (!Counts.ContainsKey(key)) Counts.Add(key, 0); diff --git a/tests/Tests/Mapping/Types/Core/DenseVector/DenseVectorAttributeTests.cs b/tests/Tests/Mapping/Types/Core/DenseVector/DenseVectorAttributeTests.cs new file mode 100644 index 00000000000..f896de30e46 --- /dev/null +++ b/tests/Tests/Mapping/Types/Core/DenseVector/DenseVectorAttributeTests.cs @@ -0,0 +1,21 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using Elastic.Elasticsearch.Xunit.XunitPlumbing; +using Nest; + +namespace Tests.Mapping.Types.Core.DenseVector +{ + public class DenseVectorTest + { + [DenseVector(Dimensions = 2)] + public string DenseVector { get; set; } + } + + [SkipVersion("<7.6.0", "Dense Vector property GA in 7.6.0")] + public class DenseVectorAttributeTests : AttributeTestsBase + { + protected override object ExpectJson => new { properties = new { denseVector = new { type = "dense_vector", dims = 2 } } }; + } +} diff --git a/tests/Tests/Mapping/Types/Core/DenseVector/DenseVectorPropertyTests.cs b/tests/Tests/Mapping/Types/Core/DenseVector/DenseVectorPropertyTests.cs new file mode 100644 index 00000000000..6641ffe6829 --- /dev/null +++ b/tests/Tests/Mapping/Types/Core/DenseVector/DenseVectorPropertyTests.cs @@ -0,0 +1,29 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using System; +using Elastic.Elasticsearch.Xunit.XunitPlumbing; +using Nest; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Framework.EndpointTests.TestState; + +namespace Tests.Mapping.Types.Core.DenseVector +{ + [SkipVersion("<7.6.0", "Dense Vector property GA in 7.6.0")] + public class DenseVectorTests : PropertyTestsBase + { + public DenseVectorTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + + protected override object ExpectJson => new { properties = new { name = new { type = "dense_vector", dims = 2 } } }; + + protected override Func, IPromise> FluentProperties => f => f + .DenseVector(s => s + .Name(p => p.Name) + .Dimensions(2) + ); + + protected override IProperties InitializerProperties => new Properties { { "name", new DenseVectorProperty { Dimensions = 2 } } }; + } +}