title: How can I get per-document significant terms aggregations in Elasticsearch?
body: <p>In Elasticsearch, my index has fields with the following definitions:</p>
  
  <pre><code>"my_id": {
      "type": "keyword"
  },
  "titles": {
      "type": "keyword",
       "fields": {
            "fulltext": {
                "type": "text"
            }
       }
  }
  </code></pre>
  
  <p>I store multiple <code>titles</code> per document (basically a string array).</p>
  
  <p>Suppose I index a document with the following:</p>
  
  <ul>
  <li>my_id = "MH123"</li>
  <li>titles = [ "Star Wars: A New Hope", "Star Wars: Return of the Jedi", "Star Wars: "Empire Strikes Back" ]</li>
  </ul>
  
  <p>I want to return <code>significant_terms</code> aggregations based on each document ID. e.g...</p>
  
  <ul>
  <li>Where my_id = "MH123"</li>
  <li>The significant terms are: "Star Wars"</li>
  </ul>
  
  <p>I know how to do this <strong>across</strong> documents using a <code>significant_terms</code> aggregation. However, I can't get it to work on a child aggregation <strong>within</strong> a document.</p>
  
  <p>I tried to create a bucket within a bucket, with the first one partitioned on the ID, and the inner one returning significant terms. The significant_terms returns an empty array.</p>
  
  <pre><code>{
      "aggs": {
          "titles": {
              "terms": {
                  "field": "my_id"
              },
              "aggs": {
                  "my_common_terms": {
                      "significant_terms": {
                          "field": "titles"
                      }
                  }
              }
          }
      }
  }
  
  </code></pre>