2017-08-29 162 views
0

在ES 5中,假设我想搜索“yabba/dabba”。 docs提到使用反斜杠转义保留字符。但如果我这样做,我会得到一个错误。执行该查询返回一个错误:故障转移Elasticsearch查询

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

回答

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