# Wanted to combine two different result set in one query

**URL:** https://discuss.elastic.co/t/wanted-to-combine-two-different-result-set-in-one-query/252962
**Category:** Elasticsearch
**Created:** [October 22, 2020, 8:32am UTC](https://discuss.elastic.co/t/wanted-to-combine-two-different-result-set-in-one-query/252962 "2020-10-22T08:32:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dattack13](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dattack13/32/70452_2.png) [@dattack13](https://discuss.elastic.co/u/dattack13)
#### Post date: [October 22, 2020, 8:32am UTC](https://discuss.elastic.co/t/wanted-to-combine-two-different-result-set-in-one-query/252962/1 "2020-10-22T08:32:42Z")

</div>

Hi There,

I have requirement where I need to combine two different result based on different filter criteria for example one query is filtering records based on some true & false indicator and then other query is filtering record on country location. After combining both the record I want to combine both result and then select only do the sizing (including both the records I want only 10 or 20), Can someone help me here -

```
{
  "size": 20,
  "sort": [
    {
      "virtualOnly": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "true",
            "operator": "and",
            "fields": [
              "virtualOnly"
            ]
          }
        }
      ],
      "should": [
        {"match": {
          "address.country.code": "US"
        }}
      ]
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 22, 2020, 9:49am UTC](https://discuss.elastic.co/t/wanted-to-combine-two-different-result-set-in-one-query/252962/2 "2020-10-22T09:49:08Z")

</div>

if you put two queries in a boolean query `should` clause this will act as an OR.

You cannot select the size based on some search criteria - which is how I understood your question, but maybe I got it wrong.

---

<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: [October 22, 2020, 9:50am UTC](https://discuss.elastic.co/t/wanted-to-combine-two-different-result-set-in-one-query/252962/3 "2020-10-22T09:50:25Z")

</div>

Also have a look at the multisearch API.  
May be that could work for you.

---

<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 19, 2020, 9:50am UTC](https://discuss.elastic.co/t/wanted-to-combine-two-different-result-set-in-one-query/252962/4 "2020-11-19T09:50:28Z")

</div>

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