示例#1
0
        /** # 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);
        }
示例#2
0
 public Fields And(string field, double?boost = null)
 {
     this.ListOfFields.Add(Field.Create(field, boost));
     return(this);
 }
示例#3
0
 public Fields And <T>(Expression <Func <T, object> > field, double?boost = null) where T : class
 {
     this.ListOfFields.Add(Field.Create(field, boost));
     return(this);
 }