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

**URL:** <https://discuss.elastic.co/t/nullpointerexception-when-performing-a-completion-suggester-query-with-synonym-analyzer-v8-5/336674>\
**Category:** Elasticsearch\
**Created:** [June 22, 2023, 10:59am UTC](https://discuss.elastic.co/t/nullpointerexception-when-performing-a-completion-suggester-query-with-synonym-analyzer-v8-5/336674 "2023-06-22T10:59:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacoMet](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@jacoMet](https://discuss.elastic.co/u/jacoMet)\
**Post date:** [June 22, 2023, 10:59am UTC](https://discuss.elastic.co/t/nullpointerexception-when-performing-a-completion-suggester-query-with-synonym-analyzer-v8-5/336674/1 "2023-06-22T10:59:56Z")

</div>

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

When executing the query below:

```auto
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:

```auto
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:

```auto
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](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html)

and

[Suggesters | Elasticsearch Guide [8.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.5/search-suggesters.html#completion-suggester)

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

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [June 22, 2023, 2:36pm UTC](https://discuss.elastic.co/t/nullpointerexception-when-performing-a-completion-suggester-query-with-synonym-analyzer-v8-5/336674/2 "2023-06-22T14:36:47Z")

</div>

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.

> [@jacoMet](#):
>
> ` "search_analyzer": "search_analyzer",`

Add search\_analyzer in query.

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

```

---

<div class="post-metadata">

**Author:** ![jacoMet](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@jacoMet](https://discuss.elastic.co/u/jacoMet)\
**Post date:** [June 26, 2023, 7:03am UTC](https://discuss.elastic.co/t/nullpointerexception-when-performing-a-completion-suggester-query-with-synonym-analyzer-v8-5/336674/3 "2023-06-26T07:03:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jacoMet](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@jacoMet](https://discuss.elastic.co/u/jacoMet)\
**Post date:** [June 29, 2023, 10:47am UTC](https://discuss.elastic.co/t/nullpointerexception-when-performing-a-completion-suggester-query-with-synonym-analyzer-v8-5/336674/4 "2023-06-29T10:47:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 27, 2023, 10:47am UTC](https://discuss.elastic.co/t/nullpointerexception-when-performing-a-completion-suggester-query-with-synonym-analyzer-v8-5/336674/5 "2023-07-27T10:47:43Z")

</div>

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