title: Use distinct and where clause in Elasticsearch Query
body: <p>I want to get result from <code>Elasticsearch</code> as Sql Query</p>
  
  <pre><code>select distinct(id) from table where E_id in (5,6) and P_id=54
  </code></pre>
  
  <p>I manged to build block of code to get distinct values using aggregates in elasticsearch as follows  </p>
  
  <pre><code>GET /Index/Type/_search?search_type=count
  {
    "aggs": {
      "my_fields": {
        "terms": {
          "field": "ID",
          "size": 0
        }
      }
    }
  }
  </code></pre>
  
  <p>and I have another block of code which does <code>where</code> clause job of <code>SQL</code> query</p>
  
  <pre><code>GET /index/type/_search
  {
      "query": {
          "bool": {            
              "must": [
                 {
                    "terms": {
                      "ID": [ "5","6" ]          
                    }
                  },
                  {
                    "terms": {
                      "ProjectID": [ "54"]
                    }
                  }
              ]
          }
      }
  }
  </code></pre>
  
  <p>How can I integrate these two blocks and get distinct result with <code>where</code> clause in elasticsearch.</p>