# Unified search across document types question?

**URL:** <https://discuss.elastic.co/t/unified-search-across-document-types-question/9759>\
**Category:** Elasticsearch\
**Created:** [November 19, 2012, 2:47pm UTC](https://discuss.elastic.co/t/unified-search-across-document-types-question/9759 "2012-11-19T14:47:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Umit\_Seren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/umit_seren/32/44933_2.png) [@Umit\_Seren](https://discuss.elastic.co/u/Umit_Seren)\
**Post date:** [November 19, 2012, 2:47pm UTC](https://discuss.elastic.co/t/unified-search-across-document-types-question/9759/1 "2012-11-19T14:47:30Z")

</div>

I am trying to implement something similar to the unified search box of  
last fm ([http://ui-patterns.com/users/1/collections/554/entry/2961](http://ui-patterns.com/users/1/collections/554/entry/2961))  
However I have some problems/issues.

let's say I have 3 document types (A, B and C) and I want to implement one  
unified search box which returns results group by their document type (see  
link above)

If I search in type A (/index/A/\_search?q=someString\* ) I get 1 hit:  
If I search in type B (/index/B/\_search?q=someString\*) I get 108 hits.  
By default only the top 10 hits are returned.

Now if I search in both document types (/index/A,B/\_search?q=someString\*) I  
get 109 hits. It again only displays the top 10 hits.  
However it only display hits from document type B and not the one from A.

Is there any easy way to return the same amount of hits for each document  
type in one search?  
Or do I have to do 3 distinct searches and then group them afterwards ? Can  
facets help me here?

thanks in advance

Ümit

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 19, 2012, 2:52pm UTC](https://discuss.elastic.co/t/unified-search-across-document-types-question/9759/2 "2012-11-19T14:52:36Z")

</div>

Perhaps Multi search is what you are looking for?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Does it help?

Le 19 novembre 2012 à 15:47, "Ümit Seren" [uemit.seren@gmail.com](mailto:uemit.seren@gmail.com) a écrit :

> I am trying to implement something similar to the unified search box of last  
> fm ( [http://ui-patterns.com/users/1/collections/554/entry/2961](http://ui-patterns.com/users/1/collections/554/entry/2961)  
> [http://ui-patterns.com/users/1/collections/554/entry/2961](http://ui-patterns.com/users/1/collections/554/entry/2961) )  
> However I have some problems/issues.
> 
> let's say I have 3 document types (A, B and C) and I want to implement one  
> unified search box which returns results group by their document type (see  
> link above)
> 
> If I search in type A (/index/A/\_search?q=someString\* ) I get 1 hit:  
> If I search in type B (/index/B/\_search?q=someString\*) I get 108 hits.  
> By default only the top 10 hits are returned.
> 
> Now if I search in both document types (/index/A,B/\_search?q=someString\*) I  
> get 109 hits. It again only displays the top 10 hits.  
> However it only display hits from document type B and not the one from A.
> 
> Is there any easy way to return the same amount of hits for each document  
> type in one search?  
> Or do I have to do 3 distinct searches and then group them afterwards ? Can  
> facets help me here?
> 
> thanks in advance
> 
> Ümit
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Umit\_Seren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/umit_seren/32/44933_2.png) [@Umit\_Seren](https://discuss.elastic.co/u/Umit_Seren)\
**Post date:** [November 19, 2012, 3:10pm UTC](https://discuss.elastic.co/t/unified-search-across-document-types-question/9759/3 "2012-11-19T15:10:11Z")

</div>

@David,  
Ah thanks. I apparently missed that part about multi serach. I will look  
into it. BTW are there some best practices for doing these kind of unified  
search across document types (think one should be aware of or take care)?

On Mon, Nov 19, 2012 at 3:52 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> \*\*  
> Perhaps Multi search is what you are looking for?
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/multi-search.html)
> 
> Does it help?
> 
> Le 19 novembre 2012 à 15:47, "Ümit Seren" [uemit.seren@gmail.com](mailto:uemit.seren@gmail.com) a  
> écrit :
> 
> I am trying to implement something similar to the unified search box of  
> last fm ( [http://ui-patterns.com/users/1/collections/554/entry/2961](http://ui-patterns.com/users/1/collections/554/entry/2961))  
> However I have some problems/issues.
> 
> let's say I have 3 document types (A, B and C) and I want to implement one  
> unified search box which returns results group by their document type (see  
> link above)
> 
> If I search in type A (/index/A/\_search?q=someString\* ) I get 1 hit:  
> If I search in type B (/index/B/\_search?q=someString\*) I get 108 hits.  
> By default only the top 10 hits are returned.
> 
> Now if I search in both document types (/index/A,B/\_search?q=someString\*)  
> I get 109 hits. It again only displays the top 10 hits.  
> However it only display hits from document type B and not the one from  
> A.
> 
> Is there any easy way to return the same amount of hits for each document  
> type in one search?  
> Or do I have to do 3 distinct searches and then group them afterwards ?  
> Can facets help me here?
> 
> thanks in advance
> 
> Ümit
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Umit\_Seren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/umit_seren/32/44933_2.png) [@Umit\_Seren](https://discuss.elastic.co/u/Umit_Seren)\
**Post date:** [November 20, 2012, 4:17pm UTC](https://discuss.elastic.co/t/unified-search-across-document-types-question/9759/4 "2012-11-20T16:17:14Z")

</div>

The Multi-search solves my problem.  
However using the JAVA API I ran into an issue with the returned hits.

I create a MutliSearchRequestBuilder and add 3 distinct  
SearchRequestBuilders to it and I specify the size to be 10 (using  
setSize()).  
However they always return 50 hits no matter which size I specify.  
Here is how the SearchRequestBuilder looks like:

{  
"size" : 10,  
"query" : {  
"multi\_match" : {  
"query" : "some text",  
"fields" : ["field1","field"]  
}  
}  
}

On Monday, November 19, 2012 3:52:45 PM UTC+1, David Pilato wrote:

> Perhaps Multi search is what you are looking for?
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/multi-search.html)
> 
> Does it help?
> 
> Le 19 novembre 2012 à 15:47, "Ümit Seren" \<[uemit...@gmail.com](mailto:uemit...@gmail.com)\<javascript:\>\>  
> a écrit :
> 
> I am trying to implement something similar to the unified search box of  
> last fm ( [http://ui-patterns.com/users/1/collections/554/entry/2961](http://ui-patterns.com/users/1/collections/554/entry/2961))  
> However I have some problems/issues.
> 
> let's say I have 3 document types (A, B and C) and I want to implement one  
> unified search box which returns results group by their document type (see  
> link above)
> 
> If I search in type A (/index/A/\_search?q=someString\* ) I get 1 hit:  
> If I search in type B (/index/B/\_search?q=someString\*) I get 108 hits.  
> By default only the top 10 hits are returned.
> 
> Now if I search in both document types (/index/A,B/\_search?q=someString\*)  
> I get 109 hits. It again only displays the top 10 hits.  
> However it only display hits from document type B and not the one from  
> A.
> 
> Is there any easy way to return the same amount of hits for each document  
> type in one search?  
> Or do I have to do 3 distinct searches and then group them afterwards ?  
> Can facets help me here?
> 
> thanks in advance
> 
> Ümit
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Umit\_Seren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/umit_seren/32/44933_2.png) [@Umit\_Seren](https://discuss.elastic.co/u/Umit_Seren)\
**Post date:** [November 20, 2012, 5:46pm UTC](https://discuss.elastic.co/t/unified-search-across-document-types-question/9759/5 "2012-11-20T17:46:08Z")

</div>

Ok forgot my message.  
I had set searchType by accident to QUERY\_AND\_FETCH instead of  
QUERY\_THEN\_FETCH.

On Tue, Nov 20, 2012 at 5:17 PM, Ümit Seren [uemit.seren@gmail.com](mailto:uemit.seren@gmail.com) wrote:

> The Multi-search solves my problem.  
> However using the JAVA API I ran into an issue with the returned hits.
> 
> I create a MutliSearchRequestBuilder and add 3 distinct  
> SearchRequestBuilders to it and I specify the size to be 10 (using  
> setSize()).  
> However they always return 50 hits no matter which size I specify.  
> Here is how the SearchRequestBuilder looks like:
> 
> {  
> "size" : 10,  
> "query" : {  
> "multi\_match" : {  
> "query" : "some text",  
> "fields" : ["field1","field"]  
> }  
> }  
> }
> 
> On Monday, November 19, 2012 3:52:45 PM UTC+1, David Pilato wrote:
> 
> > Perhaps Multi search is what you are looking for?
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/ **guide/reference/api/multi-** search.html)[http://www.elasticsearch.org/guide/reference/api/multi-search.html](http://www.elasticsearch.org/guide/reference/api/multi-search.html)
> > 
> > Does it help?
> > 
> > Le 19 novembre 2012 à 15:47, "Ümit Seren" [uemit...@gmail.com](mailto:uemit...@gmail.com) a écrit :
> > 
> > I am trying to implement something similar to the unified search box of  
> > last fm ( [http://ui-patterns.com/users/\*\*1/collections/554/entry/2961](http://ui-patterns.com/users/**1/collections/554/entry/2961)[http://ui-patterns.com/users/1/collections/554/entry/2961](http://ui-patterns.com/users/1/collections/554/entry/2961))
> > 
> > However I have some problems/issues.
> > 
> > let's say I have 3 document types (A, B and C) and I want to implement  
> > one unified search box which returns results group by their document type  
> > (see link above)
> > 
> > If I search in type A (/index/A/\_search?q=\*_someString_ ) I get 1  
> > hit:  
> > If I search in type B (/index/B/\_search?q=\*_someString_) I get 108  
> > hits.  
> > By default only the top 10 hits are returned.
> > 
> > Now if I search in both document types (/index/A,B/\_search?q=\*_someString_)  
> > I get 109 hits. It again only displays the top 10 hits.  
> > However it only display hits from document type B and not the one from  
> > A.
> > 
> > Is there any easy way to return the same amount of hits for each  
> > document type in one search?  
> > Or do I have to do 3 distinct searches and then group them afterwards ?  
> > Can facets help me here?
> > 
> > thanks in advance
> > 
> > Ümit
> > 
> > --
> > 
> > --  
> > David Pilato  
> > [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> > [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --

--

---

<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:03am UTC](https://discuss.elastic.co/t/unified-search-across-document-types-question/9759/6 "2017-07-06T03:03:30Z")

</div>


