title: Get faceted results based on query only
body: <p>I have some posts data and I use elasticsearch to search in title of these posts. Then I use filters to filter results based on category ids and some other parameters. What I'm trying to do is to get all categories of posts that matches the query criteria and ignore the filter.</p>
  
  <p>Here is my what I have done so far. This is the query part:</p>
  
  <pre><code>if ( ! empty($search) )
  {
      $query['multi_match'] = array(
          'query' =&gt; $search,
          'fields' =&gt; array('title', 'title_en')
      );
  }
  </code></pre>
  
  <p>Then I apply some filters:</p>
  
  <pre><code>if ( ! empty($loc) )
  {
      $filter['bool']['must'][]['geo_distance'] = array(
          'distance' =&gt; $distance . 'meters',
          'loc'      =&gt; $loc
      );
  }
  
  if ( isset($category) )
  {
      $filter['bool']['must'][]['terms'] = array(
          'categories' =&gt; $category
      );
  }
  </code></pre>
  
  <p>And then I facet part:</p>
  
  <pre><code>$facets = array(
      'categories' =&gt; array(
          'terms' =&gt; array(
              'field' =&gt; 'categories'
          )
      )
  );
  </code></pre>
  
  <p>and the final part:</p>
  
  <pre><code>$searchParams['body']['query']['filtered'] = array(
      'query'  =&gt; $query,
      'filter' =&gt; $filter,
  );
  $searchParams['body']['facets'] = $facets;
  </code></pre>
  
  <p>The problem is that when I apply <code>geo_distance</code> or some other filters, this affects what is returned by the facet. I want the facet to be affected by the query only, so if the <code>$search</code> variable returns 100 results and then geo distance reduces that to 10, facet should return all categories from that 100 results, not 10. Is that possible using elasticsearch?</p>