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

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

"Field values, in response to the fieldshttp://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

--
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.
To view this discussion on the web visit 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.

For example, if you index a doc like this:

POST http://localhost:9200/foo/bar
{ "foo": "bar" }

And then you query like this:

POST 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.
To view this discussion on the web visit 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.

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
{ "foo": "bar" }

And then you query like this:

POST 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.
To view this discussion on the web visit 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.

Jay, let's say I index another document:

POST 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.
To view this discussion on the web visit 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.

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 wrote:

Jay, let's say I index another document:

POST 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.
To unsubscribe from this group and all its topics, send an email to
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
.

For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAD3qxy5oHuXG9XgegQNjZKBdPfbm0ANeiw9jN4Aee58nBdh1jg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

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

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.
To view this discussion on the web visit 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.

"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.