# Spellchecking with term and phrase suggesters

**URL:** <https://discuss.elastic.co/t/spellchecking-with-term-and-phrase-suggesters/21109>\
**Category:** Elasticsearch\
**Created:** [December 5, 2014, 4:49pm UTC](https://discuss.elastic.co/t/spellchecking-with-term-and-phrase-suggesters/21109 "2014-12-05T16:49:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![micpalmia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/micpalmia/32/541_2.png) [@micpalmia](https://discuss.elastic.co/u/micpalmia)\
**Post date:** [December 5, 2014, 4:49pm UTC](https://discuss.elastic.co/t/spellchecking-with-term-and-phrase-suggesters/21109/1 "2014-12-05T16:49:49Z")

</div>

Hi all,

I need to set up a system that provides spellchecking functionality on user  
searches, similar to what Google does with its well known \*did-you-mean \*  
suggestions.  
The _term suggester_ works very well for single words, but it doesn't take  
into account shingles, thus not being able to provide suggestions that are  
accurate enough for the standards I need to reach.  
The \*phrase suggester \*is perfect for what I need, working with my shingle  
fields to rank suggestions based on a language model, but _it will not  
provide any suggestions for single-term queries._

```
    {
        "phrase" : {
            "size" : 1,
            "gram_size" : 2,
            "field" : "description.shingle",
            "analyzer" : "intact",
            "direct_generator" : [
                {"field" : "description.unstemmed"}
            ]
        }
    }

```

At the moment I'm mixing this phrase suggester with a term suggester,  
returning from one or from the other depending on the length of the  
provided query, but I cannot understand why the phrase suggester cannot  
just output single-term suggestions as well.  
Any help?

Michele

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6536746f-887d-4c7c-9679-a117fe2c3add%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6536746f-887d-4c7c-9679-a117fe2c3add%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 5, 2014, 5:43pm UTC](https://discuss.elastic.co/t/spellchecking-with-term-and-phrase-suggesters/21109/2 "2014-12-05T17:43:35Z")

</div>

On Fri, Dec 5, 2014 at 11:49 AM, Michele Palmia [micpalmia@gmail.com](mailto:micpalmia@gmail.com) wrote:

> Hi all,
> 
> I need to set up a system that provides spellchecking functionality on  
> user searches, similar to what Google does with its well known \*did-you-mean  
> \*suggestions.  
> The _term suggester_ works very well for single words, but it doesn't  
> take into account shingles, thus not being able to provide suggestions that  
> are accurate enough for the standards I need to reach.  
> The \*phrase suggester \*is perfect for what I need, working with my  
> shingle fields to rank suggestions based on a language model, but _it  
> will not provide any suggestions for single-term queries._

That right there sounds like a bug. You should get _something_ for single  
term queries. If you could put together some concise reproduction steps  
with curl and file it as an issue I'll look into it.

Nik

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPmjWd2RdhksUmJWHyF7q3id5uXv%2BXh8ZRrO3vOh5QtJwfPJSQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd2RdhksUmJWHyF7q3id5uXv%2BXh8ZRrO3vOh5QtJwfPJSQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 5, 2014, 7:03pm UTC](https://discuss.elastic.co/t/spellchecking-with-term-and-phrase-suggesters/21109/3 "2014-12-05T19:03:15Z")

</div>

On Fri, Dec 5, 2014 at 12:43 PM, Nikolas Everett [nik9000@gmail.com](mailto:nik9000@gmail.com) wrote:

> On Fri, Dec 5, 2014 at 11:49 AM, Michele Palmia [micpalmia@gmail.com](mailto:micpalmia@gmail.com)  
> wrote:
> 
> > Hi all,
> > 
> > I need to set up a system that provides spellchecking functionality on  
> > user searches, similar to what Google does with its well known \*did-you-mean  
> > \*suggestions.  
> > The _term suggester_ works very well for single words, but it doesn't  
> > take into account shingles, thus not being able to provide suggestions that  
> > are accurate enough for the standards I need to reach.  
> > The \*phrase suggester \*is perfect for what I need, working with my  
> > shingle fields to rank suggestions based on a language model, but _it  
> > will not provide any suggestions for single-term queries._
> 
> That right there sounds like a bug. You should get _something_ for single  
> term queries. If you could put together some concise reproduction steps  
> with curl and file it as an issue I'll look into it.

Replying to myself:

I'm able to get the phrase suggester to spit out single word suggestions:

> **[Search results](https://en.wikipedia.org/w/index.php?fulltext=Search&profile=default&search=gult&title=Special%3ASearch&ns0=1)**
>
> The page "Gult" does not exist. You can create a draft and submit it for review or request that a redirect be created, but consider checking the search results below to see whether the topic is already covered.

So maybe its a problem or your end.

Here is how it all comes about:

> <https://en.wikipedia.org/w/index.php?cirrusDumpQuery=yes&fulltext=Search&profile=default&search=gult&title=Special%3ASearch&ns0=1>
>
> {
> "\_\_main\_\_": {
> "description": "full\_text search for 'gult'",
> "path": "enwiki\_content\\/\_search",
> "params": {
> "timeout": "10s"
> },
> "query": {
> "track\_total\_hits": true,
> "\_source": \[
> "namespace",
> "title",
> "namespace\_text",
> "wiki",
> "redirect.\*",
> "timestamp",
> "text\_bytes"
> \],
> "fields": \[
> ...

> <https://en.wikipedia.org/w/api.php?action=cirrus-mapping-dump&format=json>
>
> {"content":{"dynamic":"false","properties":{"all":{"type":"text","fields":{"plain":{"type":"text","analyzer":"plain","search\_analyzer":"plain\_search","similarity":"BM25","position\_increment\_gap":10}},"analyzer":"text","search\_analyzer":"text\_search","similarity":"BM25","position\_increment\_gap":10},"all\_near\_match":{"type":"text","fields":{"asciifolding":{"type":"text","index\_options":"freqs","analyzer":"near\_match\_asciifolding","similarity":"BM25"}},"index\_options":"freqs","analyzer":"near\_match"...

> <https://en.wikipedia.org/w/api.php?action=cirrus-settings-dump&format=json>
>
> {"content":{"page":{"index":{"refresh\_interval":"30s","indexing":{"slowlog":{"threshold":{"index":{"warn":"10s","trace":"-1","debug":"2s","info":"5s"}}}},"auto\_expand\_replicas":"0-2","provided\_name":"enwiki\_content\_1692831672","query":{"default\_field":"all"},"creation\_date":"1692831673066","analysis":{"filter":{"suggest\_shingle":{"max\_shingle\_size":"3","min\_shingle\_size":"2","output\_unigrams":"true","type":"shingle"},"weighted\_tags\_term\_freq":{"split\_char":"|","type":"term\_freq","max\_tf":"1000"},...

Those contain the query, mapping, and settings in the indexes involved.

If I had to suggest I'd say you might not be including unigrams in your  
suggest field.

Nik

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0Dze3W4pnNJPNRVN-WXao9RygxNKpGLF3AK7uoLAx4kg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0Dze3W4pnNJPNRVN-WXao9RygxNKpGLF3AK7uoLAx4kg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![micpalmia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/micpalmia/32/541_2.png) [@micpalmia](https://discuss.elastic.co/u/micpalmia)\
**Post date:** [December 9, 2014, 4:28pm UTC](https://discuss.elastic.co/t/spellchecking-with-term-and-phrase-suggesters/21109/4 "2014-12-09T16:28:03Z")

</div>

> I'm able to get the phrase suggester to spit out single word suggestions:  
> [https://en.wikipedia.org/w/index.php?title=Special%](https://en.wikipedia.org/w/index.php?title=Special%25)  
> 3ASearch&profile=default&search=gult&fulltext=Search  
> So maybe its a problem or your end.

If I had to suggest I'd say you might not be including unigrams in your

> suggest field.

Yes, that's actually true. As the documentation for the phrase suggester is  
not very explicit, I tried using a shingle field I was already using for  
proximity queries as the suggestion field, but that doesn't output unigrams.

The resources you linked are incredibly useful (and not just for the  
suggesters). Thank you very much!  
Michele

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALkm6ke\_\_P9VY5RHN%3Dp2mauFV98SWDTM-ZQ\_QkwYHsiPGe1TiQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALkm6ke__P9VY5RHN%3Dp2mauFV98SWDTM-ZQ_QkwYHsiPGe1TiQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:44am UTC](https://discuss.elastic.co/t/spellchecking-with-term-and-phrase-suggesters/21109/5 "2017-07-06T00:44:43Z")

</div>


