Skip to content

[BUG] NPE happens on short prefix query on a field with index_prefixes #2826

Closed
@woby

Description

Describe the bug
( index_prefixes is not documented in OpenSearch’s documentation but AFAIK OpenSearch is compatible with ElasticSearch 7.10, which has index_prefixes parameter.)

When a prefix query run on a field with index_prefixes, if the length of characters in the query is [min_chars of the index_prefixes option] - 1, an error is responded.
The root cause seems to be NullPointerException.

To Reproduce
Steps to reproduce the behavior:

  1. Create an index which has a field with index_prefixes option; its min_chars is implicitly 2.
PUT test
{
  "mappings": {
    "properties": {
      "t": {
        "type": "text",
        "index_prefixes": {}
      }
    }
  }
}
  1. Search by prefix query with one character on the field.
GET test/_search
{"query":{"prefix":{"t": "a"}}}
  1. An error is responded. It says the root cause is NullPointerException.
{
  "error" : {
    "root_cause" : [
      {
        "type" : "query_shard_exception",
        "reason" : "failed to create query: Cannot invoke \"Object.hashCode()\" because \"this.rewriteMethod\" is null",
        "index" : "test",
        "index_uuid" : "XPqfSP1xT7WJt9Sxzt65qg"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "test",
        "node" : "QA35rulpSza20Wsx6rNSEg",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "failed to create query: Cannot invoke \"Object.hashCode()\" because \"this.rewriteMethod\" is null",
          "index" : "test",
          "index_uuid" : "XPqfSP1xT7WJt9Sxzt65qg",
          "caused_by" : {
            "type" : "null_pointer_exception",
            "reason" : "Cannot invoke \"Object.hashCode()\" because \"this.rewriteMethod\" is null"
          }
        }
      }
    ]
  },
  "status" : 400
}
  1. simple_query_string also fails.
# fails with the same error
GET test/_search
{"query":{"simple_query_string":{"fields":["t"], "query":"a*"}}}

Expected behavior
Run without errors. I know it is not efficient.

A similar query_string runs without any errors.

GET test/_search
{"query":{"query_string":{"fields":["t"], "query":"a*"}}}

I tried some patterns (min_chars = 2, 3, 5), and it seems that the prefix query with characters the length of which is min_chars - 1 fails. When the length is less than min_chars - 1, the query succeeds.

Plugins
N/A

Screenshots
N/A

Host/Environment (please complete the following information):

  • Version: 1.3.1

Additional context
Add any other context about the problem here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions