title: Aggregation with OR filter
body: <p>I have an index of jBPM usertasks. Each usertask has <code>id</code>, <code>actualOwner</code> and <code>actualOwner.keyword</code>, <code>potentialOwners</code> and <code>potentialOwners.keyword</code>, and <code>processId</code> fields.</p>
  <p>I need this aggregation: count of usertasks per process for some user. User task belongs to user if it's <code>actualOwner</code> or <code>potentialOwner</code> is that user. And in some statuses.</p>
  <p>Seems that is very easy query, but I cannot write it. I try this:</p>
  <pre><code>POST jbpm-tasks/_search?size=1000
  {
    &quot;query&quot;: {
      &quot;bool&quot;: {
        &quot;should&quot;: [
          { 
            &quot;term&quot;: {
              &quot;actualOwner.keyword&quot;: {
                &quot;value&quot;: &quot;vasya&quot;
              }
            }
          },
          {
            &quot;term&quot;: {
              &quot;potentialOwners.keyword&quot;: {
                &quot;value&quot;: &quot;vasya&quot;
              }
            }
          }
        ],
        &quot;must&quot;: [
          {
            &quot;terms&quot;: {
              &quot;status.keyword&quot;: [
                &quot;Created&quot;,
                &quot;Reserved&quot;,
                &quot;InProgress&quot;,
                &quot;Ready&quot;
              ]
            }
          }
        ]
      }
    },
    &quot;aggs&quot;: {
      &quot;byProcesses&quot;: {
        &quot;terms&quot;: { &quot;field&quot;: &quot;processId.keyword&quot;, &quot;size&quot;: 1000000 } 
      }
    }
  }
  </code></pre>
  <p>Query as I understand does not filter, it calculate score only. So, for this query really not matter user login, for <code>vasya</code> and. for example, <code>fedya</code> request returns same aggregation results (with different scores for tasks, but it is not interesting for now).</p>
  <p>I not understand how write filter aggregation for multiple filter with <code>OR</code> and <code>AND</code> formula. In all examples always one field...</p>
  <p>How to write this query properly?</p>