# Strange behaviour of QueryString in JavaAPI

**URL:** <https://discuss.elastic.co/t/strange-behaviour-of-querystring-in-javaapi/14876>\
**Category:** Elasticsearch\
**Created:** [December 16, 2013, 3:15am UTC](https://discuss.elastic.co/t/strange-behaviour-of-querystring-in-javaapi/14876 "2013-12-16T03:15:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zkidkid](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zkidkid](https://discuss.elastic.co/u/zkidkid)\
**Post date:** [December 16, 2013, 3:15am UTC](https://discuss.elastic.co/t/strange-behaviour-of-querystring-in-javaapi/14876/1 "2013-12-16T03:15:12Z")

</div>

Hi,  
I am using QueryString in JavaAPI and find that it work really strange with  
query string in Rest.

Here is step to reproduce it

First, add asciifolding to filter:

```
analyzer:
  default:

```

tokenizer: standard  
filter: [asciifolding,lowercase]

Create your index, and indexing your data with unicode word, ex: không có gì

Search in head plugin with: không, -\> you get your document "không có gì"  
Search in java api with: không -\> you get nothing  
Search in java api with: khong -\> you get your document

First I think it's because my index is not use asciifolding & lowercase  
filter, so I test it like that:  
[http://127.0.0.1:9200/myindex/\_analyze?text=không%20có%20gì](http://127.0.0.1:9200/myindex/_analyze?text=kh%C3%B4ng%20c%C3%B3%20g%C3%AC)  
Result:

{"tokens":[{"token":"khong","start\_offset":0,"end\_offset":5,"type":"","position":1},{"token":"co","start\_offset":6,"end\_offset":8,"type":"","position":2},{"token":"gi","start\_offset":9,"end\_offset":11,"type":"","position":3}]}

So there shouldn't problem with filter.

Currently I fix it by do Asciifolding & lowercase by my self using Lucence AsciiFoldingFilter. But I really want to know what's happening.

--  
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/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 16, 2013, 4:54am UTC](https://discuss.elastic.co/t/strange-behaviour-of-querystring-in-javaapi/14876/2 "2013-12-16T04:54:53Z")

</div>

Could you gist your java code?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 16 déc. 2013 à 04:15, kidkid [zkidkid@gmail.com](mailto:zkidkid@gmail.com) a écrit :

Hi,  
I am using QueryString in JavaAPI and find that it work really strange with query string in Rest.

Here is step to reproduce it

First, add asciifolding to filter:

```
analyzer:
  default:
tokenizer: standard
    filter: [asciifolding,lowercase]

```

Create your index, and indexing your data with unicode word, ex: không có gì

Search in head plugin with: không, -\> you get your document "không có gì"  
Search in java api with: không -\> you get nothing  
Search in java api with: khong -\> you get your document

First I think it's because my index is not use asciifolding & lowercase filter, so I test it like that:  
[http://127.0.0.1:9200/myindex/\_analyze?text=không%20có%20gì](http://127.0.0.1:9200/myindex/_analyze?text=kh%C3%B4ng%20c%C3%B3%20g%C3%AC)  
Result:  
{"tokens":[{"token":"khong","start\_offset":0,"end\_offset":5,"type":"","position":1},{"token":"co","start\_offset":6,"end\_offset":8,"type":"","position":2},{"token":"gi","start\_offset":9,"end\_offset":11,"type":"","position":3}]}

So there shouldn't problem with filter.

Currently I fix it by do Asciifolding & lowercase by my self using Lucence AsciiFoldingFilter. But I really want to know what's happening.

--  
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/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%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/EFF9AD08-3053-4004-A775-6129002B4727%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/EFF9AD08-3053-4004-A775-6129002B4727%40pilato.fr).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![zkidkid](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zkidkid](https://discuss.elastic.co/u/zkidkid)\
**Post date:** [December 17, 2013, 8:24am UTC](https://discuss.elastic.co/t/strange-behaviour-of-querystring-in-javaapi/14876/3 "2013-12-17T08:24:41Z")

</div>

Hi David,

I have figure out the problem:

Let said we have already setup as I said above.  
Now I try with:  
String query = "khô\*"  
QueryStringQueryBuilder queryString =  
QueryBuilders.queryString(query).defaultField("myfield");  
I would expect to get : "không có gì" but actually It will return nothing

I have to set analyzeWildcard(true) and it do fine.

The question here, incase I don't set analyzeWildcard(true).  
If I search kho\* it would return "không có gì" document  
But if I search khô\* it wouldn't return.

Is it reasonable ?

On Sunday, December 15, 2013 8:54:53 PM UTC-8, David Pilato wrote:

> Could you gist your java code?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 16 déc. 2013 à 04:15, kidkid \<[zki...@gmail.com](mailto:zki...@gmail.com) \<javascript:\>\> a écrit :
> 
> Hi,  
> I am using QueryString in JavaAPI and find that it work really strange  
> with query string in Rest.
> 
> Here is step to reproduce it
> 
> First, add asciifolding to filter:
> 
> ```
> analyzer:
> default:
> 
> ```
> 
> tokenizer: standard  
> filter: [asciifolding,lowercase]
> 
> Create your index, and indexing your data with unicode word, ex: không có  
> gì
> 
> Search in head plugin with: không, -\> you get your document "không có gì"  
> Search in java api with: không -\> you get nothing  
> Search in java api with: khong -\> you get your document
> 
> First I think it's because my index is not use asciifolding & lowercase  
> filter, so I test it like that:  
> [http://127.0.0.1:9200/myindex/\_analyze?text=không%20có%20gì](http://127.0.0.1:9200/myindex/_analyze?text=kh%C3%B4ng%20c%C3%B3%20g%C3%AC)  
> Result:
> 
> {"tokens":[{"token":"khong","start\_offset":0,"end\_offset":5,"type":"","position":1},{"token":"co","start\_offset":6,"end\_offset":8,"type":"","position":2},{"token":"gi","start\_offset":9,"end\_offset":11,"type":"","position":3}]}
> 
> So there shouldn't problem with filter.
> 
> Currently I fix it by do Asciifolding & lowercase by my self using Lucence AsciiFoldingFilter. But I really want to know what's happening.
> 
> --  
> 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/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%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/f2db090e-50e2-490e-a6a4-d8376c859ac0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f2db090e-50e2-490e-a6a4-d8376c859ac0%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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 17, 2013, 8:30am UTC](https://discuss.elastic.co/t/strange-behaviour-of-querystring-in-javaapi/14876/4 "2013-12-17T08:30:29Z")

</div>

I guess it is: [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)

analyze\_wildcard

By default, wildcards terms in a query string are not analyzed. By setting this value to true, a best effort will be made to analyze those as well.

So when searching for "khô\*", you are trying to compare "khô" with the inverted index term "kho". It does not match.

BTW I think you should consider using MatchQuery instead of QueryStringQuery: [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 17 décembre 2013 at 09:24:46, kidkid ([zkidkid@gmail.com](mailto:zkidkid@gmail.com)) a écrit:

Hi David,

I have figure out the problem:

Let said we have already setup as I said above.  
Now I try with:  
String query = "khô\*"  
QueryStringQueryBuilder queryString = QueryBuilders.queryString(query).defaultField("myfield");  
I would expect to get : "không có gì" but actually It will return nothing

I have to set analyzeWildcard(true) and it do fine.

The question here, incase I don't set analyzeWildcard(true).  
If I search kho\* it would return "không có gì" document  
But if I search khô\* it wouldn't return.

Is it reasonable ?

On Sunday, December 15, 2013 8:54:53 PM UTC-8, David Pilato wrote:  
Could you gist your java code?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 16 déc. 2013 à 04:15, kidkid [zki...@gmail.com](mailto:zki...@gmail.com) a écrit :

Hi,  
I am using QueryString in JavaAPI and find that it work really strange with query string in Rest.

Here is step to reproduce it

First, add asciifolding to filter:

```
analyzer:
  default:

```

tokenizer: standard  
filter: [asciifolding,lowercase]

Create your index, and indexing your data with unicode word, ex: không có gì

Search in head plugin with: không, -\> you get your document "không có gì"  
Search in java api with: không -\> you get nothing  
Search in java api with: khong -\> you get your document

First I think it's because my index is not use asciifolding & lowercase filter, so I test it like that:  
[http://127.0.0.1:9200/myindex/\_analyze?text=không%20có%20gì](http://127.0.0.1:9200/myindex/_analyze?text=kh%C3%B4ng%20c%C3%B3%20g%C3%AC)  
Result:  
{"tokens":[{"token":"khong","start\_offset":0,"end\_offset":5,"type":"","position":1},{"token":"co","start\_offset":6,"end\_offset":8,"type":"","position":2},{"token":"gi","start\_offset":9,"end\_offset":11,"type":"","position":3}]}

So there shouldn't problem with filter.

Currently I fix it by do Asciifolding & lowercase by my self using Lucence AsciiFoldingFilter. But I really want to know what's happening.

## -- 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). To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%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/f2db090e-50e2-490e-a6a4-d8376c859ac0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f2db090e-50e2-490e-a6a4-d8376c859ac0%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/etPan.52b00ba5.580bd78f.6956%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52b00ba5.580bd78f.6956%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![zkidkid](https://avatars.discourse-cdn.com/v4/letter/z/fbc32d/32.png) [@zkidkid](https://discuss.elastic.co/u/zkidkid)\
**Post date:** [December 18, 2013, 3:10am UTC](https://discuss.elastic.co/t/strange-behaviour-of-querystring-in-javaapi/14876/5 "2013-12-18T03:10:02Z")

</div>

Hi David,  
Thanks for you suggest but Match Query don't allow to use wildcard.  
So in case I search khong it will match "khong co gi" but if I search "kho"  
it will not match.  
So I back to use query string instead.  
Actually I only use wildcard in case query has only 1 word, so the  
performance is fine.

On Tuesday, December 17, 2013 12:30:29 AM UTC-8, David Pilato wrote:

> I guess it is:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)
> 
> analyze\_wildcard
> 
> By default, wildcards terms in a query string are not analyzed. By setting  
> this value to true, a best effort will be made to analyze those as well.  
> So when searching for "khô\*", you are trying to compare "khô" with the  
> inverted index term "kho". It does not match.
> 
> BTW I think you should consider using MatchQuery instead of  
> QueryStringQuery:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 17 décembre 2013 at 09:24:46, kidkid ([zki...@gmail.com](mailto:zki...@gmail.com) \<javascript:\>)  
> a écrit:
> 
> Hi David,
> 
> I have figure out the problem:
> 
> Let said we have already setup as I said above.  
> Now I try with:  
> String query = "khô\*"  
> QueryStringQueryBuilder queryString =  
> QueryBuilders.queryString(query).defaultField("myfield");  
> I would expect to get : "không có gì" but actually It will return nothing
> 
> I have to set analyzeWildcard(true) and it do fine.
> 
> The question here, incase I don't set analyzeWildcard(true).  
> If I search kho\* it would return "không có gì" document  
> But if I search khô\* it wouldn't return.
> 
> Is it reasonable ?
> 
> On Sunday, December 15, 2013 8:54:53 PM UTC-8, David Pilato wrote:
> 
> > Could you gist your java code?
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 16 déc. 2013 à 04:15, kidkid [zki...@gmail.com](mailto:zki...@gmail.com) a écrit :
> > 
> > Hi,  
> > I am using QueryString in JavaAPI and find that it work really strange  
> > with query string in Rest.
> > 
> > Here is step to reproduce it
> > 
> > First, add asciifolding to filter:
> > 
> > ```
> > analyzer:
> > default:
> > 
> > ```
> > 
> > tokenizer: standard  
> > filter: [asciifolding,lowercase]
> > 
> > Create your index, and indexing your data with unicode word, ex: không có  
> > gì
> > 
> > Search in head plugin with: không, -\> you get your document "không có gì"  
> > Search in java api with: không -\> you get nothing  
> > Search in java api with: khong -\> you get your document
> > 
> > First I think it's because my index is not use asciifolding & lowercase  
> > filter, so I test it like that:  
> > [http://127.0.0.1:9200/myindex/\_analyze?text=không%20có%20gì](http://127.0.0.1:9200/myindex/_analyze?text=kh%C3%B4ng%20c%C3%B3%20g%C3%AC)[http://127.0.0.1:9200/myindex/\_analyze?text=không%20có%20gì](http://127.0.0.1:9200/myindex/_analyze?text=kh%C3%B4ng%20c%C3%B3%20g%C3%AC)  
> > Result:
> > 
> > {"tokens":[{"token":"khong","start\_offset":0,"end\_offset":5,"type":"","position":1},{"token":"co","start\_offset":6,"end\_offset":8,"type":"","position":2},{"token":"gi","start\_offset":9,"end\_offset":11,"type":"","position":3}]}
> > 
> > So there shouldn't problem with filter.
> > 
> > Currently I fix it by do Asciifolding & lowercase by my self using Lucence AsciiFoldingFilter. But I really want to know what's happening.
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/905311c4-dbf8-4e84-a1dc-b09ee3aec0bd%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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/f2db090e-50e2-490e-a6a4-d8376c859ac0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f2db090e-50e2-490e-a6a4-d8376c859ac0%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/bcc6b4f3-3692-4f35-97f5-aaabebebead6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bcc6b4f3-3692-4f35-97f5-aaabebebead6%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, 2:00am UTC](https://discuss.elastic.co/t/strange-behaviour-of-querystring-in-javaapi/14876/6 "2017-07-06T02:00:31Z")

</div>


