'suggest_mode' => 'always' does not return suggestion's full word query

Hello, I am running an suggestions query using Elasticsearch v5.5. When looking for a whole word in the document (e.g. 'kneecap'), suggestions are not returned when the whole word is typed, but it does appear when typing part of the word (e.g. 'kneec'). I tried adding 'suggest_mode' => 'always into the params, but it still does not return the desired word.

Query params:

$autocompleteParams = [
    'index' => $this->config['esindex_suggestions'],
    'type' => '_doc',
    'body' => [
        '_source' => [ 'term', 'type', 'id' ],
        'suggest' => [
            'suggestions' => [
                'text' => $term,
                'completion' => [
                    'field' => 'suggestions',
                    'contexts' => [ 'type' => $filter ],
                    'size' => 10,
                    'suggest_mode' => 'always'
                ],
            ],
        ],
    ],
];
// run the autocomplete query
$autocompleteResults = $this->client->search($autocompleteParams);

Thanks!

Hi Jacob.

Is it possible send sample of mapping index and document?

I work for a company that deals with sensitive data so I don't feel too comfortable giving any samples. Is there any other information I can provide?

Maybe you have a self-made example of how you are indexing the document. It doesn't have to be all mapping but just the field that you apply the type suggest.
I recently implemented the completion suggester and had no problems.

@RabBit_BR , actually, I have the same problem.
Lets say I have this entity in my index:

{ 
        "_index": "myIndex",
        "_type": "_doc",
        "_id": "YWpDLYABDc-kRS0otX2Y",
        "_score": 1,
        "_source": { 
          "entry": "mazda"
        }
}

Then I run simple suggestion query:

{
  "suggest": {
    "suggestion": {
      "text": "mazda",
      "term": {
        "field": "entry",
        "suggest_mode": "always"
      }
    }
  }
}

And I get response without any options:

"suggest": { - 
    "suggestion": [ - 
      { - 
        "text": "mazda",
        "offset": 0,
        "length": 5,
        "options": [ - 

        ]
      }
    ]
  }

I what to know that specific term was or wasn't present in my index during suggestion, e.g. understand when it is a full match or there is no matches at all. How can I achieve it?

Of course, when my request contains mistakes, like:

{
  "suggest": {
    "suggestion": {
      "text": "masda",
      "term": {
        "field": "entry",
        "suggest_mode": "always"
      }
    }
  }
}

I get a correct suggestion option:

"suggest": { - 
    "suggestion": [ - 
      { - 
        "text": "masda",
        "offset": 0,
        "length": 5,
        "options": [ - 
          { - 
            "text": "mazda",
            "score": 0.8,
            "freq": 1
          }
        ]
      }
    ]
  }

My question is how can I understand when suggestion's text has no match at all, like:

{
  "suggest": {
    "suggestion": {
      "text": "ddfgsd",
      "term": {
        "field": "entry",
        "suggest_mode": "always"
      }
    }
  }
}

and whet it is a perfect match, like:

{
  "suggest": {
    "suggestion": {
      "text": "mazda",
      "term": {
        "field": "entry",
        "suggest_mode": "always"
      }
    }
  }
}

There is a difference in the two cases.
In yours you make use of the Term suggester.

The term suggester suggests terms based on edit distance. The provided suggest text is analyzed before terms are suggested. The suggested terms are provided per analyzed suggest text token. The term suggester doesn’t take the query into account that is part of request.

This explains the behavior of your results.

In the case of @jacreich I could not reproduce.

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "entry": {
        "type": "completion"
      }
    }
  }
}
POST my-index-000001/_doc
{
  "entry": "kneecap"
}
GET my-index-000001/_search
{
  "suggest": {
    "suggestion": {
      "text": "kneecap",
      "completion": {
        "field": "entry"
      }
    }
  }
}
  "suggest" : {
    "suggestion" : [
      {
        "text" : "kneecap",
        "offset" : 0,
        "length" : 7,
        "options" : [
          {
            "text" : "kneecap",
            "_index" : "my-index-000001",
            "_type" : "_doc",
            "_id" : "WhoeLoABqPZhgcMso-qX",
            "_score" : 1.0,
            "_source" : {
              "entry" : "kneecap"
            }
          }
        ]
      }
    ]
  }

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