# \[Elasticsearch - Java api \] - How to write the select query for searching text mixed with special characters(John-one) across multiple fields using elasticsearch java api?

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-api-how-to-write-the-select-query-for-searching-text-mixed-with-special-characters-john-one-across-multiple-fields-using-elasticsearch-java-api/15406>\
**Category:** Elasticsearch\
**Created:** [January 24, 2014, 1:04pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-how-to-write-the-select-query-for-searching-text-mixed-with-special-characters-john-one-across-multiple-fields-using-elasticsearch-java-api/15406 "2014-01-24T13:04:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![purna2207](https://avatars.discourse-cdn.com/v4/letter/p/858c86/32.png) [@purna2207](https://discuss.elastic.co/u/purna2207)\
**Post date:** [January 24, 2014, 1:04pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-how-to-write-the-select-query-for-searching-text-mixed-with-special-characters-john-one-across-multiple-fields-using-elasticsearch-java-api/15406/1 "2014-01-24T13:04:00Z")

</div>

Hi everybody good afternoon, Please help me to come out of this problem. I  
spent so much time to resolve this issue but I am not able to succeed.

```
        I have two users in my db collection and those names are 

```

'john' and 'john-son' , now I am trying to select all records which are  
matching with my search text among all fields of db collection. For example  
my search text is ' john' then my query is by using elasticsearch java api

QueryBuilder queryBuilderForUserSearch = QueryBuilders.fieldQuery("\_all",  
"_" + q + "_");

```
 It's working fine. But when I am trying to search with special 

```

character text like 'john-son' by this time it it returns zero records.  
Can anybody please help me why it's happens and please provide the query  
for select text with special characters also. I am really thankful to  
them.

Thanks in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d40fd5c8-ffa5-4fe5-ba99-dc6988fe6559%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d40fd5c8-ffa5-4fe5-ba99-dc6988fe6559%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [January 24, 2014, 1:46pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-how-to-write-the-select-query-for-searching-text-mixed-with-special-characters-john-one-across-multiple-fields-using-elasticsearch-java-api/15406/2 "2014-01-24T13:46:28Z")

</div>

This is because "john-son" is most likely being broken down to two terms,  
"john" and "son". What analyzer is being defined on your field?

Also note the "_" + q + "_" thing isn't necessary, this isn't SQL here

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Fri, Jan 24, 2014 at 3:04 PM, [purna2207@gmail.com](mailto:purna2207@gmail.com) wrote:

> Hi everybody good afternoon, Please help me to come out of this problem. I  
> spent so much time to resolve this issue but I am not able to succeed.
> 
> ```
> I have two users in my db collection and those names are
> 
> ```
> 
> 'john' and 'john-son' , now I am trying to select all records which are  
> matching with my search text among all fields of db collection. For example  
> my search text is ' john' then my query is by using elasticsearch java api
> 
> QueryBuilder queryBuilderForUserSearch = QueryBuilders.fieldQuery("\_all",  
> "_" + q + "_");
> 
> ```
> It's working fine. But when I am trying to search with special
> 
> ```
> 
> character text like 'john-son' by this time it it returns zero records.  
> Can anybody please help me why it's happens and please provide the query  
> for select text with special characters also. I am really thankful to  
> them.
> 
> Thanks in advance.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d40fd5c8-ffa5-4fe5-ba99-dc6988fe6559%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d40fd5c8-ffa5-4fe5-ba99-dc6988fe6559%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zun\_ojCDnKJc3SR%2BcoHTVwydayy%2BoqX9Syp6oHgEYrDAQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zun_ojCDnKJc3SR%2BcoHTVwydayy%2BoqX9Syp6oHgEYrDAQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![purna2207](https://avatars.discourse-cdn.com/v4/letter/p/858c86/32.png) [@purna2207](https://discuss.elastic.co/u/purna2207)\
**Post date:** [January 27, 2014, 10:45am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-how-to-write-the-select-query-for-searching-text-mixed-with-special-characters-john-one-across-multiple-fields-using-elasticsearch-java-api/15406/3 "2014-01-27T10:45:42Z")

</div>

Hi Sir thanks for instant response, yes there is no necessity of "\*" + q

- "\*" just " q " is enough. Present I am using standard-analyzer. Can you  
please help to come out of this problem.But it's(john-son) working  
properly on particular field search but not working "\_all " field search.

On Friday, January 24, 2014 7:16:28 PM UTC+5:30, Itamar Syn-Hershko wrote:

> This is because "john-son" is most likely being broken down to two terms,  
> "john" and "son". What analyzer is being defined on your field?
> 
> Also note the "_" + q + "_" thing isn't necessary, this isn't SQL here
> 
> --
> 
> Itamar Syn-Hershko  
> [http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
> Freelance Developer & Consultant  
> Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)
> 
> On Fri, Jan 24, 2014 at 3:04 PM, \<[purn...@gmail.com](mailto:purn...@gmail.com) \<javascript:\>\> wrote:
> 
> > Hi everybody good afternoon, Please help me to come out of this problem.  
> > I spent so much time to resolve this issue but I am not able to succeed.
> > 
> > ```
> > I have two users in my db collection and those names are 
> > 
> > ```
> > 
> > 'john' and 'john-son' , now I am trying to select all records which are  
> > matching with my search text among all fields of db collection. For example  
> > my search text is ' john' then my query is by using elasticsearch java api
> > 
> > QueryBuilder queryBuilderForUserSearch = QueryBuilders.fieldQuery("\_all",  
> > "_" + q + "_");
> > 
> > ```
> > It's working fine. But when I am trying to search with special 
> > 
> > ```
> > 
> > character text like 'john-son' by this time it it returns zero records.  
> > Can anybody please help me why it's happens and please provide the query  
> > for select text with special characters also. I am really thankful to  
> > them.
> > 
> > Thanks in advance.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d40fd5c8-ffa5-4fe5-ba99-dc6988fe6559%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d40fd5c8-ffa5-4fe5-ba99-dc6988fe6559%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/71f0063e-5192-4332-9398-a560d2bb3002%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71f0063e-5192-4332-9398-a560d2bb3002%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![purna2207](https://avatars.discourse-cdn.com/v4/letter/p/858c86/32.png) [@purna2207](https://discuss.elastic.co/u/purna2207)\
**Post date:** [January 27, 2014, 2:10pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-how-to-write-the-select-query-for-searching-text-mixed-with-special-characters-john-one-across-multiple-fields-using-elasticsearch-java-api/15406/4 "2014-01-27T14:10:31Z")

</div>

Hi Sir thanks for instant response, yes there is no necessity of "\*" + q

- "\*" just " q " is enough. Present I am using standard-analyzer. Can you  
please help to come out of this problem.But it's(john-son) working  
properly on particular field search but not working "\_all " field search.

On Friday, January 24, 2014 7:16:28 PM UTC+5:30, Itamar Syn-Hershko wrote:

> This is because "john-son" is most likely being broken down to two terms,  
> "john" and "son". What analyzer is being defined on your field?
> 
> Also note the "_" + q + "_" thing isn't necessary, this isn't SQL here
> 
> --
> 
> Itamar Syn-Hershko  
> [http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
> Freelance Developer & Consultant  
> Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)
> 
> On Fri, Jan 24, 2014 at 3:04 PM, \<[purn...@gmail.com](mailto:purn...@gmail.com) \<javascript:\>\> wrote:
> 
> > Hi everybody good afternoon, Please help me to come out of this problem.  
> > I spent so much time to resolve this issue but I am not able to succeed.
> > 
> > ```
> > I have two users in my db collection and those names are 
> > 
> > ```
> > 
> > 'john' and 'john-son' , now I am trying to select all records which are  
> > matching with my search text among all fields of db collection. For example  
> > my search text is ' john' then my query is by using elasticsearch java api
> > 
> > QueryBuilder queryBuilderForUserSearch = QueryBuilders.fieldQuery("\_all",  
> > "_" + q + "_");
> > 
> > ```
> > It's working fine. But when I am trying to search with special 
> > 
> > ```
> > 
> > character text like 'john-son' by this time it it returns zero records.  
> > Can anybody please help me why it's happens and please provide the query  
> > for select text with special characters also. I am really thankful to  
> > them.
> > 
> > Thanks in advance.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d40fd5c8-ffa5-4fe5-ba99-dc6988fe6559%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d40fd5c8-ffa5-4fe5-ba99-dc6988fe6559%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/99c8cd70-0229-4589-a477-28664fb9e88f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/99c8cd70-0229-4589-a477-28664fb9e88f%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:54am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-how-to-write-the-select-query-for-searching-text-mixed-with-special-characters-john-one-across-multiple-fields-using-elasticsearch-java-api/15406/5 "2017-07-06T01:54:36Z")

</div>


