在 ES 5 中,假设我想搜索“yabba/dabba”。该文件提到用反斜杠保留字符。但如果我这样做,我会得到一个错误。执行这个查询会返回一个错误:
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\""
}
}
您还需要转义反斜杠本身,因为它位于字符串中。这将起作用:
curl -XPOST "http://127.0.0.1:9200/messages/_search?pretty=true" --data-binary '{
"query": {
"bool": {
"must": [
{
"bool" : {
"should" : [
{
"query_string" : {
"query" : "yabba\\/dabba"
}
}
]
}
}
]
}
}
}'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句