public void UsingStaticPropertyField() { Field fieldString = "name"; /** but for expressions this is still rather involved */ var fieldExpression = Infer.Field <Project>(p => p.Name); /** this can be even shortened even further using a https://msdn.microsoft.com/en-us/library/sf0df423.aspx#Anchor_0[static import in C# 6] i.e. * `using static Nest.Infer;` */ fieldExpression = Field <Project>(p => p.Name); /** Now that is much terser then our first example using the constructor! */ Expect("name") .WhenSerializing(fieldString) .WhenSerializing(fieldExpression); /** You can specify boosts in the field using a string */ fieldString = "name^2.1"; fieldString.Boost.Should().Be(2.1); /** As well as using `Nest.Infer.Field` */ fieldExpression = Field <Project>(p => p.Name, 2.1); Expect("name^2.1") .WhenSerializing(fieldString) .WhenSerializing(fieldExpression); }
public void UsingConstructorAlsoSetsComparisonValue() { /** When using the constructor and passing a value for `Name`, `Property` or `Expression`, * `ComparisonValue` is also set on the `Field` instance; this is used when * * - determining `Field` equality * - getting the hash code for a `Field` instance * * IMPORTANT: Boost values are **not** taken into account when determining equality. */ var fieldStringWithBoostTwo = new Field("name^2"); var fieldStringWithBoostThree = new Field("name^3"); Expression <Func <Project, object> > expression = p => p.Name; var fieldExpression = new Field(expression); var fieldProperty = new Field(typeof(Project).GetProperty(nameof(Project.Name))); fieldStringWithBoostTwo.GetHashCode().Should().NotBe(0); fieldStringWithBoostThree.GetHashCode().Should().NotBe(0); fieldExpression.GetHashCode().Should().NotBe(0); fieldProperty.GetHashCode().Should().NotBe(0); fieldStringWithBoostTwo.Should().Be(fieldStringWithBoostThree); //<1> <<field-name-with-boost,Fields can constructed with a name that contains a boost>> }
public void UsingConstructorAlsoSetsComparisonValue() { /** When using the constructor and passing a value for `Name`, `Property` or `Expression`, * `ComparisonValue` is also set on the `Field` instance; this is used when * * - determining `Field` equality * - getting the hash code for a `Field` instance * * IMPORTANT: Boost values are not taken into account when determining equality. */ var fieldStringWithBoostTwo = new Field("name^2"); var fieldStringWithBoostThree = new Field("name^3"); Expression<Func<Project, object>> expression = p => p.Name; var fieldExpression = new Field(expression); var fieldProperty = new Field(typeof(Project).GetProperty(nameof(Project.Name))); fieldStringWithBoostTwo.GetHashCode().Should().NotBe(0); fieldStringWithBoostThree.GetHashCode().Should().NotBe(0); fieldExpression.GetHashCode().Should().NotBe(0); fieldProperty.GetHashCode().Should().NotBe(0); fieldStringWithBoostTwo.Should().Be(fieldStringWithBoostThree); //<1> <<field-name-with-boost,Fields can constructed with a name that contains a boost>> }
public void UsingStaticPropertyField() { Field fieldString = "name"; /** but for expressions this is still rather involved */ var fieldExpression = Field <Project>(p => p.Name); /** this can be even shortened even further using a static import. * Now that is much terser then our first example using the constructor! */ fieldExpression = Field <Project>(p => p.Name); Expect("name") .WhenSerializing(fieldString) .WhenSerializing(fieldExpression); /** You can specify boosts in the field using a string, as well as using `Nest.Infer.Field` */ fieldString = "name^2.1"; fieldString.Boost.Should().Be(2.1); fieldExpression = Field <Project>(p => p.Name, 2.1); fieldExpression.Boost.Should().Be(2.1); Expect("name^2.1") .WhenSerializing(fieldString) .WhenSerializing(fieldExpression); }
public void UsingStaticPropertyField() { Field fieldString = "name"; /** but for expressions this is still rather involved */ var fieldExpression = Infer.Field <Project>(p => p.Name); /** Using static imports in c# 6 this can be even shortened: * using static Nest.Static; */ fieldExpression = Field <Project>(p => p.Name); /** Now this is much much terser then our first example using the constructor! */ Expect("name") .WhenSerializing(fieldString) .WhenSerializing(fieldExpression); fieldString = "name^2.1"; fieldString.Boost.Should().Be(2.1); fieldExpression = Field <Project>(p => p.Name, 2.1); /** Now this is much much terser then our first example using the constructor! */ Expect("name^2.1") .WhenSerializing(fieldString) .WhenSerializing(fieldExpression); }
/** Therefor you can also implicitly convert strings and expressions to Field's */ [U] public void ImplicitConversion() { Field fieldString = "name"; /** but for expressions this is still rather involved */ Expression <Func <Project, object> > expression = p => p.Name; Field fieldExpression = expression; Expect("name") .WhenSerializing(fieldExpression) .WhenSerializing(fieldString); }
public void UsingConstructors() { var fieldString = new Field { Name = "name" }; /** especially when using C# expressions since these can not be simply new'ed*/ Expression<Func<Project, object>> expression = p => p.Name; var fieldExpression = Field.Create(expression); Expect("name") .WhenSerializing(fieldExpression) .WhenSerializing(fieldString); }
public void NameCanSpecifyBoost() { Field fieldString = "name^2"; Field fieldStringConstructor = new Field("name^2"); Field fieldStringCreate = new Field("name^2", 3); //<1> NEST will take the boost from the name fieldString.Name.Should().Be("name"); fieldStringConstructor.Name.Should().Be("name"); fieldStringCreate.Name.Should().Be("name"); fieldString.Boost.Should().Be(2); fieldStringConstructor.Boost.Should().Be(2); fieldStringCreate.Boost.Should().Be(2); }
public void NameCanSpecifyBoost() { Field fieldString = "name^2"; var fieldStringConstructor = new Field("name^2"); var fieldStringCreate = new Field("name^2", 3); //<1> NEST will take the boost from the name fieldString.Name.Should().Be("name"); fieldStringConstructor.Name.Should().Be("name"); fieldStringCreate.Name.Should().Be("name"); fieldString.Boost.Should().Be(2); fieldStringConstructor.Boost.Should().Be(2); fieldStringCreate.Boost.Should().Be(2); }
public void UsingConstructors() { var fieldString = new Field("name"); var fieldProperty = new Field(typeof(Project).GetProperty(nameof(Project.Name))); Expression <Func <Project, object> > expression = p => p.Name; var fieldExpression = new Field(expression); Expect("name") .WhenSerializing(fieldExpression) .WhenSerializing(fieldString) .WhenSerializing(fieldProperty); }
public void ImplicitConversion() { Field fieldString = "name"; Field fieldProperty = typeof(Project).GetProperty(nameof(Project.Name)); Expression <Func <Project, object> > expression = p => p.Name; Field fieldExpression = expression; Expect("name") .WhenSerializing(fieldString) .WhenSerializing(fieldProperty) .WhenSerializing(fieldExpression); }
/** # Strongly typed field access * * Several places in the elasticsearch API expect the path to a field from your original source document as a string. * NEST allows you to use C# expressions to strongly type these field path strings. * * These expressions are assigned to a type called `Field` and there are several ways to create a instance of that type */ /** Using the constructor directly is possible but rather involved */ [U] public void UsingConstructors() { var fieldString = new Field { Name = "name" }; /** especially when using C# expressions since these can not be simply new'ed*/ Expression <Func <Project, object> > expression = p => p.Name; var fieldExpression = Field.Create(expression); Expect("name") .WhenSerializing(fieldExpression) .WhenSerializing(fieldString); }
public void UsingConstructors() { var fieldString = new Field("name"); var fieldProperty = new Field(typeof(Project).GetProperty(nameof(Project.Name))); Expression<Func<Project, object>> expression = p => p.Name; var fieldExpression = new Field(expression); Expect("name") .WhenSerializing(fieldExpression) .WhenSerializing(fieldString) .WhenSerializing(fieldProperty); }
public NestedQueryDescriptor <T> Path(Field path) => Assign(a => a.Path = path);
/// <inheritdoc cref="IDissectProcessor.Field"> public DissectProcessorDescriptor <T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
public virtual FieldSortDescriptor <T> Field(Field field) { _field = field; return(this); }
public virtual FieldSortDescriptor <T> Field <TValue>(Expression <Func <T, TValue> > objectPath) { _field = objectPath; return(this); }
/// <inheritdoc cref="ISetSecurityUserProcessor.Field"/> public SetSecurityUserProcessorDescriptor <T> Field(Field field) => Assign(field, (a, v) => a.Field = v);