title: How to do nested AND and OR filters in ElasticSearch?
body: <p>My filters are grouped together into categories.
  I would like to retrieve documents where a document can match any filter in a category, but if two (or more) categories are set, then the document must match any of the filters in ALL categories.</p>
  
  <p>If written in pseudo-SQL it would be:</p>
  
  <pre><code>SELECT * FROM Documents WHERE (CategoryA = 'A') AND (CategoryB = 'B' OR CategoryB = 'C')
  </code></pre>
  
  <p>I've tried Nested filters like so:</p>
  
  <pre><code>{
      "sort": [{
          "orderDate": "desc"
      }],
      "size": 25,
      "query": {
          "match_all": {}
      },
      "filter": {
          "and": [{
              "nested": {
                  "path":"hits._source",
                  "filter": {
                      "or": [{
                          "term": {
                              "progress": "incomplete"
                          }
                      }, {
                          "term": {
                              "progress": "completed"
                          }
                      }]
                  }
              }
          }, {
              "nested": {
                  "path":"hits._source",
                  "filter": {
                      "or": [{
                          "term": {
                              "paid": "yes"
                          }
                      }, {
                          "term": {
                              "paid": "no"
                          }
                      }]
                  }
              }
          }]
      }
  }
  </code></pre>
  
  <p>But evidently I don't quite understand the ES syntax. Is this on the right track or do I need to use another filter?</p>