无法使用Elastic Search API解析查询

时间:2018-01-30 15:21:16

标签: elasticsearch elasticsearch-5

我正在使用POST / _search API在弹性搜索5.6.0中搜索数据。

当我尝试搜索查询 Android 8.0(奥利奥)搜索API成功运行时,但当我尝试 Android 8.0(奥利奥弹性搜索失败,错误失败解析查询[Android 8.0(Oreo)
请看下面的错误:

{
  "shard":0,
  "index":"my_index",
  "node":"-Dzw5527SZGf7U0Ebut0PQ",
  "reason":{
    "type":"query_shard_exception",
    "reason":"Failed to parse query [Android 8.0 (Oreo]",
    "index_uuid":"wo7ihAX8Syy15MSDrS-Wsw",
    "index":"my_index",
    "caused_by":{
      "type":"parse_exception",
      "reason":"Cannot parse 'Android 8.0 (Oreo': Encountered \"<EOF>\" at line 1, column 17.\r\nWas expecting one of:\r\n    <AND> ...\r\n    <OR> ...\r\n    <NOT> ...\r\n    \"+\" ...\r\n    \"-\" ...\r\n    <BAREOPER> ...\r\n    \"(\" ...\r\n    \")\" ...\r\n    \"*\" ...\r\n    \"^\" ...\r\n    <QUOTED> ...\r\n    <TERM> ...\r\n    <FUZZY_SLOP> ...\r\n    <PREFIXTERM> ...\r\n    <WILDTERM> ...\r\n    <REGEXPTERM> ...\r\n    \"[\" ...\r\n    \"{\" ...\r\n    <NUMBER> ...\r\n    ",
      "caused_by":{
        "type":"parse_exception",
        "reason":"Encountered \"<EOF>\" at line 1, column 17.\r\nWas expecting one of:\r\n    <AND> ...\r\n    <OR> ...\r\n    <NOT> ...\r\n    \"+\" ...\r\n    \"-\" ...\r\n    <BAREOPER> ...\r\n    \"(\" ...\r\n    \")\" ...\r\n    \"*\" ...\r\n    \"^\" ...\r\n    <QUOTED> ...\r\n    <TERM> ...\r\n    <FUZZY_SLOP> ...\r\n    <PREFIXTERM> ...\r\n    <WILDTERM> ...\r\n    <REGEXPTERM> ...\r\n    \"[\" ...\r\n    \"{\" ...\r\n    <NUMBER> ...\r\n    "
      }
    }
  }
}

以下查询对我有用:

{
  "query":{
    "bool":{
      "must":[
        {
          "query_string":{
            "query":"Android 8.0 (Oreo)",
            "default_operator":"AND"
          }
        }
      ]
    }
  }
}

以下查询引发异常:

{
  "query":{
    "bool":{
      "must":[
        {
          "query_string":{
            "query":"Android 8.0 (Oreo",
            "default_operator":"AND"
          }
        }
      ]
    }
  }
}

你可以帮我解决这个问题,为什么我在查询中错过时会收到错误?

2 个答案:

答案 0 :(得分:2)

括号是reserved character中的query string syntax,所以你需要像这样转义它

{
  "query":{
    "bool":{
      "must":[
        {
          "query_string":{
            "query":"Android 8.0 \\(Oreo",
            "default_operator":"AND"
          }
        }
      ]
    }
  }
}

答案 1 :(得分:0)

我也面临同样的问题。 我在邮递员中传递的字符串格式错误。 请检查格式。