# In the Chinese environment, how to use term query?

**URL:** <https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618>\
**Category:** Elasticsearch\
**Created:** [July 11, 2017, 9:51am UTC](https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618 "2017-07-11T09:51:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![qin](https://avatars.discourse-cdn.com/v4/letter/q/91b2a8/32.png) [@qin](https://discuss.elastic.co/u/qin)\
**Post date:** [July 11, 2017, 9:51am UTC](https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618/1 "2017-07-11T09:51:02Z")

</div>

**this is a test about term query ,but result is no ideal**

```auto
PUT /abc
{
  "mapping": {
    "abc": {
      "properties": {
        "str2": {
          "type": "string",
          "index":"not_analyzed"
        }
      }
    }
  },
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 1
  }
}

POST /abc/abc/1?pretty 
{
  "str1": "hello, world!",
  "str2": "goodbye! 你好"
}
POST /abc/abc/2?pretty 
{
  "str1": "hello",
  "str2": "你好"
} 

POST /abc/abc/3?pretty 
{
  "str1": "hello",
  "str2": "goodbye"
} 

```

###query one:

```auto
GET /abc/_search
{
  "query": {
    "term": {
      "str2": {
        "value": "goodbye"
      }
    }
    
  }
}

```

###result:

```auto
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.59086174,
    "hits": [
      {
        "_index": "abc",
        "_type": "abc",
        "_id": "3",
        "_score": 0.59086174,
        "_source": {
          "str1": "hello",
          "str2": "goodbye"
        }
      },
      {
        "_index": "abc",
        "_type": "abc",
        "_id": "1",
        "_score": 0.33355096,
        "_source": {
          "str1": "hello, world!",
          "str2": "goodbye! 你好"
        }
      }
    ]
  }
}

```

**Result is right, but query two...**

### query two:

```auto
GET /abc/_search
{
  "query": {
    "term": {
      "str2": {
        "value": "你好"
      }
    }
    
  }
}

```

###result:

```auto
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

```

**while term's value is Chinese , no result ? this is why ?**  
**str2 is `not_analyzed`**

---

<div class="post-metadata">

**Author:** ![qin](https://avatars.discourse-cdn.com/v4/letter/q/91b2a8/32.png) [@qin](https://discuss.elastic.co/u/qin)\
**Post date:** [July 11, 2017, 10:46am UTC](https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618/2 "2017-07-11T10:46:50Z")

</div>

```auto
PUT /abc
{
  "mapping": {
    "abc": {
      "properties": {
        "str2": {
          "type": "keyword"
        }
      }
    }
  },
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 1
  }
}

POST /abc/abc/1?pretty 
{
  "str2": "goodbye! 你好"
}
POST /abc/abc/2?pretty 
{
  "str2": "你好"
} 

POST /abc/abc/3?pretty 
{
  "str2": "goodbye"
} 
 

GET /abc/_search
{
  "query": {
    "term": {
      "str2": {
        "value": "你好"
      }
    }
    
  }
}

```

this the query is also no result!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 11, 2017, 11:02am UTC](https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618/3 "2017-07-11T11:02:10Z")

</div>

This forum is manned by volunteers, so please show some patience and do not send direct messages.

---

<div class="post-metadata">

**Author:** ![qin](https://avatars.discourse-cdn.com/v4/letter/q/91b2a8/32.png) [@qin](https://discuss.elastic.co/u/qin)\
**Post date:** [July 11, 2017, 11:03am UTC](https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618/4 "2017-07-11T11:03:43Z")

</div>

sorry，I try so hard to solve the problem

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 11, 2017, 11:07am UTC](https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618/5 "2017-07-11T11:07:39Z")

</div>

`str2` is mapped as `not_analyzed`, so is not broken up into tokens. If you change the mapping to `analysed` you will be able to search for parts of the string.

---

<div class="post-metadata">

**Author:** ![qin](https://avatars.discourse-cdn.com/v4/letter/q/91b2a8/32.png) [@qin](https://discuss.elastic.co/u/qin)\
**Post date:** [July 11, 2017, 12:47pm UTC](https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618/6 "2017-07-11T12:47:25Z")

</div>

I see , I just need to fully match ， query two ， result is no ideal.

---

<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:** [August 8, 2017, 12:47pm UTC](https://discuss.elastic.co/t/in-the-chinese-environment-how-to-use-term-query/92618/7 "2017-08-08T12:47:48Z")

</div>

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