NEST 2.4.6: Type Fields - cannot access internal constructor

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

Thanks

1 Like

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[]
{
    "title",
    "body",
}

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),
    "body"
}

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[]
{
    "title^2",
    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);
1 Like

Hi Russ,

Thanks for the response