# Suggest query issue

**URL:** https://discuss.elastic.co/t/suggest-query-issue/364514
**Category:** Elasticsearch
**Created:** [August 7, 2024, 6:38am UTC](https://discuss.elastic.co/t/suggest-query-issue/364514 "2024-08-07T06:38:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jahedi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jahedi/32/135254_2.png) [@jahedi](https://discuss.elastic.co/u/jahedi)
#### Post date: [August 7, 2024, 6:38am UTC](https://discuss.elastic.co/t/suggest-query-issue/364514/1 "2024-08-07T06:38:13Z")

</div>

Hi,  
I am using Suggest query for a Did-you-mean functionality based on this tutorial [Create a simple “did you mean” — ElasticSearch](https://medium.com/@andre.luiz1987/create-a-simple-did-you-mean-elasticsearch-9f0c0460a1b5) but there is an issue.

If a typo happens in the middle of a word, the suggest query returns relative phrases and it's fine but if the typo happens in the beginning of a word, It mostly shows irrelative options or shows no options.

for example consider this  
typeo is in the middle of the word, `linox` instead of `linux`

```auto
GET my_index/_search
{
  "suggest": {
    "text": "linox",
    "did_you_mean": {
      "phrase": {
        "field": "title.suggest",
        "size": 5,
        "confidence": 1,
        "max_errors":2,
        "collate": {
          "query": { 
            "source" : {
              "match": {
                "{{field_name}}": {
                  "query": "{{suggestion}}",
                  "operator": "and"
                }
              }
            }
          },
          "params": {"field_name" : "title"}, 
          "prune" :false
        }
      }
    }
  }
}

```

and It returns reletive options:

```auto
{
  "took": 8,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "suggest": {
    "did_you_mean": [
      {
        "text": "linox",
        "offset": 0,
        "length": 5,
        "options": [
          {
            "text": "linux",
            "score": 0.019855337
          },
          {
            "text": "link",
            "score": 0.0065617864
          }
        ]
      }
    ]
  }
}

```

But the problem is when the typo is at the first of the word. consider this:  
`Iinux` (starting with capital i)

```auto
GET my_index/_search
{
  "suggest": {
    "text": "Iinux",
    "did_you_mean": {
      "phrase": {
        "field": "title.suggest",
        "size": 5,
        "confidence": 1,
        "max_errors":2,
        "collate": {
          "query": { 
            "source" : {
              "match": {
                "{{field_name}}": {
                  "query": "{{suggestion}}",
                  "operator": "and"
                }
              }
            }
          },
          "params": {"field_name" : "title"}, 
          "prune" :false
        }
      }
    }
  }
}

```

and the output is empty:

```auto
{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "suggest": {
    "did_you_mean": [
      {
        "text": "Iinox",
        "offset": 0,
        "length": 5,
        "options": []
      }
    ]
  }
}

```

Both words `Iinux` and `linox` only have once character mistake and both are really similar to `linux`.  
Why Suggest query has this behavior and how can i fix this issue?

Thanks in advance.

---

<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: [August 7, 2024, 12:57pm UTC](https://discuss.elastic.co/t/suggest-query-issue/364514/2 "2024-08-07T12:57:46Z")

</div>

Hi @jahedi

Change this **prefix\_length** property to 0.

Doc:

> `prefix_length` The number of minimal prefix characters that must match in order be a candidate suggestions. Defaults to 1. Increasing this number improves spellcheck performance. Usually misspellings don’t occur in the beginning of terms.

> **[Suggesters | Elasticsearch Guide \[7.17\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-suggesters.html#_direct_generators)**

```auto
      "phrase": {
        "field": "title.suggest",
        "size": 5,
        "confidence": 1,
        "direct_generator": [
          {
            "field": "title.suggest",
            "prefix_length": 0. <<<<-------
          }
        ],

```

---

<div class="post-metadata">

### Author: ![jahedi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jahedi/32/135254_2.png) [@jahedi](https://discuss.elastic.co/u/jahedi)
#### Post date: [August 7, 2024, 1:05pm UTC](https://discuss.elastic.co/t/suggest-query-issue/364514/3 "2024-08-07T13:05:16Z")

</div>

Thank you so much
