NEST 2.2 Limit Fields returned

Hello,

I am trying to limit the fields that are returned from a query but i cant seem to get the .Fields() part of the query detecting the objects in my class:

   var result = client.Search<MyClass>(s => s
                
               .Size(10000)
              .Fields(f => f.MyField)
               .Query(q => q

When i type .Fields(f => f. I only get the choice to select Fields or Field (not my class fields)

Thanks,

Take a look at the 2.x documentation on Fields usage

As an example, if MyClass looks like

public class MyClass
{
    public string Foo { get; set;}

    public int Bar { get; set;}
}

You can do

client.Search<MyClass>(s => s
    .Size(10000)
    .Fields(f => f
        .Fields(
            ff => ff.Foo,
            ff => ff.Bar
        )
    )
);

or

client.Search<MyClass>(s => s
    .Size(10000)
    .Fields(f => f
        .Field(ff => ff.Foo)
        .Field(ff => ff.Bar)
    )
);

both serialize to

{
  "size": 10000,
  "fields": [
    "foo",
    "bar"
  ]
}

As a side note, asking for 10,000 documents in one request is a lot! You may want to consider using scroll to efficiently retrieve them.

Thank you very much.. I must have been looking at the 1.x documentation. Thanks for the tip on scrolling - i already have most of my queries using scroll but in this case i am only going to bring back 2 small fields and the doc count should hover around 3000.