palmic
palmic

Reputation: 1856

How to search for utf-8 special characters in elasticsearch?

I have a problem to find solution of querying Unicode special chars in Elastic search.

When i create this index:

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

and then iam trying to search for "řeky" phrase, everything is OK:

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

But when I try to search for the same word escaped I find nothing:

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

Is somehow possible force elastic to accept escaped strings in queries instead of raw queries?

Thank You.

Upvotes: 4

Views: 9970

Answers (1)

DrTech
DrTech

Reputation: 17319

Assuming you're using eg bash, then you have one too many backslashes:

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

Upvotes: 5

Related Questions