Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE happens on short prefix query on a field with index_prefixes #1038

Open
mattjarnevic opened this issue Jul 13, 2022 · 0 comments
Open

NPE happens on short prefix query on a field with index_prefixes #1038

mattjarnevic opened this issue Jul 13, 2022 · 0 comments

Comments

@mattjarnevic
Copy link

Running ElasticSearch version 7.17.5
Running latest release (7.2.1) of elasticsearch-rails and elasticsearch-model

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

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.

This issue was found in OpenSearch and has a very detailed explanation of the issue along with a fix. Copied the details over for the basics of when this occurs. opensearch-project/OpenSearch#2879

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant