Skip to content

query_string query with forward slash (/) causes token_mgr_error in parser #140012

@ban-xiu

Description

@ban-xiu

Elasticsearch Version

8.17.3

Installed Plugins

No response

Java Version

jdk23

OS Version

6.6.0-75.0.0.79.oe2403sp1.x86_64

Problem Description

When executing a query_stringquery containing a forward slash (/) within a field's search value, the Elasticsearch parser fails with a token_mgr_error(lexical error). The query is interpreted incorrectly, causing the parser to encounter an unexpected (end-of-input) prematurely.

Steps to Reproduce

POST /myindex/_search
{
  "query": {
    "query_string": {
      "query": "display_name:(a b/b c d e)^4.5"
    }
  }
}

Logs (if relevant)

{
  "error": {
    "root_cause": [
      {
        "type": "token_mgr_error",
        "reason": """token_mgr_error: Lexical error at line 1, column 31.  Encountered: <EOF> after prefix "/b c d e)^4.5" (in lexical state 2)"""
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "myindex",
        "node": "xxxxxx",
        "reason": {
          "type": "query_shard_exception",
          "reason": "Failed to parse query [display_name:(a b/b c d e)^4.5]",
          "index_uuid": "xxxxxx",
          "index": "myindex",
          "caused_by": {
            "type": "parse_exception",
            "reason": """parse_exception: Cannot parse 'display_name:(a b/b c d e)^4.5': Lexical error at line 1, column 31.  Encountered: <EOF> after prefix "/b c d e)^4.5" (in lexical state 2)""",
            "caused_by": {
              "type": "token_mgr_error",
              "reason": """token_mgr_error: Lexical error at line 1, column 31.  Encountered: <EOF> after prefix "/b c d e)^4.5" (in lexical state 2)"""
            }
          }
        }
      }
    ],
    "caused_by": {
      "type": "token_mgr_error",
      "reason": """token_mgr_error: Lexical error at line 1, column 31.  Encountered: <EOF> after prefix "/b c d e)^4.5" (in lexical state 2)"""
    }
  },
  "status": 400
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    >bugneeds:triageRequires assignment of a team area label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions