title: elasticSearch: how to query with collapse
body: <p>I'd like to get a query result with two different part,</p>
  <ul>
  <li>query docs with field X and collapse on it.</li>
  <li>query docs without field X</li>
  <li>pagination based on queries above</li>
  </ul>
  <p>For example, I have docs:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>docID</th>
  <th>Field X</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>a</td>
  </tr>
  <tr>
  <td>2</td>
  <td>a</td>
  </tr>
  <tr>
  <td>3</td>
  <td>null</td>
  </tr>
  <tr>
  <td>4</td>
  <td>b</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>There are 4 docs, doc 1 and 2 have same X value, doc 3 have no value at X, doc 4 have unique value.</p>
  <p>So the target docs should be (1 or 2), 3 and 4, and I need to add pagination condition (from + size)here</p>
  <p>Is there any way to do this? now I have a collapse query but can only get doc(1 or 2)</p>
  <pre><code>GET job_info/_search
  {
    &quot;_source&quot;: false,
    &quot;aggregations&quot;: {
      &quot;total&quot;: {
         &quot;cardinality&quot;: {
             &quot;field&quot;: &quot;x.keyword&quot;
         }
       }
     },
    &quot;collapse&quot;: {
       &quot;field&quot;: &quot;x.keyword&quot;
     },
    &quot;from&quot;: 0,
    &quot;query&quot;: {
      &quot;bool&quot;: {
        &quot;must&quot;: [
          {
            &quot;terms&quot;: {
               &quot;other_condition1&quot;: [
                    1101
                ]
             }
          },
          {
            &quot;match&quot;: {
               &quot;other_condition1&quot;: {
                   &quot;query&quot;: &quot;abc&quot;
                }
            }
           }
        ]
      }
    },
    &quot;size&quot;: 10,
    &quot;track_total_hits&quot;: true
  }
  </code></pre>