在ES 5中,假设我想搜索"yabba/dabba“。docs提到使用反斜杠对保留字符进行转义。但是如果我这样做,我会得到一个错误。执行此查询将返回错误:
curl -XPOST "http://127.0.0.1:9200/messages/_search?pretty=true" --data-binary '{
"query": {
"bool": {
"must": [
{
"bool" : {
"should" : [
{
"query_string" : {
"query" : "yabba\/dabba"
}
}
]
}
}
]
}
}
}'返回的错误相关部分为:
"reason" : {
"type" : "query_shard_exception",
"reason" : "Failed to parse query [yabba/dabba]",
"index_uuid" : "hhldqVnWSDelNyMdtiF0kw",
"index" : "messages_201708291329",
"caused_by" : {
"type" : "parse_exception",
"reason" : "Cannot parse 'yabba/dabba': Lexical error at line 1, column 12. Encountered: <EOF> after : \"/dabba\"",
"caused_by" : {
"type" : "token_mgr_error",
"reason" : "Lexical error at line 1, column 12. Encountered: <EOF> after : \"/dabba\""
}
}发布于 2017-08-30 11:34:42
您还需要转义反斜杠本身,因为它位于字符串中。这将会起作用:
curl -XPOST "http://127.0.0.1:9200/messages/_search?pretty=true" --data-binary '{
"query": {
"bool": {
"must": [
{
"bool" : {
"should" : [
{
"query_string" : {
"query" : "yabba\\/dabba"
}
}
]
}
}
]
}
}
}'https://stackoverflow.com/questions/45948547
复制相似问题