NullPointerException when performing a Completion Suggester query with synonym analyzer, v8.5

I need to be able to perform Completion Suggest queries that are context dependent.

When executing the query below:

POST synonym_file_test/_search
{
"_source": "suggest",     
"suggest": {
  "my-suggest": {
    "prefix": "N",
    "completion": {
      "field": "general_suggest",
      "size": 3,
      "skip_duplicates": false,
      "contexts" : {
        "typ_context" : ["1"] 
        }
      }
    }
  }
}

#returns the following error

{
  "error": {
    "root_cause": [
      {
        "type": "null_pointer_exception",
        "reason": """Cannot invoke "org.elasticsearch.index.analysis.AnalyzerComponents.getCharFilters()" because "components" is null"""
      }
    ],
  }
}

Although the analyzer seems to be working fine when using it like below:

GET synonym_file_test/_analyze
{
  "analyzer": "search_analyzer",
  "text": "N"
}

#returns the following

{
  "tokens": [
    {
      "token": "norra",
      "start_offset": 0,
      "end_offset": 1,
      "type": "SYNONYM",
      "position": 0
    },
    {
      "token": "n",
      "start_offset": 0,
      "end_offset": 1,
      "type": "<ALPHANUM>",
      "position": 0
    }
  ]
}

The following is the config (mapping/settings) I am using for this purpose:

PUT synonym_file_test
{
 "mappings: {
   "properties": {
      "general_suggest": {
        "type": "completion",
        "search_analyzer": "search_analyzer",
        "preserve_separators": true,
        "preserve_position_increments": true,
        "max_input_length": 50,
        "contexts" : [
            {
              "name" : "typ_context",
              "type" : "category",
              "path" : "typ"
            }
          ]
      }
    }
 },
 "settings": { 
    "index":{ 
      "analysis": { 
        "analyzer": {
          "index_analyzer": {
            "tokenizer" : "standard",
            "filter" : [
              "lowercase"  
            ]
          },
          "search_analyzer": {
            "tokenizer": "standard",
            "filter": [
              "lowercase",
              "synonym_filter"
            ]
          }
        },
      "filter":{
        "synonym_filter": {
          "type":"synonym_graph",
          "synonyms_path": "analyze/synonyms.txt",
          "updateable": true
        }
      } 
    } 
  } 
 }
}

I have looked in to the documentation regarding both the Synonyms and the Completion Suggesters

Synonym token filter | Elasticsearch Guide [8.8] | Elastic

and

Suggesters | Elasticsearch Guide [8.5] | Elastic

also done alot of looking around on the forum and third party docs to find a fix for it without ant progress, hence the post.

Thankful for an input on this, regards

Hi @jacoMet

The reason for the problem I don't know for sure, it could even be a limitation of the suggester + synonyms.
But you could try this:

Remove search_analyzer in mapping field general_suggest.

Add search_analyzer in query.

"suggest": {
    "my-suggest": {
      "prefix": "n",
      "completion": {
        "analyzer": "search_analyzer",
        "field": "general_suggest",

Hey @RabBit_BR !

This worked, it seems logical that when not initiating the synonyms during the indexing phase one needs to specify the analyzer to be used during the search phase inside the query. Dont know if i have the right ide about, what do you think?

Anyhow all is well and good, thanks a lot,

best regards

UPDATE

I thought that the last solution was a fix to my issue but I was wrong, although i did not get any errors while executing the query through the synonym analyzer, the synonyms were never applied instead the completion suggester just worked as it would without the synonym analyzer. I have stopped looking in to it for now and just decided too keep the synonyms defined in the mapping untill I have time to prioritixe this again.

Regards

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.