Getting specific fields from objects embedded in arrays


(Eran Kutner-2) #1

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


(Shay Banon) #2

Which version are you using? The following gist will return "a.x" : [1, 2]:
https://gist.github.com/1409479.

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


(Eran Kutner-2) #3

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


(Shay Banon) #4

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


(Eran Kutner-2) #5

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


(Shay Banon) #6

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


(system) #7