【问题标题】:How to search for utf-8 special characters in elasticsearch?如何在 elasticsearch 中搜索 utf-8 特殊字符?
【发布时间】:2012-02-02 19:52:17
【问题描述】:

我在 Elastic 搜索中找不到查询 Unicode 特殊字符的解决方案。

当我创建这个索引时:

curl -XPUT http://localhost:9200/index/type/1 -d '{"name" : "Vrba u řeky"}'

然后我尝试搜索“řeky”短语,一切正常:

curl -XGET 'http://localhost:9200/index/type/_search?pretty=1' -d '{"query" : {"text" : 

{ "_all" : "řeky" }}}'

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.10848885,
    "hits" : [ {
      "_index" : "index",
      "_type" : "type",
      "_id" : "1",
      "_score" : 0.10848885, "_source" : {"name" : "Vrba u řeky"}
    } ]
  }
}

但是当我尝试搜索同一个单词时,我什么也没找到:

curl -XGET 'http://localhost:9200/index/type/_search?pretty=1' -d '{"query" : {"text" : { "_all" : "\\u0159eky" }}}'

是否有可能强制弹性接受查询中的转义字符串而不是原始查询?

谢谢。

【问题讨论】:

    标签: elasticsearch unicode utf-8


    【解决方案1】:

    假设你使用的是 bash,那么你的反斜杠太多了:

    curl -XGET 'http://localhost:9200/index/type/_search?pretty=1' -d '
        {"query" : {"text" : { "_all" : "\u0159eky" }}}
    '
    {
      "took" : 16,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      },
      "hits" : {
        "total" : 1,
        "max_score" : 0.10848885,
        "hits" : [ {
          "_index" : "index",
          "_type" : "type",
          "_id" : "1",
          "_score" : 0.10848885, "_source" : {"name" : "Vrba u řeky"}
        } ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-04
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多