# ES 1.0 update - why are fields returns an array when fields parameter is used?

**URL:** <https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862>\
**Category:** Elasticsearch\
**Created:** [February 18, 2014, 1:17am UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862 "2014-02-18T01:17:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jay\_Hilden](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_hilden/32/877_2.png) [@Jay\_Hilden](https://discuss.elastic.co/u/Jay_Hilden)\
**Post date:** [February 18, 2014, 1:17am UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862/1 "2014-02-18T01:17:01Z")

</div>

I was reading the documentation on the updated 1.0 release and saw the  
following:

"Field values, in response to the fields[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-request-fields.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-request-fields.html) parameter,  
are now always returned as arrays. A field could have single or multiple  
values, which meant that sometimes they were returned as scalars and  
sometimes as arrays."

I'm trying to understand this change. Will you please give me an example  
on where the field returned would be an array.

Thanks in advance!

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/\_return\_values.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/_return_values.html)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3e2e4992-99b7-445e-847c-e27a848fd993%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3e2e4992-99b7-445e-847c-e27a848fd993%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 18, 2014, 3:55pm UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862/2 "2014-02-18T15:55:20Z")

</div>

For example, if you index a doc like this:

POST [http://localhost:9200/foo/bar](http://localhost:9200/foo/bar)  
{ "foo": "bar" }

And then you query like this:

POST [http://localhost:9200/foo/\_search](http://localhost:9200/foo/_search)  
{  
"fields": ["foo"]  
}

Your result will now be like this in 1.0 (note that the value bar is  
returned as an array ["bar"] instead of just a string "bar"):

{  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "foo",  
"\_type" : "bar",  
"\_id" : "w34aAgVpQ9GJ0PJ4LqyYLQ",  
"\_score" : 1.0,  
"fields" : {  
"foo" : ["bar"]  
}  
} ]  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/861b1c55-ffc6-4884-82b1-19670602f984%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/861b1c55-ffc6-4884-82b1-19670602f984%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jay\_Hilden](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_hilden/32/877_2.png) [@Jay\_Hilden](https://discuss.elastic.co/u/Jay_Hilden)\
**Post date:** [February 18, 2014, 4:15pm UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862/3 "2014-02-18T16:15:19Z")

</div>

Binh, thank you for your response, I have created a similar test scenario  
and verified that I get the same results. My question is why is ["bar"] an  
array object at all? Under what conditions would it be possible to have a  
return value of "bar2" like my example below:

{  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "foo",  
"\_type" : "bar",  
"\_id" : "w34aAgVpQ9GJ0PJ4LqyYLQ",  
"\_score" : 1.0,  
"fields" : {  
"foo" : ["bar", "bar2"]  
}  
} ]  
}  
}

Thanks!

On Tuesday, February 18, 2014 9:55:20 AM UTC-6, Binh Ly wrote:

> For example, if you index a doc like this:
> 
> POST [http://localhost:9200/foo/bar](http://localhost:9200/foo/bar)  
> { "foo": "bar" }
> 
> And then you query like this:
> 
> POST [http://localhost:9200/foo/\_search](http://localhost:9200/foo/_search)  
> {  
> "fields": ["foo"]  
> }
> 
> Your result will now be like this in 1.0 (note that the value bar is  
> returned as an array ["bar"] instead of just a string "bar"):
> 
> {  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "foo",  
> "\_type" : "bar",  
> "\_id" : "w34aAgVpQ9GJ0PJ4LqyYLQ",  
> "\_score" : 1.0,  
> "fields" : {  
> "foo" : ["bar"]  
> }  
> } ]  
> }  
> }

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/550a6264-e602-4beb-947d-e4786e5fe3f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/550a6264-e602-4beb-947d-e4786e5fe3f7%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 18, 2014, 4:21pm UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862/4 "2014-02-18T16:21:53Z")

</div>

Jay, let's say I index another document:

POST [http://localhost:9200/foo/bar](http://localhost:9200/foo/bar)  
{ "foo": ["bar", "bar2"] }

Then when I query again, it would yield the results like you asked.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cd31dd72-9e95-4917-8bb9-5b9e6942e7d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cd31dd72-9e95-4917-8bb9-5b9e6942e7d4%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jay\_Hilden](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_hilden/32/877_2.png) [@Jay\_Hilden](https://discuss.elastic.co/u/Jay_Hilden)\
**Post date:** [February 18, 2014, 4:48pm UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862/5 "2014-02-18T16:48:40Z")

</div>

Thanks Binh, that seems obvious now. It's interesting that I can specify a  
"field" query for a primitive type, or an array, but not a leaf field. I  
would have thought that a leaf field would be treated like an array, but I  
suppose then it would have no name to reference on.

Thanks for the feedback.

On Tue, Feb 18, 2014 at 10:21 AM, Binh Ly [binh@hibalo.com](mailto:binh@hibalo.com) wrote:

> Jay, let's say I index another document:
> 
> POST [http://localhost:9200/foo/bar](http://localhost:9200/foo/bar)  
> { "foo": ["bar", "bar2"] }
> 
> Then when I query again, it would yield the results like you asked.
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/1dMSGYmJcyw/unsubscribe](https://groups.google.com/d/topic/elasticsearch/1dMSGYmJcyw/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/cd31dd72-9e95-4917-8bb9-5b9e6942e7d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cd31dd72-9e95-4917-8bb9-5b9e6942e7d4%40googlegroups.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAD3qxy5oHuXG9XgegQNjZKBdPfbm0ANeiw9jN4Aee58nBdh1jg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAD3qxy5oHuXG9XgegQNjZKBdPfbm0ANeiw9jN4Aee58nBdh1jg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 18, 2014, 9:31pm UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862/6 "2014-02-18T21:31:28Z")

</div>

If you're referring to the field query type in 0.90.x, that is deprecated  
in 1.0 and no longer works:

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/\_deprecations.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/_deprecations.html)

Just FYI.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b99c8ddd-945e-46e2-9f4d-10e38e933270%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b99c8ddd-945e-46e2-9f4d-10e38e933270%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![n81](https://avatars.discourse-cdn.com/v4/letter/n/ee7513/32.png) [@n81](https://discuss.elastic.co/u/n81)\
**Post date:** [April 25, 2014, 6:25pm UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862/7 "2014-04-25T18:25:23Z")

</div>

"By always returning arrays, this simplifies user code."

Can someone please tell me how this simplifies user code? If I index an array, I expect an array back and I have nothing more to do than fetch the "\_fields". If I index a value, say first\_name, why on earth would I want to parse through "\_fields" and pull out the value from an array? Very unhappy with this change.

---

<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, 1:33am UTC](https://discuss.elastic.co/t/es-1-0-update-why-are-fields-returns-an-array-when-fields-parameter-is-used/15862/8 "2017-07-06T01:33:28Z")

</div>


