# Java transport client doing chinese match query hit nothing

**URL:** <https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571>\
**Category:** Elasticsearch\
**Created:** [August 10, 2017, 8:38am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571 "2017-08-10T08:38:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![douxf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douxf/32/35290_2.png) [@douxf](https://discuss.elastic.co/u/douxf)\
**Post date:** [August 10, 2017, 8:38am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/1 "2017-08-10T08:38:52Z")

</div>

Elasticsearch version (bin/elasticsearch --version):  
Version: 2.4.4, Build: fcbb46d/2017-01-03T11:33:16Z, JVM: 1.8.0\_112  
Plugins installed: []  
ik, head  
JVM version (java -version):  
JVM: 1.8.0\_112  
OS version (uname -a if on a Unix-like system):  
Darwin DoudeMacBook-Pro.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE\_X86\_64 x86\_64

Description of the problem including expected versus actual behavior:  
use java trasport client, construct a match query using operator "and", the value is Chinese, in the index, there are records for the query, but query nothing.  
Steps to reproduce:  
index:  
{  
"user" : {  
"aliases" : { },  
"mappings" : {  
"userInfo" : {  
"properties" : {  
"age" : {  
"type" : "integer"  
},  
"created" : {  
"type" : "date",  
"format" : "strict\_date\_optional\_time||epoch\_millis"  
},  
"name" : {  
"type" : "string",  
"store" : true  
},  
"userId" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"store" : true  
}  
}  
}  
},  
"settings" : {  
"index" : {  
"client" : {  
"transport" : {  
"ping\_timeout" : "60s"  
}  
},  
"creation\_date" : "1502344889730",  
"number\_of\_shards" : "2",  
"number\_of\_replicas" : "1",  
"uuid" : "v88dMBG0QbmiTrLZ0rIqpQ",  
"version" : {  
"created" : "2040499"  
}  
}  
},  
"warmers" : { }  
}  
}  
insert three records:  
User user1 = new User("105", "Test ABC 芦玉Match123", 31, new Date());  
User user2 = new User("106", "test 开发 芦match玉", 41, new Date());  
User user3 = new User("107", "This 开发 is a 芦玉test", 51, new Date());

Client:  
{  
"size" : 100,  
"query" : {  
"bool" : {  
"should" : {  
"match" : {  
"name" : {  
"query" : "\u82A6\u7389",  
"type" : "phrase\_prefix",  
"operator" : "AND",  
"minimum\_should\_match" : "90%"  
}  
}  
}  
}  
},  
"explain" : true  
}  
no hit.  
{  
"took": 1,  
"timed\_out": false,  
"\_shards": {  
"total": 2,  
"successful": 2,  
"failed": 0  
},  
"hits": {  
"total": 0,  
"max\_score": null,  
"hits": []  
}  
}

Now use:  
{  
"size": 100,  
"query": {  
"bool": {  
"should": {  
"match": {  
"name": {  
"query": "芦玉",  
"type": "phrase\_prefix",  
"operator": "AND",  
"minimum\_should\_match": "90%"  
}  
}  
}  
}  
},  
"explain": true  
}

{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 2,  
"successful": 2,  
"failed": 0  
},  
"hits": {  
"total": 2,  
"max\_score": 0.52021796,  
"hits": [...

---

<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:** [August 10, 2017, 9:13am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/2 "2017-08-10T09:13:59Z")

</div>

Could you provide a full recreation script as described in

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

It will help to better understand what you are doing and we will be able to play with your script just by copy and pasting.

I think it's related to analyzers here.

BTW have a look at the `_analyze` API to see how your terms are actually indexed.

---

<div class="post-metadata">

**Author:** ![douxf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douxf/32/35290_2.png) [@douxf](https://discuss.elastic.co/u/douxf)\
**Post date:** [August 10, 2017, 9:38am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/3 "2017-08-10T09:38:00Z")

</div>

1. Create a simple index and mapping, the mapping use default analyzer.
2. Index some records with Chinese words.
3. Using java client build a match query, operator is 'and', value are Chinese words.
4. Then java client execute the query, the result hit nothing(There are really have the words in the index).  
5.The java client tostring method will print the query , in which the Chinese words are converted to \uxxxx
5. If I paste the printed json string in the head plugin, then search, aslo hit nothing.  
7 but if i change the converted Chinese words from \uxxxx to real Chinese, the head query will hit.

---

<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:** [August 10, 2017, 9:49am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/4 "2017-08-10T09:49:19Z")

</div>

I understood what you do. I just need a script I can play to reproduce it.

---

<div class="post-metadata">

**Author:** ![douxf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douxf/32/35290_2.png) [@douxf](https://discuss.elastic.co/u/douxf)\
**Post date:** [August 10, 2017, 10:01am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/5 "2017-08-10T10:01:03Z")

</div>

How to upload scripts?

---

<div class="post-metadata">

**Author:** ![douxf](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douxf/32/35290_2.png) [@douxf](https://discuss.elastic.co/u/douxf)\
**Post date:** [August 10, 2017, 10:38am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/6 "2017-08-10T10:38:28Z")

</div>

It's my fault. Thx you very much. I use the apache common lang StringEscapeUtils to escape special char, which will convert Chinese to \uxxxxx.

How to escape the {} ! chars?

---

<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:** [August 10, 2017, 10:47am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/7 "2017-08-10T10:47:50Z")

</div>

Please read again:

> [@Java transport client doing chinese match query hit nothing](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/2):
>
> Could you provide a full recreation script as described in [https://discuss.elastic.co/t/about-the-elasticsearch-category/21](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) It will help to better understand what you are doing and we will be able to play with your script just by copy and pasting. I think it's related to analyzers here. BTW have a look at the \_analyze API to see how your terms are actually indexed.

---

<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:** [September 7, 2017, 10:49am UTC](https://discuss.elastic.co/t/java-transport-client-doing-chinese-match-query-hit-nothing/96571/8 "2017-09-07T10:49:09Z")

</div>

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