# Elasticsearch bool should filter with result limit

**URL:** https://discuss.elastic.co/t/elasticsearch-bool-should-filter-with-result-limit/28012
**Category:** Elasticsearch
**Created:** [August 25, 2015, 1:40pm UTC](https://discuss.elastic.co/t/elasticsearch-bool-should-filter-with-result-limit/28012 "2015-08-25T13:40:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tushar](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@tushar](https://discuss.elastic.co/u/tushar)
#### Post date: [August 25, 2015, 1:40pm UTC](https://discuss.elastic.co/t/elasticsearch-bool-should-filter-with-result-limit/28012/1 "2015-08-25T13:40:56Z")

</div>

in the below query I want only 1 results from department "a" and two from "b"  
but when I run the query the results are empty. Can anyone please tell  
me where am I going wrong

```
{
                  "query": {
                    "range": {
                      "Date": {
                        "gte": "1440364380",
                         "lte": "1440450780"
                      }
                    }
                  },
                  "filter": {
                    "bool": {
                      "should": [
                        {
                          "term": {
                            "Department": "a"
                             size:1

                                 },
                          "term": {
                            "Department": "b"
                             size:2

                                 }
                        }
                      ]
                    }
                  },"sort": [
                    {
                      "Date": {
                        "order": "desc"
                      }
                    }
                  ]
                }
```

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [August 25, 2015, 1:54pm UTC](https://discuss.elastic.co/t/elasticsearch-bool-should-filter-with-result-limit/28012/2 "2015-08-25T13:54:56Z")

</div>

There is no `size` parameter on the term query. If you want to get 1 result from department A and 2 from department b, you need to run two queries.

---

<div class="post-metadata">

### Author: ![tushar](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@tushar](https://discuss.elastic.co/u/tushar)
#### Post date: [September 20, 2015, 12:59pm UTC](https://discuss.elastic.co/t/elasticsearch-bool-should-filter-with-result-limit/28012/3 "2015-09-20T12:59:28Z")

</div>

Is there any other work around, because I have 20 conditions to match with the limit if I run a loop of individual queries the response is very very slow.

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [September 24, 2015, 10:15am UTC](https://discuss.elastic.co/t/elasticsearch-bool-should-filter-with-result-limit/28012/4 "2015-09-24T10:15:28Z")

</div>

Have you tried running them in a multi-search request? [https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-multi-search.html](https://www.elastic.co/guide/en/elasticsearch/reference/1.7/search-multi-search.html)

---

<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 5, 2017, 11:48pm UTC](https://discuss.elastic.co/t/elasticsearch-bool-should-filter-with-result-limit/28012/5 "2017-07-05T23:48:17Z")

</div>


