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

4

我需要找到一种方法来查询 Elastic search 中的 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" }}}'

是否有办法强制Elastic接受转义字符串作为查询而不是原始查询?

谢谢。

1个回答

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"}
    } ]
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接