# Query\_string within background\_filter in significant terms aggregation

**URL:** <https://discuss.elastic.co/t/query-string-within-background-filter-in-significant-terms-aggregation/53935>\
**Category:** Elasticsearch\
**Created:** [June 25, 2016, 8:35am UTC](https://discuss.elastic.co/t/query-string-within-background-filter-in-significant-terms-aggregation/53935 "2016-06-25T08:35:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Lam](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@Patrick\_Lam](https://discuss.elastic.co/u/Patrick_Lam)\
**Post date:** [June 25, 2016, 8:35am UTC](https://discuss.elastic.co/t/query-string-within-background-filter-in-significant-terms-aggregation/53935/1 "2016-06-25T08:35:00Z")

</div>

Hi,

Is there a way to use a filter with a query\_string query within the background\_filter of a significant terms aggregation (on ES 2.1)? It seems like the background filter will not accept a query\_string even within a filter context. Replacing it with a match query works. It seems like maybe the query parsing is not enabled within background\_filter in significant terms?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [June 25, 2016, 12:03pm UTC](https://discuss.elastic.co/t/query-string-within-background-filter-in-significant-terms-aggregation/53935/2 "2016-06-25T12:03:08Z")

</div>

Working for me on 2.3 and the LastFM data.

No background filter and a search for an old French hip-hop artist:

```
GET lastfmusers2/_search
{
   "query": {
	  "match": {
		 "artists.raw": "mc solaar"
	  }
   },
   "size": 0,
   "aggs": {
	  "keywords": {
		 "significant_terms": {
			"field": "artists.raw"
		 }
	  }
   }
}

```

.. returns other French hip-hop artists e.g. Iam

If we set a background\_filter for "France" with the same seed artist query:

```
GET lastfmusers2/_search
{
   "query": {
	  "match": {
		 "artists.raw": "mc solaar"
	  }
   },
   "size": 0,
   "aggs": {
	  "keywords": {
		 "significant_terms": {
			"field": "artists.raw",
			"background_filter": {
			   "query_string": {
				  "query": "country:france"
			   }
			}
		 }
	  }
   }
}

```

.. and I get "pioneers of German hip-hop Die Fantastischen Vier" (at least according to Spotify).

---

<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:** [July 5, 2017, 10:40pm UTC](https://discuss.elastic.co/t/query-string-within-background-filter-in-significant-terms-aggregation/53935/3 "2017-07-05T22:40:33Z")

</div>


