How to retrieve fields that are arrays

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"
}
} ]
}
}

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 :wink:
@dadoonet

Le 1 févr. 2012 à 06:19, Nick Hoffman 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"
}
} ]
}
}

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"
}
} ]
}
}

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 :wink:
@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.

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.