diff --git a/src/Nest/Mapping/DynamicTemplate/SingleMapping.cs b/src/Nest/Mapping/DynamicTemplate/SingleMapping.cs index f3db554cd16..5b6590cebfc 100644 --- a/src/Nest/Mapping/DynamicTemplate/SingleMapping.cs +++ b/src/Nest/Mapping/DynamicTemplate/SingleMapping.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq.Expressions; namespace Nest { @@ -6,7 +8,6 @@ public class SingleMappingDescriptor : DescriptorBase, IPropertiesDescriptor>, IPropertiesDescriptor where T : class { - [Obsolete("Only valid for indices created before Elasticsearch 5.0 and will be removed in the next major version. For newly created indices, use `text` or `keyword` instead.")] public IProperty String(Func, IStringProperty> selector) => selector?.Invoke(new StringPropertyDescriptor()); @@ -17,6 +18,10 @@ public IProperty Text(Func, ITextProperty> selector) = public IProperty Keyword(Func, IKeywordProperty> selector) => selector?.Invoke(new KeywordPropertyDescriptor()); + /// + /// Number introduces a numeric mapping that defaults to `float` use .Type() to set the right type if needed or use + /// Scalar instead of + /// public IProperty Number(Func, INumberProperty> selector) => selector?.Invoke(new NumberPropertyDescriptor()); @@ -28,7 +33,7 @@ public IProperty Boolean(Func, IBooleanProperty> se public IProperty Binary(Func, IBinaryProperty> selector) => selector?.Invoke(new BinaryPropertyDescriptor()); - + / public IProperty Attachment(Func, IAttachmentProperty> selector) => selector?.Invoke(new AttachmentPropertyDescriptor()); @@ -61,5 +66,157 @@ public IProperty Generic(Func, IGenericProperty> se public IProperty Percolator(Func, IPercolatorProperty> selector) => selector?.Invoke(new PercolatorPropertyDescriptor()); + +#pragma warning disable CS3001 // Argument type is not CLS-compliant + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Float)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Float)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Float)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Float)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Byte)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Byte)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Byte)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Byte)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + public IProperty Scalar(Expression>> field, Func, INumberProperty> selector) => + selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double)); + + public IProperty Scalar(Expression> field, Func, IDateProperty> selector) => + selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field)); + public IProperty Scalar(Expression> field, Func, IDateProperty> selector) => + selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IDateProperty> selector) => + selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IDateProperty> selector) => + selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field)); + + public IProperty Scalar(Expression> field, Func, IDateProperty> selector) => + selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field)); + public IProperty Scalar(Expression> field, Func, IDateProperty> selector) => + selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IDateProperty> selector) => + selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IDateProperty> selector) => + selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field)); + + public IProperty Scalar(Expression> field, Func, IBooleanProperty> selector) => + selector.InvokeOrDefault(new BooleanPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression> field, Func, IBooleanProperty> selector) => + selector.InvokeOrDefault(new BooleanPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IBooleanProperty> selector) => + selector.InvokeOrDefault(new BooleanPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IBooleanProperty> selector) => + selector.InvokeOrDefault(new BooleanPropertyDescriptor().Name(field)); + + public IProperty Scalar(Expression> field, Func, IKeywordProperty> selector) => + selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression> field, Func, IKeywordProperty> selector) => + selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IKeywordProperty> selector) => + selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IKeywordProperty> selector) => + selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field)); + + public IProperty Scalar(Expression> field, Func, IKeywordProperty> selector) => + selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression> field, Func, IKeywordProperty> selector) => + selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IKeywordProperty> selector) => + selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, IKeywordProperty> selector) => + selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field)); + + + public IProperty Scalar(Expression> field, Func, ITextProperty> selector) => + selector.InvokeOrDefault(new TextPropertyDescriptor().Name(field)); + public IProperty Scalar(Expression>> field, Func, ITextProperty> selector) => + selector.InvokeOrDefault(new TextPropertyDescriptor().Name(field)); +#pragma warning restore CS3001 // Argument type is not CLS-compliant } } diff --git a/src/Nest/Mapping/Types/Properties-Scalar.cs b/src/Nest/Mapping/Types/Properties-Scalar.cs new file mode 100644 index 00000000000..1c65c4c36ac --- /dev/null +++ b/src/Nest/Mapping/Types/Properties-Scalar.cs @@ -0,0 +1,254 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Newtonsoft.Json; + +namespace Nest +{ + public partial interface IPropertiesDescriptor + where T : class + where TReturnType : class + { +#pragma warning disable CS3001 // Argument type is not CLS-compliant + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + TReturnType Scalar(Expression>> field, Func, INumberProperty> selector); + + TReturnType Scalar(Expression> field, Func, IDateProperty> selector); + TReturnType Scalar(Expression> field, Func, IDateProperty> selector); + TReturnType Scalar(Expression>> field, Func, IDateProperty> selector); + TReturnType Scalar(Expression>> field, Func, IDateProperty> selector); + + TReturnType Scalar(Expression> field, Func, IDateProperty> selector); + TReturnType Scalar(Expression> field, Func, IDateProperty> selector); + TReturnType Scalar(Expression>> field, Func, IDateProperty> selector); + TReturnType Scalar(Expression>> field, Func, IDateProperty> selector); + + TReturnType Scalar(Expression> field, Func, IBooleanProperty> selector); + TReturnType Scalar(Expression> field, Func, IBooleanProperty> selector); + TReturnType Scalar(Expression>> field, Func, IBooleanProperty> selector); + TReturnType Scalar(Expression>> field, Func, IBooleanProperty> selector); + + TReturnType Scalar(Expression> field, Func, IKeywordProperty> selector); + TReturnType Scalar(Expression> field, Func, IKeywordProperty> selector); + TReturnType Scalar(Expression>> field, Func, IKeywordProperty> selector); + TReturnType Scalar(Expression>> field, Func, IKeywordProperty> selector); + + TReturnType Scalar(Expression> field, Func, IKeywordProperty> selector); + TReturnType Scalar(Expression> field, Func, IKeywordProperty> selector); + TReturnType Scalar(Expression>> field, Func, IKeywordProperty> selector); + TReturnType Scalar(Expression>> field, Func, IKeywordProperty> selector); + + TReturnType Scalar(Expression> field, Func, ITextProperty> selector); + TReturnType Scalar(Expression>> field, Func, ITextProperty> selector); +#pragma warning restore CS3001 // Argument type is not CLS-compliant + } + + public partial class PropertiesDescriptor : IsADictionaryDescriptorBase, IProperties, PropertyName, IProperty>, IPropertiesDescriptor> + where T : class + { +#pragma warning disable CS3001 // Argument type is not CLS-compliant + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Integer))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Float))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Float))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Float))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Float))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Byte))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Byte))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Byte))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Byte))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Short))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Long))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + public PropertiesDescriptor Scalar(Expression>> field, Func, INumberProperty> selector) => + SetProperty(selector.InvokeOrDefault(new NumberPropertyDescriptor().Name(field).Type(NumberType.Double))); + + public PropertiesDescriptor Scalar(Expression> field, Func, IDateProperty> selector) => + SetProperty(selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression> field, Func, IDateProperty> selector) => + SetProperty(selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IDateProperty> selector) => + SetProperty(selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IDateProperty> selector) => + SetProperty(selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field))); + + public PropertiesDescriptor Scalar(Expression> field, Func, IDateProperty> selector) => + SetProperty(selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression> field, Func, IDateProperty> selector) => + SetProperty(selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IDateProperty> selector) => + SetProperty(selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IDateProperty> selector) => + SetProperty(selector.InvokeOrDefault(new DatePropertyDescriptor().Name(field))); + + public PropertiesDescriptor Scalar(Expression> field, Func, IBooleanProperty> selector) => + SetProperty(selector.InvokeOrDefault(new BooleanPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression> field, Func, IBooleanProperty> selector) => + SetProperty(selector.InvokeOrDefault(new BooleanPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IBooleanProperty> selector) => + SetProperty(selector.InvokeOrDefault(new BooleanPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IBooleanProperty> selector) => + SetProperty(selector.InvokeOrDefault(new BooleanPropertyDescriptor().Name(field))); + + public PropertiesDescriptor Scalar(Expression> field, Func, IKeywordProperty> selector) => + SetProperty(selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression> field, Func, IKeywordProperty> selector) => + SetProperty(selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IKeywordProperty> selector) => + SetProperty(selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IKeywordProperty> selector) => + SetProperty(selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field))); + + public PropertiesDescriptor Scalar(Expression> field, Func, IKeywordProperty> selector) => + SetProperty(selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression> field, Func, IKeywordProperty> selector) => + SetProperty(selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IKeywordProperty> selector) => + SetProperty(selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, IKeywordProperty> selector) => + SetProperty(selector.InvokeOrDefault(new KeywordPropertyDescriptor().Name(field))); + + + public PropertiesDescriptor Scalar(Expression> field, Func, ITextProperty> selector) => + SetProperty(selector.InvokeOrDefault(new TextPropertyDescriptor().Name(field))); + public PropertiesDescriptor Scalar(Expression>> field, Func, ITextProperty> selector) => + SetProperty(selector.InvokeOrDefault(new TextPropertyDescriptor().Name(field))); +#pragma warning restore CS3001 // Argument type is not CLS-compliant + } +} diff --git a/src/Nest/Mapping/Types/Properties.cs b/src/Nest/Mapping/Types/Properties.cs index 7f7f4f672f0..56b1534c043 100644 --- a/src/Nest/Mapping/Types/Properties.cs +++ b/src/Nest/Mapping/Types/Properties.cs @@ -33,7 +33,7 @@ public Properties(Dictionary container) public void Add(Expression> name, IProperty property) => this.BackingDictionary.Add(name, property); } - public interface IPropertiesDescriptor + public partial interface IPropertiesDescriptor where T : class where TReturnType : class { @@ -42,6 +42,10 @@ public interface IPropertiesDescriptor TReturnType String(Func, IStringProperty> selector); TReturnType Text(Func, ITextProperty> selector); TReturnType Keyword(Func, IKeywordProperty> selector); + /// + /// Number introduces a numeric mapping that defaults to `float` use .Type() to set the right type if needed or use + /// Scalar instead of + /// TReturnType Number(Func, INumberProperty> selector); TReturnType TokenCount(Func, ITokenCountProperty> selector); TReturnType Date(Func, IDateProperty> selector); @@ -60,7 +64,7 @@ TReturnType Nested(Func, INestedProp TReturnType Percolator(Func, IPercolatorProperty> selector); } - public class PropertiesDescriptor : IsADictionaryDescriptorBase, IProperties, PropertyName, IProperty>, IPropertiesDescriptor> + public partial class PropertiesDescriptor : IsADictionaryDescriptorBase, IProperties, PropertyName, IProperty>, IPropertiesDescriptor> where T : class { public PropertiesDescriptor() : base(new Properties()) { } @@ -74,6 +78,10 @@ public PropertiesDescriptor() : base(new Properties()) { } public PropertiesDescriptor Keyword(Func, IKeywordProperty> selector) => SetProperty(selector); + /// + /// Number introduces a numeric mapping that defaults to `float` use .Type() to set the right type if needed or use + /// Scalar instead of + /// public PropertiesDescriptor Number(Func, INumberProperty> selector) => SetProperty(selector); public PropertiesDescriptor TokenCount(Func, ITokenCountProperty> selector) => SetProperty(selector); diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index 9362dcb3079..f88b68a449c 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -884,6 +884,7 @@ + diff --git a/src/Tests/IndexModules/UsageTestBase.cs b/src/Tests/IndexModules/UsageTestBase.cs index 480b4f029fc..af144b48c6b 100644 --- a/src/Tests/IndexModules/UsageTestBase.cs +++ b/src/Tests/IndexModules/UsageTestBase.cs @@ -12,13 +12,17 @@ public abstract class UsageTestBase : Ser protected abstract TInitializer Initializer { get; } protected abstract Func Fluent { get; } + protected virtual bool TestObjectInitializer => true; + protected UsageTestBase() { this.FluentInstance = this.Fluent(new TDescriptor()); } - [U] protected void SerializesInitializer() => - this.AssertSerializesAndRoundTrips(this.Initializer); + [U] protected void SerializesInitializer() + { + if (this.TestObjectInitializer) this.AssertSerializesAndRoundTrips(this.Initializer); + } [U] protected void SerializesFluent() => this.AssertSerializesAndRoundTrips(this.FluentInstance); diff --git a/src/Tests/Mapping/Scalar/ScalarUsageTests.cs b/src/Tests/Mapping/Scalar/ScalarUsageTests.cs new file mode 100644 index 00000000000..9b68c1b7fa3 --- /dev/null +++ b/src/Tests/Mapping/Scalar/ScalarUsageTests.cs @@ -0,0 +1,248 @@ +using Nest; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tests.Framework; +using Tests.Framework.MockData; + +namespace Tests.Mapping.Scalar +{ + public class ScalarUsageTests : UsageTestBase, TypeMapping> + { + protected override bool SupportsDeserialization => false; + protected override bool TestObjectInitializer => false; + + public class ScalarPoco + { + public int Int { get; set; } + public IEnumerable Ints { get; set; } + public int? IntNullable { get; set; } + public IEnumerable IntNullables { get; set; } + + public float Float { get; set; } + public IEnumerable Floats { get; set; } + public float? FloatNullable { get; set; } + public IEnumerable FloatNullables { get; set; } + + public double Double { get; set; } + public IEnumerable Doubles { get; set; } + public double? DoubleNullable { get; set; } + public IEnumerable DoubleNullables { get; set; } + + public sbyte SByte { get; set; } + public IEnumerable SBytes { get; set; } + public sbyte? SByteNullable { get; set; } + public IEnumerable SByteNullables { get; set; } + + public short Short { get; set; } + public IEnumerable Shorts { get; set; } + public short? ShortNullable { get; set; } + public IEnumerable ShortNullables { get; set; } + + public byte Byte { get; set; } + public IEnumerable Bytes { get; set; } + public byte? ByteNullable { get; set; } + public IEnumerable ByteNullables { get; set; } + + public long Long { get; set; } + public IEnumerable Longs { get; set; } + public long? LongNullable { get; set; } + public IEnumerable LongNullables { get; set; } + + public uint Uint { get; set; } + public IEnumerable Uints { get; set; } + public uint? UintNullable { get; set; } + public IEnumerable UintNullables { get; set; } + + public TimeSpan TimeSpan { get; set; } + public IEnumerable TimeSpans { get; set; } + public TimeSpan? TimeSpanNullable { get; set; } + public IEnumerable TimeSpanNullables { get; set; } + + public decimal Decimal { get; set; } + public IEnumerable Decimals {get;set; } + public decimal? DecimalNullable { get; set; } + public IEnumerable DecimalNullables { get; set; } + + public ulong Ulong { get; set; } + public IEnumerable Ulongs { get; set; } + public ulong? UlongNullable { get; set; } + public IEnumerable UlongNullables { get; set; } + + public DateTime DateTime { get; set; } + public IEnumerable DateTimes { get; set; } + public DateTime? DateTimeNullable { get; set; } + public IEnumerable DateTimeNullables { get; set; } + + public DateTimeOffset DateTimeOffset { get; set; } + public IEnumerable DateTimeOffsets { get; set; } + public DateTimeOffset? DateTimeOffsetNullable { get; set; } + public IEnumerable DateTimeOffsetNullables { get; set; } + + public bool Bool { get; set; } + public IEnumerable Bools { get; set; } + public bool? BoolNullable { get; set; } + public IEnumerable BoolNullables { get; set; } + + public char Char { get; set; } + public IEnumerable Chars { get; set; } + public char? CharNullable { get; set; } + public IEnumerable CharNullables { get; set; } + + public Guid Guid { get; set; } + public IEnumerable Guids { get; set; } + public Guid? GuidNullable { get; set; } + public IEnumerable GuidNullables { get; set; } + + public string String { get; set; } + public IEnumerable Strings { get; set; } + } + + protected override object ExpectJson => new + { + properties = new + { + @bool = new { type = "boolean" }, + bools = new { type = "boolean" }, + boolNullable = new { type = "boolean" }, + boolNullables = new { type = "boolean" }, + @byte = new { type = "short" }, + bytes = new { type = "short" }, + byteNullable = new { type = "short" }, + byteNullables = new { type = "short" }, + @char = new { type = "keyword" }, + chars = new { type = "keyword" }, + charNullable = new { type = "keyword" }, + charNullables = new { type = "keyword" }, + dateTime = new { type = "date" }, + dateTimes = new { type = "date" }, + dateTimeNullable = new { type = "date" }, + dateTimeNullables = new { type = "date" }, + dateTimeOffset = new { type = "date" }, + dateTimeOffsets = new { type = "date" }, + dateTimeOffsetNullable = new { type = "date" }, + dateTimeOffsetNullables = new { type = "date" }, + @decimal = new { type = "double" }, + decimals = new { type = "double" }, + decimalNullable = new { type = "double" }, + decimalNullables = new { type = "double" }, + @double = new { type = "double" }, + doubles = new { type = "double" }, + doubleNullable = new { type = "double" }, + doubleNullables = new { type = "double" }, + @float = new { type = "float" }, + floats = new { type = "float" }, + floatNullable = new { type = "float" }, + floatNullables = new { type = "float" }, + guid = new { type = "keyword" }, + guids = new { type = "keyword" }, + guidNullable = new { type = "keyword" }, + guidNullables = new { type = "keyword" }, + @int = new { type = "integer" }, + ints = new { type = "integer" }, + intNullable = new { type = "integer" }, + intNullables = new { type = "integer" }, + @long = new { type = "long" }, + longs = new { type = "long" }, + longNullable = new { type = "long" }, + longNullables = new { type = "long" }, + sByte = new { type = "byte" }, + sBytes = new { type = "byte" }, + sByteNullable = new { type = "byte" }, + sByteNullables = new { type = "byte" }, + @short = new { type = "short" }, + shorts = new { type = "short" }, + shortNullable = new { type = "short" }, + shortNullables = new { type = "short" }, + timeSpan = new { type = "long" }, + timeSpans = new { type = "long" }, + timeSpanNullable = new { type = "long" }, + timeSpanNullables = new { type = "long" }, + @uint = new { type = "long" }, + uints = new { type = "long" }, + uintNullable = new { type = "long" }, + uintNullables = new { type = "long" }, + @ulong = new { type = "double" }, + ulongs = new { type = "double" }, + ulongNullable = new { type = "double" }, + ulongNullables = new { type = "double" }, + @string = new { type = "text" }, + strings = new { type = "text" } + } + }; + + protected override Func, ITypeMapping> Fluent => f => f + .Properties(ps => ps + .Scalar(p => p.Int, m => m) + .Scalar(p => p.Ints, m => m) + .Scalar(p => p.IntNullable, m => m) + .Scalar(p => p.IntNullables, m => m) + .Scalar(p => p.Float, m => m) + .Scalar(p => p.Floats, m => m) + .Scalar(p => p.FloatNullable, m => m) + .Scalar(p => p.FloatNullables, m => m) + .Scalar(p => p.Double, m => m) + .Scalar(p => p.Doubles, m => m) + .Scalar(p => p.DoubleNullable, m => m) + .Scalar(p => p.DoubleNullables, m => m) + .Scalar(p => p.SByte, m => m) + .Scalar(p => p.SBytes, m => m) + .Scalar(p => p.SByteNullable, m => m) + .Scalar(p => p.SByteNullables, m => m) + .Scalar(p => p.Short, m => m) + .Scalar(p => p.Shorts, m => m) + .Scalar(p => p.ShortNullable, m => m) + .Scalar(p => p.ShortNullables, m => m) + .Scalar(p => p.Byte, m => m) + .Scalar(p => p.Bytes, m => m) + .Scalar(p => p.ByteNullable, m => m) + .Scalar(p => p.ByteNullables, m => m) + .Scalar(p => p.Long, m => m) + .Scalar(p => p.Longs, m => m) + .Scalar(p => p.LongNullable, m => m) + .Scalar(p => p.LongNullables, m => m) + .Scalar(p => p.Uint, m => m) + .Scalar(p => p.Uints, m => m) + .Scalar(p => p.UintNullable, m => m) + .Scalar(p => p.UintNullables, m => m) + .Scalar(p => p.TimeSpan, m => m) + .Scalar(p => p.TimeSpans, m => m) + .Scalar(p => p.TimeSpanNullable, m => m) + .Scalar(p => p.TimeSpanNullables, m => m) + .Scalar(p => p.Decimal, m => m) + .Scalar(p => p.Decimals, m => m) + .Scalar(p => p.DecimalNullable, m => m) + .Scalar(p => p.DecimalNullables, m => m) + .Scalar(p => p.Ulong, m => m) + .Scalar(p => p.Ulongs, m => m) + .Scalar(p => p.UlongNullable, m => m) + .Scalar(p => p.UlongNullables, m => m) + .Scalar(p => p.DateTime, m => m) + .Scalar(p => p.DateTimes, m => m) + .Scalar(p => p.DateTimeNullable, m => m) + .Scalar(p => p.DateTimeNullables, m => m) + .Scalar(p => p.DateTimeOffset, m => m) + .Scalar(p => p.DateTimeOffsets, m => m) + .Scalar(p => p.DateTimeOffsetNullable, m => m) + .Scalar(p => p.DateTimeOffsetNullables, m => m) + .Scalar(p => p.Bool, m => m) + .Scalar(p => p.Bools, m => m) + .Scalar(p => p.BoolNullable, m => m) + .Scalar(p => p.BoolNullables, m => m) + .Scalar(p => p.Char, m => m) + .Scalar(p => p.Chars, m => m) + .Scalar(p => p.CharNullable, m => m) + .Scalar(p => p.CharNullables, m => m) + .Scalar(p => p.Guid, m => m) + .Scalar(p => p.Guids, m => m) + .Scalar(p => p.GuidNullable, m => m) + .Scalar(p => p.GuidNullables, m => m) + .Scalar(p => p.String, m => m) + .Scalar(p => p.Strings, m => m) + ); + + protected override TypeMapping Initializer => null; + } +} diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 391e37da707..f55b821208c 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -348,6 +348,7 @@ + diff --git a/src/Tests/tests.yaml b/src/Tests/tests.yaml index 6fc7c370378..825accf5dd5 100644 --- a/src/Tests/tests.yaml +++ b/src/Tests/tests.yaml @@ -1,5 +1,5 @@ # mode either u (unit test), i (integration test) or m (mixed mode) -mode: m +mode: u # the elasticsearch version that should be started # Can be a snapshot version of sonatype or "latest" to get the latest snapshot of sonatype elasticsearch_version: 5.0.0-beta1