# How to retrieve fields that are arrays

**URL:** <https://discuss.elastic.co/t/how-to-retrieve-fields-that-are-arrays/6560>\
**Category:** Elasticsearch\
**Created:** [February 1, 2012, 5:19am UTC](https://discuss.elastic.co/t/how-to-retrieve-fields-that-are-arrays/6560 "2012-02-01T05:19:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Hoffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_hoffman/32/1872_2.png) [@Nick\_Hoffman](https://discuss.elastic.co/u/Nick_Hoffman)\
**Post date:** [February 1, 2012, 5:19am UTC](https://discuss.elastic.co/t/how-to-retrieve-fields-that-are-arrays/6560/1 "2012-02-01T05:19:26Z")

</div>

Hey guys. I've just noticed that if a search's "fields" option contains the  
name of an array-field, the array-field isn't returned.

In the example below, the "name" field is returned, but not the "data"  
field. Why is that?

Thanks,  
Nick

$ curl -X DELETE 'localhost:9200/test'  
$ curl -X PUT 'localhost:9200/test'

$ curl -X POST 'localhost:9200/test/test/1' -d '{ name: "Nick", age: 30,  
data: [{foo: "bar"}] }'

$ curl 'localhost:9200/test/test/\_search?pretty=1' -d '{ fields: ["name",  
"data"] }'  
{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "test",  
"\_id" : "1",  
"\_score" : 1.0,  
"fields" : {  
"name" : "Nick"  
}  
} ]  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 1, 2012, 6:25am UTC](https://discuss.elastic.co/t/how-to-retrieve-fields-that-are-arrays/6560/2 "2012-02-01T06:25:00Z")

</div>

Did you try with "data.foo" ?  
I don't think that you can get the array.  
But, if you did not disable source, you could get the full document (and the source array)

HTH  
David 😉  
@dadoonet

Le 1 févr. 2012 à 06:19, Nick Hoffman [nick@deadorange.com](mailto:nick@deadorange.com) a écrit :

> Hey guys. I've just noticed that if a search's "fields" option contains the name of an array-field, the array-field isn't returned.
> 
> In the example below, the "name" field is returned, but not the "data" field. Why is that?
> 
> Thanks,  
> Nick
> 
> $ curl -X DELETE 'localhost:9200/test'  
> $ curl -X PUT 'localhost:9200/test'
> 
> $ curl -X POST 'localhost:9200/test/test/1' -d '{ name: "Nick", age: 30, data: [{foo: "bar"}] }'
> 
> $ curl 'localhost:9200/test/test/\_search?pretty=1' -d '{ fields: ["name", "data"] }'  
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "test",  
> "\_id" : "1",  
> "\_score" : 1.0,  
> "fields" : {  
> "name" : "Nick"  
> }  
> } ]  
> }  
> }

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 1, 2012, 11:08am UTC](https://discuss.elastic.co/t/how-to-retrieve-fields-that-are-arrays/6560/3 "2012-02-01T11:08:19Z")

</div>

Which version are you using? I executed it on latest 0.18.7 and it works well and returns the data array...

On Wednesday, February 1, 2012 at 7:19 AM, Nick Hoffman wrote:

> Hey guys. I've just noticed that if a search's "fields" option contains the name of an array-field, the array-field isn't returned.
> 
> In the example below, the "name" field is returned, but not the "data" field. Why is that?
> 
> Thanks,  
> Nick
> 
> $ curl -X DELETE 'localhost:9200/test'  
> $ curl -X PUT 'localhost:9200/test'
> 
> $ curl -X POST 'localhost:9200/test/test/1' -d '{ name: "Nick", age: 30, data: [{foo: "bar"}] }'
> 
> $ curl 'localhost:9200/test/test/\_search?pretty=1' -d '{ fields: ["name", "data"] }'  
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "test",  
> "\_id" : "1",  
> "\_score" : 1.0,  
> "fields" : {  
> "name" : "Nick"  
> }  
> } ]  
> }  
> }

---

<div class="post-metadata">

**Author:** ![Nick\_Hoffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_hoffman/32/1872_2.png) [@Nick\_Hoffman](https://discuss.elastic.co/u/Nick_Hoffman)\
**Post date:** [February 1, 2012, 2:57pm UTC](https://discuss.elastic.co/t/how-to-retrieve-fields-that-are-arrays/6560/4 "2012-02-01T14:57:26Z")

</div>

On Wednesday, 1 February 2012 01:25:00 UTC-5, David Pilato wrote:

> Did you try with "data.foo" ?  
> I don't think that you can get the array.  
> But, if you did not disable source, you could get the full document (and  
> the source array)
> 
> HTH  
> David 😉  
> @dadoonet

Yeah, I tried both "data.foo" and "data.\*", but neither worked. I could  
retrieve \_source and examine that, but my documents are quite large, so  
that's a lot of extra data to return.

---

<div class="post-metadata">

**Author:** ![Nick\_Hoffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_hoffman/32/1872_2.png) [@Nick\_Hoffman](https://discuss.elastic.co/u/Nick_Hoffman)\
**Post date:** [February 1, 2012, 3:05pm UTC](https://discuss.elastic.co/t/how-to-retrieve-fields-that-are-arrays/6560/5 "2012-02-01T15:05:33Z")

</div>

On Wednesday, 1 February 2012 06:08:19 UTC-5, kimchy wrote:

> Which version are you using? I executed it on latest 0.18.7 and it works  
> well and returns the data array...

You're right! I just upgraded from 0.17.something , and the "data" field's  
returned now. Thanks, Shay.

---

<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 6, 2017, 3:40am UTC](https://discuss.elastic.co/t/how-to-retrieve-fields-that-are-arrays/6560/6 "2017-07-06T03:40:46Z")

</div>


