# Aggregate across doctype?

**URL:** <https://discuss.elastic.co/t/aggregate-across-doctype/1104>\
**Category:** Elasticsearch\
**Created:** [May 21, 2015, 3:11pm UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104 "2015-05-21T15:11:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cching](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cching/32/44800_2.png) [@cching](https://discuss.elastic.co/u/cching)\
**Post date:** [May 21, 2015, 3:11pm UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104/1 "2015-05-21T15:11:43Z")

</div>

Is it possible to aggregate across doctype? What I'm wanting to do is given doctypes of 'people', 'bears', 'lions, a search for 'leo' would find, say, the top 10 hits in each doctype of 'people', 'bears', 'lions'. Alternatively, I could add a doctype field to each document, but that seems wasteful.

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 21, 2015, 3:31pm UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104/2 "2015-05-21T15:31:21Z")

</div>

the problem is that you can not ask for a precise number of hist for each type, but you can use [\_msearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html) in msearch you can made 3 different request, one for each type in the same request HTTP. by this way you can be sure to have the same number of results at least for each type

---

<div class="post-metadata">

**Author:** ![cching](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cching/32/44800_2.png) [@cching](https://discuss.elastic.co/u/cching)\
**Post date:** [May 21, 2015, 3:33pm UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104/3 "2015-05-21T15:33:05Z")

</div>

Oh, nice, I hadn't thought of that, thanks for the suggestion!

---

<div class="post-metadata">

**Author:** ![cching](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cching/32/44800_2.png) [@cching](https://discuss.elastic.co/u/cching)\
**Post date:** [May 21, 2015, 4:03pm UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104/4 "2015-05-21T16:03:58Z")

</div>

I've run into a little snag with using \_msearch. I realized that I also need suggest cross-doctype as well. Is there an equivalent for suggest?

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 21, 2015, 4:13pm UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104/5 "2015-05-21T16:13:12Z")

</div>

i never tried with suggest but the \_msearch have the "search\_type" this give you the possibility to use par example the \_count API so you can test to do something like :

```
{"index" : "test", "search_type" : "suggest"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 10}

```

keep me posted if that works @cching ! 😉

---

<div class="post-metadata">

**Author:** ![cching](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cching/32/44800_2.png) [@cching](https://discuss.elastic.co/u/cching)\
**Post date:** [May 21, 2015, 4:39pm UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104/6 "2015-05-21T16:39:24Z")

</div>

I'll give that a try and post back. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![cching](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cching/32/44800_2.png) [@cching](https://discuss.elastic.co/u/cching)\
**Post date:** [May 21, 2015, 7:46pm UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104/7 "2015-05-21T19:46:39Z")

</div>

Using search\_type:"suggest" does not work:

{  
"error": "ElasticsearchIllegalArgumentException[No search type for [suggest]]",  
"status": 400  
}

Neither does using the \_msearch endpoint with something like:

{ "suggest" : { "my-suggest" : { "text" : "n", "completion" : { "field" : "suggest" } } } }

Thanks for the help, though, it's much appreciated. Guess I might have to make multiple requests manually.

---

<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:12am UTC](https://discuss.elastic.co/t/aggregate-across-doctype/1104/8 "2017-07-06T00:12:32Z")

</div>


