# Background\_filter on parent field in a nested significant\_terms aggregation

**URL:** <https://discuss.elastic.co/t/background-filter-on-parent-field-in-a-nested-significant-terms-aggregation/125295>\
**Category:** Elasticsearch\
**Created:** [March 23, 2018, 2:13am UTC](https://discuss.elastic.co/t/background-filter-on-parent-field-in-a-nested-significant-terms-aggregation/125295 "2018-03-23T02:13:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjhh](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jjhh](https://discuss.elastic.co/u/jjhh)\
**Post date:** [March 23, 2018, 2:13am UTC](https://discuss.elastic.co/t/background-filter-on-parent-field-in-a-nested-significant-terms-aggregation/125295/1 "2018-03-23T02:13:11Z")

</div>

My mapping looks like:

```
"properties": {
  "user_id": {
    "type": "keyword"
  },
  "need_to_check": {
    "type": "boolean"
  },
  "tags": {
    "type": "nested",
    "properties": {
      "name": {
        "type": "keyword"
      },
      "relevance": {
        "type": "scaled_float",
        "scaling_factor": 100
      }
    }
  }
}

```

I would like to do `significant_terms` aggregation on `tags.name` and `background_filter` on `need_to_check`, but the following query won't do, because in the `nested` aggregation, I only have the access to the `tags` documents, which don't have the `need_to_check` field. As a result, in the response, the `bg_count`s in `buckets` are always 0.

```
GET index_xyz/_search
{  
  "size":0,
  "query":{  
    "bool":{  
      "filter":[  
        {  
          "terms":{  
            "userid":[  
              "1",
              "2"
            ]
          }
        },
        {  
          "term":{  
            "need_to_check":false
          }
        }
      ]
    }
  },
  "aggs":{  
    "nested":{  
      "nested":{  
        "path":"tags"
      },
      "aggs":{  
        "tags":{  
          "significant_terms":{  
            "field":"tags.name",
            "background_filter": {
              "term":{  
                "need_to_check":false
              }
            }
          }
        }
      }
    }
  }
}

```

What's the right way to achieve this? Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 20, 2018, 2:13am UTC](https://discuss.elastic.co/t/background-filter-on-parent-field-in-a-nested-significant-terms-aggregation/125295/2 "2018-04-20T02:13:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
