# Get Array FieldValues ElasticSearch NEST

**URL:** <https://discuss.elastic.co/t/get-array-fieldvalues-elasticsearch-nest/288911>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [November 10, 2021, 3:58pm UTC](https://discuss.elastic.co/t/get-array-fieldvalues-elasticsearch-nest/288911 "2021-11-10T15:58:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_X](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mr_x/32/96967_2.png) [@Mr\_X](https://discuss.elastic.co/u/Mr_X)\
**Post date:** [November 10, 2021, 3:58pm UTC](https://discuss.elastic.co/t/get-array-fieldvalues-elasticsearch-nest/288911/1 "2021-11-10T15:58:21Z")

</div>

Is there a way to get Arrays returned in FieldValues using NEST.  
Consider the following query

```auto
            var searchResponse = client.Search<VehicleSpecs>(s => s
                .Index("specs")
                .Source(false)
                .Size(1000)
                .Query(q => q
                    .MatchAll()
                )
                .Fields(fs => fs
                    .Field(vs => vs.VehiclePhotos)));

```

VehiclePhotos is a an array of string in the above example but when I try to read it back it only returns first element from the array. Here is what I have tried so far

```auto
            foreach (var fields in searchResponse.Fields)
            {
                //var c = fields.ValueOf<VehicleSpecs, List<string>>(vs => vs.VehiclePhotos).Count;
                var photo= fields.Value<string>("vehiclePhotos");
            }

```

The commented line throws an error if i uncomment it

---

<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:** [November 15, 2021, 8:46am UTC](https://discuss.elastic.co/t/get-array-fieldvalues-elasticsearch-nest/288911/2 "2021-11-15T08:46:31Z")

</div>

You can use

```auto
foreach (var fields in searchResponse.Fields)
{
	string[] photo = fields.ValuesOf<string>("vehiclePhotos");
}

```

---

<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:** [December 13, 2021, 8:46am UTC](https://discuss.elastic.co/t/get-array-fieldvalues-elasticsearch-nest/288911/3 "2021-12-13T08:46:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
