Sorting/retrieving a subset of child attributes

Hi guys,

I'm having some struggles trying to structure some index(es) and would like
some input regarding it's feasibility or alternatives.
We need to perform a search ordered by some child attributes. The scenario
is having a document with a repeating child attribute and we need to query
the index and return only some attributes from the child relation. For
example:

Entity: {
Name: John Doe,
Objects: [
{
User: A
},
{
User: B
},
]
},
Entity: {
Name: Michael Doe,
Objects: []
}.

User A should be able to see all Entities, but only with the objects
associated with him. So we want to retrieve all entities but only return
its child elements that match User=A. With the small sample from above,
both entities would be returned but John Doe would have only one child
element (the first one). We cannot simply filter Objects.User = A, because
that would filter out the parent entities that don't have that child (for
example, with Objects:[{User=B}]).

Another approach, would be to sort (with basic sort or via script) based on
the child attribute, that way elements would be filtered out, but there
would be the need to have some post processing step to remove unwanted
objects.

I've found some open issues regarding parent/child sorting and inner
objects but they are, as said, open:

https://github.com/elasticsearch/elasticsearch/issues/2917 - Sorting based
on parent/child relationship
https://github.com/elasticsearch/elasticsearch/issues/3022 - Return
matching nested inner objects per hit

The scenario doesn't seem that "strange" or uncommon and it's probably been
addressed before. Is there a a solution to perform such sorting/filterring
with a single query ?
We are also checking on the possiblity on having two indexe but, in that
case, we always end up with some extra parsing between the two queries,
that (maybe) could end up consuming too much (time/memory?).

Thanks in advance

--
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/f80e5bec-cec2-406b-954e-05eb5fdcf7ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.