elasticsearch,term,Unicode,elasticsearch,Term" /> elasticsearch,term,Unicode,elasticsearch,Term" />

ElasticSearch是否支持Unicode/中文?

ElasticSearch是否支持Unicode/中文?,unicode,elasticsearch,term,Unicode,elasticsearch,Term,我正在通过ElasticSearch进行文本搜索,使用术语类型进行查询时出现问题。我在下面做的基本上是 添加带有中文字符串的文档(你好). 使用文本方法查询,返回文档 使用term方法查询,不返回任何内容 那么,为什么会发生这种情况?以及如何解决它 ➜ curl -XPOST 'http://localhost:9200/test/test/' -d '{ "name" : "你好" }' { "ok": true, "_index": "test", "_type": "tes

我正在通过ElasticSearch进行文本搜索,使用术语类型进行查询时出现问题。我在下面做的基本上是

  • 添加带有中文字符串的文档(你好).
  • 使用文本方法查询,返回文档
  • 使用term方法查询,不返回任何内容
  • 那么,为什么会发生这种情况?以及如何解决它

    ➜  curl -XPOST 'http://localhost:9200/test/test/' -d '{ "name" : "你好" }'
    
    {
      "ok": true,
      "_index": "test",
      "_type": "test",
      "_id": "VdV8K26-QyiSCvDrUN00Nw",
      "_version": 1
    }
    





    从ElasticSearch文档中,关于:

    匹配具有包含术语(未分析)的字段的文档

    默认情况下,
    名称
    字段是经过分析的,因此术语查询无法找到该字段(仅查找未分析的字段)。您可以尝试使用另一个具有不同
    名称
    (非中文)的文档对其进行索引,但术语查询也无法找到该字段。如果您现在想知道为什么以下搜索查询会返回结果:

    curl -XGET 'http://localhost:9200/test/test/_search?pretty=1' -d '{"query" : {"term" : { "name" : "好" }}}'
    
    这是因为每个标记都是一个未经分析的术语。如果您要索引一个名为你好吗", 您也找不到包含“”的文档好吗“或”你好,但您可以找到包含你", "好“或”吗“使用术语查询


    对于中文,您可能需要特别注意所使用的分析器。但对我来说,标准分析器似乎足够好(按字符而不是空格标记中文短语)。

    默认分析器不适用于亚洲语言。 尝试使用以下分析器:

    ➜  curl -XGET 'http://localhost:9200/test/test/_search?pretty=1'
    
    {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 1,
        "max_score": 1.0,
        "hits": [
          {
            "_index": "test",
            "_type": "test",
            "_id": "VdV8K26-QyiSCvDrUN00Nw",
            "_score": 1.0,
            "_source": {
              "name": "你好"
            }
          }
        ]
      }
    }
    
    ➜  curl -XGET 'http://localhost:9200/test/test/_search?pretty=1' -d '{
      "query": {
        "text": {
          "name": "你好"
        }
      }
    }'
    
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 1,
        "max_score": 0.8838835,
        "hits": [
          {
            "_index": "test",
            "_type": "test",
            "_id": "VdV8K26-QyiSCvDrUN00Nw",
            "_score": 0.8838835,
            "_source": {
              "name": "你好"
            }
          }
        ]
      }
    }
    
    ➜  curl -XGET 'http://localhost:9200/test/test/_search?pretty=1' -d '{
      "query": {
        "term": {
          "name": "你好"
        }
      }
    }'
    
    {
      "took" : 2,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      },
      "hits" : {
        "total" : 0,
        "max_score" : null,
        "hits" : [ ]
      }
    }
    
    curl -XGET 'http://localhost:9200/test/test/_search?pretty=1' -d '{"query" : {"term" : { "name" : "好" }}}'