In the Chinese environment, how to use term query?

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

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:

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

###result:

{
  "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:

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

###result:

{
  "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

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!

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

sorry,I try so hard to solve the problem

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.

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

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