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

Error when doing a prefix search when the prefix is min_chars -1 #94364

Closed
joancf opened this issue Mar 7, 2023 · 1 comment · Fixed by #94369
Closed

Error when doing a prefix search when the prefix is min_chars -1 #94364

joancf opened this issue Mar 7, 2023 · 1 comment · Fixed by #94369
Assignees
Labels
>bug :Search Relevance/Analysis How text is split into tokens Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch

Comments

@joancf
Copy link

joancf commented Mar 7, 2023

Elasticsearch Version

8.6.2

Installed Plugins

elastiknn-8.6.2.1.zip

Java Version

openjdk 18.0.2.1 2022-08-18

OS Version

docker: Linux c30f7a57fb60 5.4.0-139-generic #156-Ubuntu SMP Fri Jan 20 17:27:18 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Problem Description

When doing a prefix search over a text field with index_prefixes and min_chars = X , if the length of the prefix is X-1, the search fails with a lucene null pointer error:

this error has been reported (and solved) for openserarch, here opensearch-project/OpenSearch#2826

Steps to Reproduce

1 crate an index with index prefix and index some docs:

PUT test_prefix
{
  "mappings": {
    "properties": {
      "t": {
        "type": "text",
        "index_prefixes": {"min_chars":3}
      }
    }
  }
}

POST test_prefix/_doc
{
  "t":"This is the test to these kind of errors"
}

Do the search , the first and second work correctly while the last one, with a prefix of min_chars-1 fails

GET test_prefix/_search
{"query":{"prefix":{"t": "t"}}}

GET test_prefix/_search
{"query":{"prefix":{"t": "the"}}}

GET test_prefix/_search
{"query":{"prefix":{"t": "th"}}}

simple_query_string also fails

GET test_prefix/_search
{"query":{"simple_query_string":{"fields":["t"], "query":"th*"}}}

The regexp is the only option to do the search, but i could not find information on the documentation if regexp queries take advantage of the index_prefix

GET test_prefix/_search
{"query":{"regexp": {
      "t": {
        "value": "th.*",
        "flags": "ALL",
        "case_insensitive": true,
        "max_determinized_states": 10000,
        "rewrite": "constant_score"
      }
    }}}

Output

the error produced is the next

{
  "error" : {
    "root_cause" : [
      {
        "type" : "null_pointer_exception",
        "reason" : "Cannot invoke \"org.apache.lucene.search.MultiTermQuery$RewriteMethod.rewrite(org.apache.lucene.index.IndexReader, org.apache.lucene.search.MultiTermQuery)\" because \"this.rewriteMethod\" is null"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "test_prefix",
        "node" : "KPamBItNTOi2hLRNTFcTMw",
        "reason" : {
          "type" : "null_pointer_exception",
          "reason" : "Cannot invoke \"org.apache.lucene.search.MultiTermQuery$RewriteMethod.rewrite(org.apache.lucene.index.IndexReader, org.apache.lucene.search.MultiTermQuery)\" because \"this.rewriteMethod\" is null"
        }
      }
    ],
    "caused_by" : {
      "type" : "null_pointer_exception",
      "reason" : "Cannot invoke \"org.apache.lucene.search.MultiTermQuery$RewriteMethod.rewrite(org.apache.lucene.index.IndexReader, org.apache.lucene.search.MultiTermQuery)\" because \"this.rewriteMethod\" is null",
      "caused_by" : {
        "type" : "null_pointer_exception",
        "reason" : "Cannot invoke \"org.apache.lucene.search.MultiTermQuery$RewriteMethod.rewrite(org.apache.lucene.index.IndexReader, org.apache.lucene.search.MultiTermQuery)\" because \"this.rewriteMethod\" is null"
      }
    }
  },
  "status" : 500
}
@joancf joancf added >bug needs:triage Requires assignment of a team area label labels Mar 7, 2023
@joancf joancf changed the title Error when doing a prefix search when the prefix is min_prefix -1 Error when doing a prefix search when the prefix is min_chars -1 Mar 7, 2023
@HiDAl HiDAl added :Search Relevance/Analysis How text is split into tokens Team:Search Meta label for search team and removed needs:triage Requires assignment of a team area label labels Mar 7, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@benwtrent benwtrent self-assigned this Mar 7, 2023
benwtrent added a commit that referenced this issue Mar 8, 2023
In certain scenarios, running a MultiTerm query sets a `null` rewrite method. While `null` is usually checked, there are branches in the code where this is not adequately checked.

Additionally, `MultiTermQuery#setRewriteMethod` has been deprecated for a while. So, to correct this bug, 

 - Remove calls to `MultiTermQuery#setRewriteMethod` where possible
 - Always check for `null` rewrite method


closes: #94364
benwtrent added a commit to benwtrent/elasticsearch that referenced this issue Mar 8, 2023
…c#94369)

In certain scenarios, running a MultiTerm query sets a `null` rewrite method. While `null` is usually checked, there are branches in the code where this is not adequately checked.

Additionally, `MultiTermQuery#setRewriteMethod` has been deprecated for a while. So, to correct this bug, 

 - Remove calls to `MultiTermQuery#setRewriteMethod` where possible
 - Always check for `null` rewrite method


closes: elastic#94364
elasticsearchmachine pushed a commit that referenced this issue Mar 8, 2023
#94399)

In certain scenarios, running a MultiTerm query sets a `null` rewrite method. While `null` is usually checked, there are branches in the code where this is not adequately checked.

Additionally, `MultiTermQuery#setRewriteMethod` has been deprecated for a while. So, to correct this bug, 

 - Remove calls to `MultiTermQuery#setRewriteMethod` where possible
 - Always check for `null` rewrite method


closes: #94364
@javanna javanna added Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Relevance/Analysis How text is split into tokens Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants