# NEST 2.2 Limit Fields returned

**URL:** <https://discuss.elastic.co/t/nest-2-2-limit-fields-returned/47653>\
**Category:** Elasticsearch\
**Created:** [April 18, 2016, 12:54pm UTC](https://discuss.elastic.co/t/nest-2-2-limit-fields-returned/47653 "2016-04-18T12:54:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![whittssg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whittssg/32/27669_2.png) [@whittssg](https://discuss.elastic.co/u/whittssg)\
**Post date:** [April 18, 2016, 12:54pm UTC](https://discuss.elastic.co/t/nest-2-2-limit-fields-returned/47653/1 "2016-04-18T12:54:08Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [April 19, 2016, 8:43am UTC](https://discuss.elastic.co/t/nest-2-2-limit-fields-returned/47653/2 "2016-04-19T08:43:06Z")

</div>

Take a look at the 2.x documentation on [`Fields` usage](https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/fields-usage.html)

As an example, if `MyClass` looks like

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

    public int Bar { get; set;}
}

```

You can do

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

```

or

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

```

both serialize to

```javascript
{
  "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`](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-scroll.html) to efficiently retrieve them.

---

<div class="post-metadata">

**Author:** ![whittssg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whittssg/32/27669_2.png) [@whittssg](https://discuss.elastic.co/u/whittssg)\
**Post date:** [April 19, 2016, 11:22am UTC](https://discuss.elastic.co/t/nest-2-2-limit-fields-returned/47653/3 "2016-04-19T11:22:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:58pm UTC](https://discuss.elastic.co/t/nest-2-2-limit-fields-returned/47653/4 "2017-07-05T22:58:05Z")

</div>


