title: Elasticsearch: Autocomplete on the available buckets in an aggregation
body: <p>boiled down to its essence the problem is that</p>
  
  <ul>
  <li>I have a multi-valued field of unanalysed strings (consider them as <code>tags</code>)</li>
  <li>I have an aggregation, which collects these tags</li>
  </ul>
  
  <p>Now the requirement is to be able to filter these aggregations by <code>tags</code> (which is the easy part) and provide prefix search on the set of available <code>tags</code> (the hard part) to have a neat drill-down feature.</p>
  
  <p>If I do a naive filter on the prefix (e.g. "Ge") of a <code>tag</code></p>
  
  <pre><code>   "aggregations": {
        "tags": {
           "filter": {
              "prefix": {
                 "tags": "Ge"
              }
           },
           "aggregations": {
              "tags": {
                 "terms": {
                    "field": "tags"
                 }
              }
           }
        }
  </code></pre>
  
  <p>it returns all <code>tags</code> that occur in a field where at least one <code>tag</code> starts with "G".</p>
  
  <p>Is there a way to fix that other than retrieve to many <code>tags</code> and then prefix-filter them "by hand". btw if think scripting like in <a href="https://stackoverflow.com/questions/26992154/elasticsearch-possible-to-process-aggregation-results">Elasticsearch: Possible to process aggregation results?</a> should not be necessary.</p>
  
  <p>thanks
  markus</p>