title: Elasticsearch nested significant terms aggregation with background filter
body: <p>I am having hard times applying a background filter to a nested significant terms aggregation , the <code>bg_count</code> is always 0.</p>
  
  <p>I'm indexing article views that have ids and timestamps, and have multiple applications on a single index. I want the foreground and background set to relate to the same application, so I'm trying to apply a term filter on the <code>app_id</code> field both in the boo query and in the background filter. <code>article_views</code> is a nested object since I want to be also able to query on views with a range filter on <code>timestamp</code>, but I haven't got to that yet.</p>
  
  <p><strong>Mapping:</strong></p>
  
  <pre><code>    {
      "article_views": {
          "type": "nested",
          "properties": {
              "id": {
                  "type": "string",
                  "index": "not_analyzed"
              },
              "timestamp": {
                  "type": "date",
                  "format": "strict_date_optional_time||epoch_millis"
              }
          }
      },
      "app_id": {
          "type": "string",
          "index": "not_analyzed"
      }
  }
  </code></pre>
  
  <p><strong>Query:</strong></p>
  
  <pre><code>  {
     "aggregations": {
        "articles": {
           "nested": {
              "path": "article_views"
           },
           "aggs": {
              "articles": {
                 "significant_terms": {
                    "field": "article_views.id",
                    "size": 5,
                    "background_filter": {
                       "term": {
                          "app_id": "17"
                       }
                    }
                 }
              }
           }
        }
     },
     "query": {
        "bool": {
           "must": [
              {
                 "term": {
                    "app_id": "17"
                 }
              },
              {
                 "nested": {
                    "path": "article_views",
                    "query": {
                       "terms": {
                          "article_views.id": [
                             "1",
                             "2"
                          ]
                       }
                    }
                 }
              }
           ]
        }
     }
  }
  </code></pre>
  
  <p>As I said, in my result, the <code>bg_count</code> is always 0, which had me worried. If the significant terms is on other fields which are not nested the <code>background_filter</code> works fine.</p>
  
  <p><strong>Elasticsearch version is 2.2.</strong></p>
  
  <p>Thanks</p>