diff --git a/src/Nest/CommonAbstractions/Infer/Field/Field.cs b/src/Nest/CommonAbstractions/Infer/Field/Field.cs index 2151d5e8149..35f46c8f293 100644 --- a/src/Nest/CommonAbstractions/Infer/Field/Field.cs +++ b/src/Nest/CommonAbstractions/Infer/Field/Field.cs @@ -18,7 +18,9 @@ public class Field : IEquatable, IUrlParameter private readonly object _comparisonValue; private readonly Type _type; - public Field(string name, double? boost = null, string format = null) + public Field(string name, double? boost = null) : this(name, boost, format: null) {} + + public Field(string name, double? boost, string format = null) { name.ThrowIfNullOrEmpty(nameof(name)); Name = ParseFieldName(name, out var b); @@ -27,7 +29,9 @@ public Field(string name, double? boost = null, string format = null) _comparisonValue = Name; } - public Field(Expression expression, double? boost = null, string format = null) + public Field(Expression expression, double? boost = null) : this(expression, boost, format: null) { } + + public Field(Expression expression, double? boost, string format = null) { Expression = expression ?? throw new ArgumentNullException(nameof(expression)); Boost = boost; @@ -37,7 +41,9 @@ public Field(Expression expression, double? boost = null, string format = null) CachableExpression = !new HasVariableExpressionVisitor(expression).Found; } - public Field(PropertyInfo property, double? boost = null, string format = null) + public Field(PropertyInfo property, double? boost = null) : this(property, boost, format: null) { } + + public Field(PropertyInfo property, double? boost, string format = null) { Property = property ?? throw new ArgumentNullException(nameof(property)); Boost = boost; @@ -98,13 +104,21 @@ string IUrlParameter.GetString(IConnectionConfigurationValues settings) public Fields And(Field field) => new Fields(new[] { this, field }); - public Fields And(Expression> field, double? boost = null, string format = null) where T : class => + public Fields And(Expression> field, double? boost = null) where T : class => + new Fields(new[] { this, new Field(field, boost, format: null) }); + + public Fields And(Expression> field, double? boost, string format = null) where T : class => new Fields(new[] { this, new Field(field, boost, format) }); - public Fields And(string field, double? boost = null, string format = null) => + public Fields And(string field, double? boost = null) => new Fields(new[] { this, new Field(field, boost, format: null) }); + + public Fields And(string field, double? boost, string format = null) => new Fields(new[] { this, new Field(field, boost, format) }); - public Fields And(PropertyInfo property, double? boost = null, string format = null) => + public Fields And(PropertyInfo property, double? boost = null) => + new Fields(new[] { this, new Field(property, boost, format: null) }); + + public Fields And(PropertyInfo property, double? boost, string format = null) => new Fields(new[] { this, new Field(property, boost, format) }); private static string ParseFieldName(string name, out double? boost) diff --git a/src/Nest/CommonAbstractions/Static/Infer.cs b/src/Nest/CommonAbstractions/Static/Infer.cs index ac612e179ff..588d226dd91 100644 --- a/src/Nest/CommonAbstractions/Static/Infer.cs +++ b/src/Nest/CommonAbstractions/Static/Infer.cs @@ -56,13 +56,17 @@ public static Fields Fields(params Expression>[] fields) wher /// Create a strongly typed string field name representation of the path to a property /// e.g. p => p.Array.First().SubProperty.Field will return 'array.subProperty.field' /// - public static Field Field(Expression> path, double? boost = null, string format = null) + public static Field Field(Expression> path, double? boost = null) where T : class => Field(path, boost, null); + + public static Field Field(Expression> path, double? boost, string format = null) where T : class => new Field(path, boost, format); - public static Field Field(string field, double? boost = null, string format = null) => - new Field(field, boost, format); + public static Field Field(string field, double? boost = null) => Field(field, boost, format: null); + + public static Field Field(string field, double? boost, string format = null) => new Field(field, boost, format); - public static Field Field(PropertyInfo property, double? boost = null, string format = null) => + public static Field Field(PropertyInfo property, double? boost = null) => Field(property, boost, format: null); + public static Field Field(PropertyInfo property, double? boost, string format = null) => new Field(property, boost, format); public static PropertyName Property(string property) => property; diff --git a/src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs b/src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs index 981ab70bca7..46577190797 100644 --- a/src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs +++ b/src/Tests/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs @@ -500,7 +500,7 @@ public void PrecedenceIsAsExpected() usingSettings.Expect("data").ForField(Field(p => p.DataMember)); usingSettings.Expect("DEFAULTFIELDNAMEINFERRER").ForField(Field(p => p.DefaultFieldNameInferrer)); - + var x = Field(p => p.Name, 1.0); /** The same naming rules also apply when indexing a document */ usingSettings.Expect(new [] { diff --git a/src/Tests/Tests/Search/Search/SearchApiTests.cs b/src/Tests/Tests/Search/Search/SearchApiTests.cs index 1b6c5c6b444..5ce16bd992e 100644 --- a/src/Tests/Tests/Search/Search/SearchApiTests.cs +++ b/src/Tests/Tests/Search/Search/SearchApiTests.cs @@ -272,8 +272,8 @@ public SearchApiDocValueFieldsTests(ReadOnlyCluster cluster, EndpointUsage usage Field = "state", Value = "Stable" }), - DocValueFields = Infer.Field(p => p.Name, format: "use_field_mapping") - .And(p => p.LastActivity, format: "weekyear") + DocValueFields = Infer.Field(p => p.Name, boost: null, format: "use_field_mapping") + .And(p => p.LastActivity, boost: null, format: "weekyear") }; protected override void ExpectResponse(ISearchResponse response)