# Sorting/retrieving a subset of child attributes

**URL:** <https://discuss.elastic.co/t/sorting-retrieving-a-subset-of-child-attributes/20741>\
**Category:** Elasticsearch\
**Created:** [November 13, 2014, 11:12pm UTC](https://discuss.elastic.co/t/sorting-retrieving-a-subset-of-child-attributes/20741 "2014-11-13T23:12:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpinBoldak](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@SpinBoldak](https://discuss.elastic.co/u/SpinBoldak)\
**Post date:** [November 13, 2014, 11:12pm UTC](https://discuss.elastic.co/t/sorting-retrieving-a-subset-of-child-attributes/20741/1 "2014-11-13T23:12:42Z")

</div>

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](https://github.com/elasticsearch/elasticsearch/issues/2917) - Sorting based  
on parent/child relationship  
[https://github.com/elasticsearch/elasticsearch/issues/3022](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/f80e5bec-cec2-406b-954e-05eb5fdcf7ac%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:50am UTC](https://discuss.elastic.co/t/sorting-retrieving-a-subset-of-child-attributes/20741/2 "2017-07-06T00:50:03Z")

</div>

Closed on July 6, 2017, 12:50am UTC


