0

I am using POST /_search API to search data in elastic search 5.6.0.

When I tried to search for query Android 8.0 (Oreo) search API worked successfully, but when I tried for Android 8.0 (Oreo elastic search failed with error Failed to parse query [Android 8.0 (Oreo]
Please have a look at error below:

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

Below query worked for me :

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

Below query throws an exception:

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

could you please help me on this, why am I getting an error when I missed ) in a query?

2 Answers 2

3

The parenthesis is a reserved character in the query string syntax, so you need to escape it like this

{
  "query":{
    "bool":{
      "must":[
        {
          "query_string":{
            "query":"Android 8.0 \\(Oreo",
            "default_operator":"AND"
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

7 Comments

Hi Val, I tried this as well. If I try to escape it using \, it throws me an error { "type": "json_parse_exception", "reason": "Unrecognized character escape '(' (code 40)\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@59ed12ad; line: 7, column: 36]" } Also, I would like to know, how come ( ) worked and ( not ?
My bad try again, you need to escape the backslash, too.
Can you please tell me, how come ( ) worked for me even without escaping
() worked but not as you expected, the parenthesis where simply wrapping the Oreo token but in no case they were matched
Thanks a lot, Val.
|
0

I also faced the same issue. String i was passing in the Postman was in wrong format. please check the format.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.