# How to used XContentFilterBuilder?

**URL:** <https://discuss.elastic.co/t/how-to-used-xcontentfilterbuilder/6393>\
**Category:** Elasticsearch\
**Created:** [January 16, 2012, 6:53am UTC](https://discuss.elastic.co/t/how-to-used-xcontentfilterbuilder/6393 "2012-01-16T06:53:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [January 16, 2012, 6:53am UTC](https://discuss.elastic.co/t/how-to-used-xcontentfilterbuilder/6393/1 "2012-01-16T06:53:47Z")

</div>

Hi

I want to define token filter using java.can any one help me how to  
used XContentFilterBuilder class to define filter and if possible  
please explain with example.

used token filter what i want to used on search query:

type: stop  
stopwords\_path="d:\resouces\stopwords\_eng.txt  
ignore\_case=true

I am using following java code to search data:  
String indexName="test1";  
String indexType="type1";  
String data="is";  
QueryStringQueryBuilder querystring = new  
QueryStringQueryBuilder(data);  
SearchResponse searchResponse =  
client.prepareSearch(indexName).setTypes(indexType).setSearchType(SearchTyp  
e.DEFAULT)  
.setQuery(querystring.analyzer("whitespace"))  
.setFilter(...............) ////**_Here needs to  
define token filter_**\*\*\*\*\*  
.setSize(100).execute().action Get();

please help me.

Thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 16, 2012, 11:51am UTC](https://discuss.elastic.co/t/how-to-used-xcontentfilterbuilder/6393/2 "2012-01-16T11:51:06Z")

</div>

Use the FilterBuilders factory to create filters (similar to QueryBuilders).

On Mon, Jan 16, 2012 at 8:53 AM, sam [mishra.sameek@gmail.com](mailto:mishra.sameek@gmail.com) wrote:

> Hi
> 
> I want to define token filter using java.can any one help me how to  
> used XContentFilterBuilder class to define filter and if possible  
> please explain with example.
> 
> used token filter what i want to used on search query:
> 
> type: stop  
> stopwords\_path="d:\resouces\stopwords\_eng.txt  
> ignore\_case=true
> 
> I am using following java code to search data:  
> String indexName="test1";  
> String indexType="type1";  
> String data="is";  
> QueryStringQueryBuilder querystring = new  
> QueryStringQueryBuilder(data);  
> SearchResponse searchResponse =  
> client.prepareSearch(indexName).setTypes(indexType).setSearchType(SearchTyp  
> e.DEFAULT)  
> .setQuery(querystring.analyzer("whitespace"))  
> .setFilter(...............) ////_**Here needs to  
> define token filter**_\*\*\*\*\*  
> .setSize(100).execute().action Get();
> 
> please help me.
> 
> 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:** [July 6, 2017, 3:42am UTC](https://discuss.elastic.co/t/how-to-used-xcontentfilterbuilder/6393/3 "2017-07-06T03:42:36Z")

</div>


