如何在elasticsearch中搜索utf-8特殊字符?

时间:2012-01-04 22:17:23

标签: elasticsearch unicode utf-8

我有一个问题,就是在弹性搜索中找到查询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" }}}'

以某种方式强制弹性来接受查询中的转义字符串而不是原始查询吗?

谢谢。

1 个答案:

答案 0 :(得分:5)

假设你正在使用例如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"}
    } ]
  }
}
相关问题