# ES 5.0 wildcard query, problem with CJK characters

**URL:** <https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815>\
**Category:** Elasticsearch\
**Created:** [December 13, 2016, 5:05am UTC](https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815 "2016-12-13T05:05:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hacksign](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hacksign/32/5918_2.png) [@Hacksign](https://discuss.elastic.co/u/Hacksign)\
**Post date:** [December 13, 2016, 5:05am UTC](https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815/1 "2016-12-13T05:05:09Z")

</div>

If there is a data in ES like this :

```auto
{'realname':'XZY'}

```

**note** : X/Z/Y are CJK charcters, **NOT** English letters.

If I want pick above item out , I wrote dsl below :

```auto
    {
        "size" : 10,
        "query" : {
            "wildcard" : {
                "realname" : "X*"
            }
        }
    }

```

this works fine, but If DSL is like this :

```auto
{
    "size" : 10,
    "query" : {
        "wildcard" : {
            "realname" : "X*Y"
        }
    }
}

```

this can not find anything.

anything wrong ? or I misunderstank something from [this](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-wildcard-query.html) document ?

---

<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 13, 2016, 6:02am UTC](https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815/2 "2016-12-13T06:02:59Z")

</div>

Try the \_analyze API to see how your document is actually indexed.  
Then remember that wildcard string is not analyzed so it's compared to the previous output.

Finally: don't use wildcards!

---

<div class="post-metadata">

**Author:** ![Hacksign](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hacksign/32/5918_2.png) [@Hacksign](https://discuss.elastic.co/u/Hacksign)\
**Post date:** [December 13, 2016, 8:32am UTC](https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815/3 "2016-12-13T08:32:12Z")

</div>

thanks for reply.  
this is the output of \_analyze :

**XZY** are still CJK characters ...

```auto
[root@host ~]# curl http://localhost:9200/dbs/_analyze?pretty -d '{"field":"some_field", "text":"XZY"}'
{
  "tokens" : [
    {
      "token" : "X",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "<IDEOGRAPHIC>",
      "position" : 0
    },
    {
      "token" : "Z",
      "start_offset" : 1,
      "end_offset" : 2,
      "type" : "<IDEOGRAPHIC>",
      "position" : 1
    },
    {
      "token" : "Y",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "<IDEOGRAPHIC>",
      "position" : 2
    }
  ]
}

```

the problem confuse me is ,  
under Elasticsearch 2.3, wildcard search like this:

```auto
    "size" : 10,
    "query" : {
        "wildcard" : {
            "realname" : "X*Y"
        }
    }
}

```

will return results.

but after upgrade es to 5.0, only querys below could return results :

```auto
    {
        "size" : 10,
        "query" : {
            "wildcard" : {
                "realname" : "X*"
            }
        }
    }

```

if this is a problem relative to mapping and participle, why "X\*" could hit results while "X\*Y" could not ?

---

<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 13, 2016, 8:54am UTC](https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815/4 "2016-12-13T08:54:27Z")

</div>

I don't know how it worked previously in 2.x series.  
May be the analyzer you were using was producing `["XYZ"]` instead of `["X", "Y", "Z"]`?

---

<div class="post-metadata">

**Author:** ![Hacksign](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hacksign/32/5918_2.png) [@Hacksign](https://discuss.elastic.co/u/Hacksign)\
**Post date:** [December 16, 2016, 2:44am UTC](https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815/5 "2016-12-16T02:44:51Z")

</div>

As \_analyze api returned.  
CJK character is analyzed as ['X', 'Z', 'Y'], not ['XZY'].  
this seems to be the default analyzer behaviour(split CJK characters into single word one after another).

So, still confused of understanding why can not get correct result by providing 'X\*Y' to wildcard query.

---

<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, 2016, 8:21am UTC](https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815/6 "2016-12-17T08:21:23Z")

</div>

So if you have in the inverted index:

- `X`
- `Y`
- `Z`

`X*Y` won't match any on those, right?  
`X*`, `Y*`, `Z*` will.

---

<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:** [January 14, 2017, 8:21am UTC](https://discuss.elastic.co/t/es-5-0-wildcard-query-problem-with-cjk-characters/68815/7 "2017-01-14T08:21:34Z")

</div>

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