# Changing filters dynamically

**URL:** <https://discuss.elastic.co/t/changing-filters-dynamically/170085>\
**Category:** Elastic Search\
**Tags:** elastic-site-search\
**Created:** [February 27, 2019, 1:38am UTC](https://discuss.elastic.co/t/changing-filters-dynamically/170085 "2019-02-27T01:38:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cakePlease](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@cakePlease](https://discuss.elastic.co/u/cakePlease)\
**Post date:** [February 27, 2019, 1:38am UTC](https://discuss.elastic.co/t/changing-filters-dynamically/170085/1 "2019-02-27T01:38:53Z")

</div>

Hi there,  
We're using the jquery client library for our custom search along with using "domain-identifier" to filter our results from 3 different domains.

Im having a hard time trying to figure out how to use the jquery **[swiftype-search-jquery](https://github.com/swiftype/swiftype-search-jquery)** to change the filter parameter and have it picked up by the plugin object.

Currently have 3 call to actions, each with a click event to build a new filter object, however i dont know how to pass this changed object to the existing $el.swifttypeSearch({}) object. I hope that makes sense.

```
var searchScope = function(){
	....some biz logic here...

	if(onClickSearchScope>0){
		return {'page': {'domain-identifier':onClickSearchScope}};
	} else {
		return {};
	}
	
};

$('.st-default-search-input').swiftypeSearch({
		resultContainingElement: '.st-search-container',
		engineKey: 'myEngineIDHere',
		renderFunction: customRenderFunction,
		perPage: 20,
		filters: searchScope()		
	});

```

Any help would be appreciated

---

<div class="post-metadata">

**Author:** ![cakePlease](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@cakePlease](https://discuss.elastic.co/u/cakePlease)\
**Post date:** [February 27, 2019, 6:33am UTC](https://discuss.elastic.co/t/changing-filters-dynamically/170085/2 "2019-02-27T06:33:58Z")

</div>

I finally figured out how to accomplish this, by putting the function call directly within the swiftypeSearch instantiation call:

```
$('.st-default-search-input').swiftypeSearch({
	resultContainingElement: '.st-search-container',
	engineKey: 'myEngineIDHere',
	renderFunction: customRenderFunction,
	perPage: 20,
	filters: function(){
		return {'page': {'domain-identifier':1}};
	}		
});
```

---

<div class="post-metadata">

**Author:** ![goodroot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/goodroot/32/38389_2.png) [@goodroot](https://discuss.elastic.co/u/goodroot)\
**Post date:** [February 27, 2019, 3:17pm UTC](https://discuss.elastic.co/t/changing-filters-dynamically/170085/3 "2019-02-27T15:17:26Z")

</div>

Hey there, cakePlease.

Looks like you have found the right solution.

Enjoy the week,

Kellen

Ps. _"Uh, death, please. No, cake! Cake! Cake, sorry. Sorry..."_

---

<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:** [March 27, 2019, 3:17pm UTC](https://discuss.elastic.co/t/changing-filters-dynamically/170085/4 "2019-03-27T15:17:40Z")

</div>

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