# Combine two queries like a OR statement

**URL:** <https://discuss.elastic.co/t/combine-two-queries-like-a-or-statement/204100>\
**Category:** Elasticsearch\
**Created:** [October 17, 2019, 4:36pm UTC](https://discuss.elastic.co/t/combine-two-queries-like-a-or-statement/204100 "2019-10-17T16:36:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Federico\_Pazos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/federico_pazos/32/56118_2.png) [@Federico\_Pazos](https://discuss.elastic.co/u/Federico_Pazos)\
**Post date:** [October 17, 2019, 4:36pm UTC](https://discuss.elastic.co/t/combine-two-queries-like-a-or-statement/204100/1 "2019-10-17T16:36:30Z")

</div>

Hi! I'm trying to create an Elastic Search query to modify the data received but I don't have much knowledge about Elastic and I don't know how to accomplish that.

I have my "tasks" data with three properties, **assignedToGroup** , **assignedToRole** and **assignedToUser**.  
This is the actual query that doesn't include the field **assignedToRole** because is new:

```
   {
  "_source": {
    "includes": [
      "taskId",
      "tenantId-createdAt-circuitId",
      "assignedToGroup",
      "assignedToUser",
      "circuitId",
      "createdAt",
      "createdByRole",
      "currentStatus",
      "taskType",
      "tenantId",
      "history",
      "payload",
      "slaExpiresAt",
      "taskDefinitionName",
      "taskDefinitionId",
      "input"
    ]
  },
  "sort": [
    {
      "createdAt": {
        "order": "desc"
      }
    }
  ],
  "size": 20,
  "from": 0,
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "match": {
                "tenantId.keyword": "tenant1"
              }
            },
            {
              "range": {
                "createdAt": {
                  "gte": "now-1y/d",
                  "lte": "now+1d/d"
                }
              }
            }
          ],
          "should": [
            {
              "match": {
                "createdByGroup.keyword": "0"
              }
            },
            {
              "match": {
                "assignedToGroup": "0"
              }
            }
          ]
        }
      },
      "should": [
        {
          "match": {
            "assignedToUser.keyword": "oficialsucursal1@btekstudio1.onmicrosoft.com"
          }
        },
        {
          "match": {
            "createdByUser.keyword": "oficialsucursal1@btekstudio1.onmicrosoft.com"
          }
        }
      ]
    }
  }
}

```

This is my mapping [https://pastebin.com/yE6PGLDQ](https://pastebin.com/yE6PGLDQ)

So as an user with specific group and role, I need to:

- Receive tasks assigned to the user
- Receive tasks assigned to the user's group
- Receive tasks assigned to the user's role

OR

- Receive tasks without role assigned but with user's group

---

<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 14, 2019, 4:36pm UTC](https://discuss.elastic.co/t/combine-two-queries-like-a-or-statement/204100/2 "2019-11-14T16:36:33Z")

</div>

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