# Segregating search results by document type

**URL:** <https://discuss.elastic.co/t/segregating-search-results-by-document-type/17336>\
**Category:** Elasticsearch\
**Created:** [May 4, 2014, 3:34pm UTC](https://discuss.elastic.co/t/segregating-search-results-by-document-type/17336 "2014-05-04T15:34:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rex\_Bradford](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rex_bradford/32/1598_2.png) [@Rex\_Bradford](https://discuss.elastic.co/u/Rex_Bradford)\
**Post date:** [May 4, 2014, 3:34pm UTC](https://discuss.elastic.co/t/segregating-search-results-by-document-type/17336/1 "2014-05-04T15:34:05Z")

</div>

I am working on a first elasticsearch project, where I am displaying a  
search results page with hits segregated by type.

The types in this case are things like essays, journals, photos, reports,  
etc., 9 total, though what they are is irrelevant. I currently store them  
all in the same index; each type has its own mappings so I can support  
special fields (e.g., photographer) in search results.

The main search results page displays 9 sections, segregated by type, with  
up to N results in each.

I have this up and running, but only by running 9 searches in parallel to  
get the top N hits in each type. Each query is of the form:  
[http://website:9200/index/type/\_search…](http://website:9200/index/type/_search%E2%80%A6)..

For the primary search page, I hate to run 9 elasticsearch queries when  
somebody types in a query - is there a way to do this with a single query?  
The problem with that, implemented naively anyway, is that I would like  
the top N hits for each type even if they are not high scoring - in other  
words, if the top 30 hits are essays I still would like to display the top  
3 photos, and not 0 photos because none of them score high enough.

Rex Bradford

--  
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/70a4517d-f493-4fe7-9be4-8b71af1855fe%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/70a4517d-f493-4fe7-9be4-8b71af1855fe%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, 1:31am UTC](https://discuss.elastic.co/t/segregating-search-results-by-document-type/17336/2 "2017-07-06T01:31:54Z")

</div>


