Getting specific fields from objects embedded in arrays

Hi,
I have an index with objects that look like this:
{
a : [
{ x:1, y:2 },
{ x:2, y:3 },
]
}

I'd like to get only the "x" members from the array objects. I expected
that specifying "a.x" in the fields list would work and return something
like:
{
a: [
{ x:1 },
{ x:2 }
]
}
but it doesn't. It just doesn't return anything.

Is there another syntax I should use?

Thanks,
Eran

Which version are you using? The following gist will return "a.x" : [1, 2]:
gist:1409479 · GitHub.

p.s. Next time, please provide information similar to the gist I provided.

On Wed, Nov 30, 2011 at 5:24 PM, Eran Kutner eran@gigya-inc.com wrote:

Hi,
I have an index with objects that look like this:
{
a : [
{ x:1, y:2 },
{ x:2, y:3 },
]
}

I'd like to get only the "x" members from the array objects. I expected
that specifying "a.x" in the fields list would work and return something
like:
{
a: [
{ x:1 },
{ x:2 }
]
}
but it doesn't. It just doesn't return anything.

Is there another syntax I should use?

Thanks,
Eran

Sorry about that, I thought I was asking a usage question, not reporting an
issue.
I'm using 0.17.6 and your query doesn't return any fields.

Running: curl 'localhost:9200/test/_search?q=*&fields=a'
Doesn't return anything either.

Only : curl 'localhost:9200/test/_search?q=&fields=_source.a'
Works and returns the object "a" but: curl
'localhost:9200/test/_search?q=
&fields=_source.a.x'
Doesn't return anything again.

-eran

This type of "navigation" is supported in 0.18 (where you should not use
_source prefix at all any more).

On Wed, Nov 30, 2011 at 9:07 PM, Eran Kutner eran@gigya-inc.com wrote:

Sorry about that, I thought I was asking a usage question, not reporting
an issue.
I'm using 0.17.6 and your query doesn't return any fields.

Running: curl 'localhost:9200/test/_search?q=*&fields=a'
Doesn't return anything either.

Only : curl 'localhost:9200/test/_search?q=&fields=_source.a'
Works and returns the object "a" but: curl
'localhost:9200/test/_search?q=
&fields=_source.a.x'
Doesn't return anything again.

-eran

Thanks Shay, tested now with 0.18.5 and it does indeed work as you said,
however it feels to me the response should be structured differently.
Since ElasticSearch is document oriented I would expect the search result
to keep the original document's structure, but limit the returned fields to
the requested ones, so my expectation would be to get back:
{
a: [
{ x:1 },
{ x:2 }
]
}

not:
{
a.x: [1, 2]
}

This becomes more apparent if you fetch multiple fields, the original
document structure is completely lost. By the way, if you do the same thing
with MongoDB you get back a structure like I would expect.

-eran

I understand, but this is how it works. I find it more usable the way it
works currently (and less "noisy" in terms of data), especially if we are
talking about "deep" navigation. But, its possible to provide other
formats...

On Thu, Dec 1, 2011 at 9:14 PM, Eran Kutner eran@gigya-inc.com wrote:

Thanks Shay, tested now with 0.18.5 and it does indeed work as you said,
however it feels to me the response should be structured differently.
Since Elasticsearch is document oriented I would expect the search result
to keep the original document's structure, but limit the returned fields to
the requested ones, so my expectation would be to get back:

{
a: [
{ x:1 },
{ x:2 }
]
}

not:
{
a.x: [1, 2]
}

This becomes more apparent if you fetch multiple fields, the original
document structure is completely lost. By the way, if you do the same thing
with MongoDB you get back a structure like I would expect.

-eran