# Search results grouping (aka field combining/collapsing, distinct, de-dup) or alternate sollution

**URL:** <https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693>\
**Category:** Elasticsearch\
**Created:** [August 9, 2012, 2:23pm UTC](https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693 "2012-08-09T14:23:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Lopez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_lopez/32/2754_2.png) [@Alex\_Lopez](https://discuss.elastic.co/u/Alex_Lopez)\
**Post date:** [August 9, 2012, 2:23pm UTC](https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693/1 "2012-08-09T14:23:25Z")

</div>

Hi!

I just built the current 0.20.0 snapshot and I was wondering what is the  
evolution of the issue discussed here:

> <https://github.com/elastic/elasticsearch/issues/256>

Is it possible to use anything of this sort with the current 0.20.0  
snapshot?

I'll try to explain our issue to see if it can be resolved in another way  
if search grouping is still far from implemented:

We have users that can have several roles (one or many), currently each  
user-role is indexed as one independent document. We want to search by user  
name, and get only one result per user (it does not matter which). So  
ideally we would like to group by user name. I have been reading about  
nested documents, and parent/child relationships. (Are they related?) Which  
one would better cover our use-case? Note that we might index different  
user-roles at different times, so perhaps parent-child indexing is more  
suited. Is parent mapping always done at type level? (Can we index a  
document and tell ES which is its parent document, or is it always infered  
from their respective types?)

Thanks for such an excellent search engine and thanks in advance for any  
clarifications on our issue!

---

<div class="post-metadata">

**Author:** ![Alex\_Lopez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_lopez/32/2754_2.png) [@Alex\_Lopez](https://discuss.elastic.co/u/Alex_Lopez)\
**Post date:** [August 9, 2012, 4:34pm UTC](https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693/2 "2012-08-09T16:34:45Z")

</div>

Sorry for the premature questions on parent-child relationships, I think  
we'll go for a solution implemented using parent field mapping and some  
ORed has\_child filters (ala

> **[Fun with elasticsearch's children and nested documents - Space Vatican](https://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/)**
>
> When you’re indexing data, the world is rarely as simple as each document existing in isolation. Sometimes, you’re better off …

).

On Thursday, August 9, 2012 3:23:25 PM UTC+1, Alex López wrote:

> Hi!
> 
> I just built the current 0.20.0 snapshot and I was wondering what is the  
> evolution of the issue discussed here:
> 
> [Field Collapsing/Combining · Issue #256 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/256)
> 
> Is it possible to use anything of this sort with the current 0.20.0  
> snapshot?
> 
> I'll try to explain our issue to see if it can be resolved in another way  
> if search grouping is still far from implemented:
> 
> We have users that can have several roles (one or many), currently each  
> user-role is indexed as one independent document. We want to search by user  
> name, and get only one result per user (it does not matter which). So  
> ideally we would like to group by user name. I have been reading about  
> nested documents, and parent/child relationships. (Are they related?) Which  
> one would better cover our use-case? Note that we might index different  
> user-roles at different times, so perhaps parent-child indexing is more  
> suited. Is parent mapping always done at type level? (Can we index a  
> document and tell ES which is its parent document, or is it always infered  
> from their respective types?)
> 
> Thanks for such an excellent search engine and thanks in advance for any  
> clarifications on our issue!

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 9, 2012, 5:52pm UTC](https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693/3 "2012-08-09T17:52:49Z")

</div>

Lucene 4 will have (has) a grouping API:  
[http://lucene.apache.org/core/4\_0\_0-ALPHA/grouping/index.html](http://lucene.apache.org/core/4_0_0-ALPHA/grouping/index.html)

It might be worthwhile to adhere to the Lucene API and not recreate  
something that is not portable. Shay's call. That said, Lucene 4 is  
still only in alpha, and since the API might change, so coding against  
it might be a bit premature. Perhaps Simon W has some more insight.

Cheers,

Ivan

On Thu, Aug 9, 2012 at 9:34 AM, Alex López [aliksandr@gmail.com](mailto:aliksandr@gmail.com) wrote:

> Sorry for the premature questions on parent-child relationships, I think  
> we'll go for a solution implemented using parent field mapping and some ORed  
> has\_child filters (ala  
> [Fun with elasticsearch's children and nested documents - Space Vatican](http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/)  
> ).
> 
> On Thursday, August 9, 2012 3:23:25 PM UTC+1, Alex López wrote:
> 
> > Hi!
> > 
> > I just built the current 0.20.0 snapshot and I was wondering what is the  
> > evolution of the issue discussed here:
> > 
> > [Field Collapsing/Combining · Issue #256 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/256)
> > 
> > Is it possible to use anything of this sort with the current 0.20.0  
> > snapshot?
> > 
> > I'll try to explain our issue to see if it can be resolved in another way  
> > if search grouping is still far from implemented:
> > 
> > We have users that can have several roles (one or many), currently each  
> > user-role is indexed as one independent document. We want to search by user  
> > name, and get only one result per user (it does not matter which). So  
> > ideally we would like to group by user name. I have been reading about  
> > nested documents, and parent/child relationships. (Are they related?) Which  
> > one would better cover our use-case? Note that we might index different  
> > user-roles at different times, so perhaps parent-child indexing is more  
> > suited. Is parent mapping always done at type level? (Can we index a  
> > document and tell ES which is its parent document, or is it always infered  
> > from their respective types?)
> > 
> > Thanks for such an excellent search engine and thanks in advance for any  
> > clarifications on our issue!

---

<div class="post-metadata">

**Author:** ![Alex\_Lopez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_lopez/32/2754_2.png) [@Alex\_Lopez](https://discuss.elastic.co/u/Alex_Lopez)\
**Post date:** [August 10, 2012, 9:29am UTC](https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693/4 "2012-08-10T09:29:35Z")

</div>

Thanks for the feedback, I read that version 0.20.0 was getting some  
refactoring to allow for this kind of queries, but I guess waiting for  
Lucene 4 API to freeze makes sense anyway.

2012/8/9 Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com):

> Lucene 4 will have (has) a grouping API:  
> [Lucene 4.0.0 API](http://lucene.apache.org/core/4_0_0-ALPHA/grouping/index.html)
> 
> It might be worthwhile to adhere to the Lucene API and not recreate  
> something that is not portable. Shay's call. That said, Lucene 4 is  
> still only in alpha, and since the API might change, so coding against  
> it might be a bit premature. Perhaps Simon W has some more insight.
> 
> Cheers,
> 
> Ivan
> 
> On Thu, Aug 9, 2012 at 9:34 AM, Alex López [aliksandr@gmail.com](mailto:aliksandr@gmail.com) wrote:
> 
> > Sorry for the premature questions on parent-child relationships, I think  
> > we'll go for a solution implemented using parent field mapping and some ORed  
> > has\_child filters (ala  
> > [Fun with elasticsearch's children and nested documents - Space Vatican](http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/)  
> > ).
> > 
> > On Thursday, August 9, 2012 3:23:25 PM UTC+1, Alex López wrote:
> > 
> > > Hi!
> > > 
> > > I just built the current 0.20.0 snapshot and I was wondering what is the  
> > > evolution of the issue discussed here:
> > > 
> > > [Field Collapsing/Combining · Issue #256 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/256)
> > > 
> > > Is it possible to use anything of this sort with the current 0.20.0  
> > > snapshot?
> > > 
> > > I'll try to explain our issue to see if it can be resolved in another way  
> > > if search grouping is still far from implemented:
> > > 
> > > We have users that can have several roles (one or many), currently each  
> > > user-role is indexed as one independent document. We want to search by user  
> > > name, and get only one result per user (it does not matter which). So  
> > > ideally we would like to group by user name. I have been reading about  
> > > nested documents, and parent/child relationships. (Are they related?) Which  
> > > one would better cover our use-case? Note that we might index different  
> > > user-roles at different times, so perhaps parent-child indexing is more  
> > > suited. Is parent mapping always done at type level? (Can we index a  
> > > document and tell ES which is its parent document, or is it always infered  
> > > from their respective types?)
> > > 
> > > Thanks for such an excellent search engine and thanks in advance for any  
> > > clarifications on our issue!

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 14, 2012, 9:51pm UTC](https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693/5 "2012-08-14T21:51:33Z")

</div>

Lucene 4.0 is now in beta:  
[http://search-lucene.com/m/9LhyoLfdKY&subj=+ANNOUNCE+Apache+Lucene+4+0+beta+released+](http://search-lucene.com/m/9LhyoLfdKY&subj=+ANNOUNCE+Apache+Lucene+4+0+beta+released+)

Hopefully the full release will happen on schedule around September/October.

On Fri, Aug 10, 2012 at 2:29 AM, Alex Rodriguez Lopez  
[aliksandr@gmail.com](mailto:aliksandr@gmail.com) wrote:

> Thanks for the feedback, I read that version 0.20.0 was getting some  
> refactoring to allow for this kind of queries, but I guess waiting for  
> Lucene 4 API to freeze makes sense anyway.
> 
> 2012/8/9 Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com):
> 
> > Lucene 4 will have (has) a grouping API:  
> > [Lucene 4.0.0 API](http://lucene.apache.org/core/4_0_0-ALPHA/grouping/index.html)
> > 
> > It might be worthwhile to adhere to the Lucene API and not recreate  
> > something that is not portable. Shay's call. That said, Lucene 4 is  
> > still only in alpha, and since the API might change, so coding against  
> > it might be a bit premature. Perhaps Simon W has some more insight.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Thu, Aug 9, 2012 at 9:34 AM, Alex López [aliksandr@gmail.com](mailto:aliksandr@gmail.com) wrote:
> > 
> > > Sorry for the premature questions on parent-child relationships, I think  
> > > we'll go for a solution implemented using parent field mapping and some ORed  
> > > has\_child filters (ala  
> > > [Fun with elasticsearch's children and nested documents - Space Vatican](http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/)  
> > > ).
> > > 
> > > On Thursday, August 9, 2012 3:23:25 PM UTC+1, Alex López wrote:
> > > 
> > > > Hi!
> > > > 
> > > > I just built the current 0.20.0 snapshot and I was wondering what is the  
> > > > evolution of the issue discussed here:
> > > > 
> > > > [Field Collapsing/Combining · Issue #256 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/256)
> > > > 
> > > > Is it possible to use anything of this sort with the current 0.20.0  
> > > > snapshot?
> > > > 
> > > > I'll try to explain our issue to see if it can be resolved in another way  
> > > > if search grouping is still far from implemented:
> > > > 
> > > > We have users that can have several roles (one or many), currently each  
> > > > user-role is indexed as one independent document. We want to search by user  
> > > > name, and get only one result per user (it does not matter which). So  
> > > > ideally we would like to group by user name. I have been reading about  
> > > > nested documents, and parent/child relationships. (Are they related?) Which  
> > > > one would better cover our use-case? Note that we might index different  
> > > > user-roles at different times, so perhaps parent-child indexing is more  
> > > > suited. Is parent mapping always done at type level? (Can we index a  
> > > > document and tell ES which is its parent document, or is it always infered  
> > > > from their respective types?)
> > > > 
> > > > Thanks for such an excellent search engine and thanks in advance for any  
> > > > clarifications on our issue!

--

---

<div class="post-metadata">

**Author:** ![Jim\_Hazen](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jim\_Hazen](https://discuss.elastic.co/u/Jim_Hazen)\
**Post date:** [October 8, 2012, 11:59pm UTC](https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693/6 "2012-10-08T23:59:25Z")

</div>

I'm also eagerly awaiting this feature. I'm developing a catalog of  
applications (think app store). Let's say you'd like to page through a  
list of applications where the results displayed contain the highest  
version of the app you have access to (based on a number of factors). This  
is very difficult to do outside of the search engine while maintaining the  
appropriate paging values.

Like you say, if there's a way to do this with the .19 or .20 beta  
releases, I'd love to understand it as well.

--

---

<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, 3:09am UTC](https://discuss.elastic.co/t/search-results-grouping-aka-field-combining-collapsing-distinct-de-dup-or-alternate-sollution/8693/7 "2017-07-06T03:09:39Z")

</div>


