在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\""
}
}
答案 0 :(得分:1)
您还需要转义反斜杠本身,因为它位于字符串中。这将有效:
curl -XPOST "http://127.0.0.1:9200/messages/_search?pretty=true" --data-binary '{
"query": {
"bool": {
"must": [
{
"bool" : {
"should" : [
{
"query_string" : {
"query" : "yabba\\/dabba"
}
}
]
}
}
]
}
}
}'