# How can I fix this to suggest phrases after say, three characters have been entered?

**URL:** <https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755>\
**Category:** Elasticsearch\
**Created:** [September 25, 2023, 12:40pm UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755 "2023-09-25T12:40:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhavyagc](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bhavyagc](https://discuss.elastic.co/u/Bhavyagc)\
**Post date:** [September 25, 2023, 12:40pm UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/1 "2023-09-25T12:40:48Z")

</div>

My query  
{  
"suggest": {  
"text" : "Tes",  
"simple\_phrase" : {  
"phrase" : {  
"field" : "Active\_Substance\_mstr.trigram",  
"size" : 1,  
"max\_errors" : 6,  
"direct\_generator" : [ {  
"field" : "Active\_Substance\_mstr.trigram",  
"suggest\_mode" : "always",  
"min\_word\_length" : 1,  
"max\_edits" :"2"  
} ],  
"collate": {  
"query": {  
"source" : {  
"match": {  
"{{field\_name}}" : "{{suggestion}}"  
}  
}  
},  
"params": {"field\_name" : "title"},  
"prune": true  
}  
}  
}  
}  
}

Data:  
{  
"Active\_Substance\_mstr": "Test",  
"Biomarker\_mstr": "TestABC"  
}  
Result:

{  
"took": 1,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": {  
"value": 0,  
"relation": "eq"  
},  
"max\_score": null,  
"hits":   
},  
"suggest": {  
"simple\_phrase": [  
{  
"text": "Tes",  
"offset": 0,  
"length": 3,  
"options":   
}  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 25, 2023, 1:26pm UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/2 "2023-09-25T13:26:28Z")

</div>

Welcome!

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Have a look at the [Elastic Stack and Solutions Help · Forums and Slack | Elastic](https://elastic.co/community/help) page. It contains also lot of useful information on how to ask for help.

Also please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.

---

<div class="post-metadata">

**Author:** ![Bhavyagc](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bhavyagc](https://discuss.elastic.co/u/Bhavyagc)\
**Post date:** [September 25, 2023, 4:51pm UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/3 "2023-09-25T16:51:30Z")

</div>

Hi !

Thanks for your response..

I am trying to implement Phrase suggester in my project to achieve autocomplete functionality. Below is the problem I am facing.  
I am searching for 'BGM' I should get 'BGM67' as my result, however its not happening. Suppose if I have a word 'Product' and If I type prod then product and other suggestions that starts with prod should get listed, how can I achieve it ? (default max edit is set to 2, is this the reason that product is not listed). But after typing 'Produ' I am getting 'Product' in the suggestion list.

In other post I checked on how to implement Phrase suggester functionality using elastic.clients.elasticsearch .net client as I did not find reference.

Could you please help?

Please let me know if you need any further details....

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 25, 2023, 7:09pm UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/4 "2023-09-25T19:09:36Z")

</div>

> [@Bhavyagc](#):
>
> Could you please help?

Please provide a full recreation script as I mentioned earlier. That would help.

Otherwise, please have a look at this resource which could help:

[![](https://us1.discourse-cdn.com/elastic/original/3X/9/0/908b141b2fd1b4baa6bcf151c4a25ad9a73872bb.jpeg "Search as you type - Daily Elastic Byte S01E06") ](https://www.youtube.com/watch?v=GCnPx89oD4Y)

---

<div class="post-metadata">

**Author:** ![Bhavyagc](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bhavyagc](https://discuss.elastic.co/u/Bhavyagc)\
**Post date:** [September 26, 2023, 5:16am UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/5 "2023-09-26T05:16:29Z")

</div>

Hi, Good Morning..

Below here is what I am trying to achieve...

I am trying to create an index 'dpa\_suggestormultifield' in Elasticsearch with the below mappings for field 'Active\_Substance\_mstr'

```auto
PUT/ http://localhost:9200/dpa_suggestormultifield
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "analysis": {
        "analyzer": {
          "trigram": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["lowercase","shingle"]
          }
         
        },
        "filter": {
          "shingle": {
            "type": "shingle",
            "min_shingle_size": 2,
            "max_shingle_size": 3
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "Active_Substance_mstr": {
        "type": "text",
        "fields": {
          "trigram": {
            "type": "text",
            "analyzer": "trigram"
          }
        }
      }
    }
  }
}

```

Below is the data I am inserting into my index.

```auto
POST/ http://localhost:9200/dpa_suggestormultifield/_bulk
 {
        "Active_Substance_mstr": "rurioctocog alfa pegol"
    }
    {
        "Active_Substance_mstr": "tenofovir disoproxil"
    }
    {
        "Active_Substance_mstr": "trastuzumad"
    }
     {
        "Active_Substance_mstr": "CHLOROPROCAINE HYDROCHLORIDE"
    }
    {
      "Active_Substance_mstr": "trastuzumad"
     }
        {
        "Active_Substance_mstr": "The Vaccines and Related Biological Product"
    }
      {
        "Active_Substance_mstr": "BGMQ2"
    }
    {
        "Active_Substance_mstr": "Test"
    }
    
    {
        "Active_Substance_mstr": "tar-ausguide20110608bio"
    }

```

After data insert I am trying to get suggestions using phrase suggester with text 'prod' I didn't get matching results because of max\_edits is defaluts to 2.

```auto
GET/ http://localhost:9200/dpa_suggestormultifield/_search
{
  "suggest": {
    "text" : "prod",
    "simple_phrase" : {
      "phrase" : {
        "field" : "Active_Substance_mstr.trigram",
        "size" : 1,
        "direct_generator" : [ {
          "field" : "Active_Substance_mstr.trigram",
          "suggest_mode" : "always",
          "min_word_length" : 1
        } ]

        }
      }
    }
  }

```

However if I try to search with 'Produ' I get the results. Below is the response.

```auto
{
    "took": 61,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "suggest": {
        "simple_phrase": [
            {
                "text": "Produ",
                "offset": 0,
                "length": 5,
                "options": [
                    {
                        "text": "product",
                        "score": 0.21575698
                    }
                ]
            }
        ]
    }
}

```

My question here is how to get results even if I search with **'prod'** - I should get results as **'product'** using phrase suggester

Please let me know if you need further details.

---

<div class="post-metadata">

**Author:** ![Bhavyagc](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bhavyagc](https://discuss.elastic.co/u/Bhavyagc)\
**Post date:** [September 26, 2023, 5:16pm UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/6 "2023-09-26T17:16:53Z")

</div>

Sorry @dadoonet , Search as you type doesn't suits our requirement that's the reason we are going ahead with phrase suggester for autocomplete functionality.

Above is the query and results we are trying to achieve in .NET, dummy data is used for development purpose.

Also, could you please help me to implement Phrase suggester in .NET Core using elastic.clients.elasticsearch library?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 26, 2023, 7:24pm UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/7 "2023-09-26T19:24:02Z")

</div>

No sorry. I can't. I'm not a dotnet dev.

---

<div class="post-metadata">

**Author:** ![Bhavyagc](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@Bhavyagc](https://discuss.elastic.co/u/Bhavyagc)\
**Post date:** [September 27, 2023, 4:34am UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/8 "2023-09-27T04:34:30Z")

</div>

@dadoonet , Could you help me with this, can this be achievable?

---

<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:** [October 25, 2023, 4:35am UTC](https://discuss.elastic.co/t/how-can-i-fix-this-to-suggest-phrases-after-say-three-characters-have-been-entered/343755/9 "2023-10-25T04:35:14Z")

</div>

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