Suggester doesn't suggest as expected, based on beginning of word

I want ElasticSearch to suggest more words, based on the beginning of a word. My example is the following. I have these titles:

  • affaldsregister
  • affaldsdatasystem - Import af indberetninger
  • anmod om ændring af affaldsordning
  • ansøgning om dispensation for affaldsregulativ

I want the suggester to find, the words in bold, when I use the word affald or afald . I have tried the following:

POST virk_search_pub_dan/_search 
{
  "suggest": {
    "simple_terms": {
      "text": "affald",
      "term": {
        "max_edits": 1,
        "max_term_freq": 1,
        "max_inspections": 5,
        "field": "title",
        "size": 5,
        "suggest_mode": "always",
        "prefix_length": 3
      }        
    }
  }
}

But I get no suggestions. My title field is analyzed with the standard tokenizer. What am I missing?

Br Casper

I have create an example:

PUT test

PUT test/_doc/1
{
  "title": "affaldsregister"
}

PUT test/_doc/2
{
  "title": "affaldsdatasystem - Import af indberetninger"
}

PUT test/_doc/3
{
  "title": "anmod om ændring af affaldsordning"
}

PUT test/_doc/4
{  "title": "ansøgning om dispensation for affaldsregulativ " }

POST test/_search
{
  "suggest": {
    "term_suggest": {
      "text": "affald",
      "term": {
        "field": "title"
      }
    }
  }
}

In the example you posted, the edit distance to find a term is too much so elasticsearch can not suggest a correction for your incomplete/typo text.

Here is an example which works:

GET test/_search
{
  "suggest": {
    "term_suggest": {
      "text": "affaldsdasystem",
      "term": {
        "field": "title"
      }
    }
  }
}

It gives:

{
  "took" : 10,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "suggest" : {
    "term_suggest" : [
      {
        "text" : "affaldsdasystem",
        "offset" : 0,
        "length" : 15,
        "options" : [
          {
            "text" : "affaldsdatasystem",
            "score" : 0.8666667,
            "freq" : 1
          }
        ]
      }
    ]
  }
}

If you are looking for completion, read https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-suggesters.html#completion-suggester and https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-as-you-type.html

Thanks for the response.

My case is, I have lot of documents, and I want suggestions like Google, based on the text in the documents. I both want single word and phase suggestions. I am not sure, how to do that, with the standard suggesters.

I believe this is what AppSearch can provide out of the box.

Otherwise, I think you can combine hopefully multiple suggestions within the same API call???

Not an expert on that part here. Sorry :frowning:

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