# Query with calculated limit

**URL:** <https://discuss.elastic.co/t/query-with-calculated-limit/153514>\
**Category:** Elasticsearch\
**Created:** [October 23, 2018, 4:13am UTC](https://discuss.elastic.co/t/query-with-calculated-limit/153514 "2018-10-23T04:13:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrikerMan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brikerman/32/36811_2.png) [@BrikerMan](https://discuss.elastic.co/u/BrikerMan)\
**Post date:** [October 23, 2018, 4:13am UTC](https://discuss.elastic.co/t/query-with-calculated-limit/153514/1 "2018-10-23T04:13:54Z")

</div>

I have video model and album model, Like,

```auto
| video | title | album_id |
| ----- | --------- | -------- |
| 1 | apple A 1 | 1 |
| 2 | apple A 2 | 1 |
| 3 | apple A 3 | 1 |
| 4 | apple A 4 | 1 |
| 5 | apple A 5 | 1 |
| 6 | apple B 6 | 2 |
| 7 | apple B 7 | 2 |
| 8 | apple B 8 | 2 |
| 9 | apple B 9 | 2 |

```

Now I have to query videos with a limit that I should return at most 2 videos for each album. Like when I search `apple`, I need to get `[apple A 1, Apple A 2, Apple B 6, Apple B 7]`. Is there any way to do this?

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [October 23, 2018, 11:43am UTC](https://discuss.elastic.co/t/query-with-calculated-limit/153514/2 "2018-10-23T11:43:21Z")

</div>

Hi, I don't it is possible, but instead you can use the multi-search:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html)

bye  
Xavier

---

<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:** [November 20, 2018, 11:43am UTC](https://discuss.elastic.co/t/query-with-calculated-limit/153514/3 "2018-11-20T11:43:24Z")

</div>

Closed on November 20, 2018, 11:43am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
