NEST 2.4.6: Type Fields - cannot access internal constructor

(Denis Lamanov) #1

Hi guys, Hi @forloop

How should we initialize Fields in SourceFilter?

Using the latest version of NEST we can't specify source fields since can't use type Fields:

var source = new SourceFilter
Include = new Fields( new List{ new Field { Name = "test"}})

But cannot access internal constructor of Fields


(Russ Cam) #2

Hey @Denis_Lamanov, for some reason I missed this post first time round :smile:

You can construct a Fields in NEST 2.x in numerous ways

from string

Fields fieldsFromStrings = new[]

from expressions, using Infer.Field

Fields fieldsFromExpressions = new[]
    Infer.Field<Question>(f => f.Title),
    Infer.Field<Question>(f => f.Body),

from a mix of the two

Fields fieldsFromStringsAndExpressions = new[]
    Infer.Field<Question>(f => f.Title),

You can also specify boosts as well, as part of the string if using a string, or as the second parameter to field creation methods

Fields fieldsFromChainedField = 
    Infer.Field<Question>(f => f.Title).And<Question>(f => f.Body);

Fields fieldsFromStringsWithBoost = new[]
    Field.Create("body", 5),

Fields fieldsFromExpressionsWithBoost = new[]
    Infer.Field<Question>(f => f.Title, 2),
    Infer.Field<Question>(f => f.Body, 5),

Fields fieldsFromChainedFieldWihtBoost =
    Infer.Field<Question>(f => f.Title, 2).And<Question>(f => f.Body);

(Denis Lamanov) #3

Hi Russ,

Thanks for the response

(system) #4