# How to refer custom analyzer in search query?

**URL:** <https://discuss.elastic.co/t/how-to-refer-custom-analyzer-in-search-query/6397>\
**Category:** Elasticsearch\
**Created:** [January 16, 2012, 12:18pm UTC](https://discuss.elastic.co/t/how-to-refer-custom-analyzer-in-search-query/6397 "2012-01-16T12:18:33Z")\
**Posts on this page:** 2\
**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, 12:18pm UTC](https://discuss.elastic.co/t/how-to-refer-custom-analyzer-in-search-query/6397/1 "2012-01-16T12:18:33Z")

</div>

Hi

I am using elastic server 0.16.2. i am using following java code for  
creating custom analyzer:  
I have created gist for used java code that create custom  
analyzer(search\_analyzer)

> <https://gist.github.com/sameek/1620578>

search query java code :

QueryStringQueryBuilder querystring = new  
QueryStringQueryBuilder(data);  
SearchResponse searchResponse =  
client.prepareSearch(indexName).setSearchType(SearchType.DEFAULT)  
.setQuery(querystring.analyzer("search\_analyzer")).setExplain(true).setSize(100).execute().actionGet();

I have following doubt regarding custom analyzer:

1. Is it is necessary to use same analyzer index creation and  
searching time.
2. how to refer custom analyzer in search query.  
3.if we used following java code for define custom analyzer on  
index ,it can change previous created index mapping.

please help me and clear things.

---

<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-refer-custom-analyzer-in-search-query/6397/2 "2017-07-06T03:42:35Z")

</div>


