2017-08-29 170 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" 
      } 
     } 
     ] 
     } 
     } 
     ] 
    } 
    } 
}'