# Inject Synonyms Direct Generator in phrase\_suggester

**URL:** <https://discuss.elastic.co/t/inject-synonyms-direct-generator-in-phrase-suggester/117131>\
**Category:** Elasticsearch\
**Created:** [January 25, 2018, 10:24pm UTC](https://discuss.elastic.co/t/inject-synonyms-direct-generator-in-phrase-suggester/117131 "2018-01-25T22:24:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![moy2010](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moy2010/32/22403_2.png) [@moy2010](https://discuss.elastic.co/u/moy2010)\
**Post date:** [January 25, 2018, 10:24pm UTC](https://discuss.elastic.co/t/inject-synonyms-direct-generator-in-phrase-suggester/117131/1 "2018-01-25T22:24:56Z")

</div>

Good afternoon, ES community. At the end of the [documentation for the phrase suggester](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html), is the following paragraph:

"pre\_filter and post\_filter can also be used to inject synonyms after candidates are generated. For instance for the query captain usq we might generate a candidate usa for term usq which is a synonym for america which allows to present captain america to the user if this phrase scores high enough.".

Following the given example right before paragraph, how can the direct generator be modified to inject synonyms?

I'm trying by creating an analyzer named "suggestion\_synonyms" which uses a synonym token filter and passing this analyzer in the post\_filter for the direct generatior, but with no success so far:

POST \_search  
{  
"suggest": {  
"text" : "obel prize",  
"simple\_phrase" : {  
"phrase" : {  
"field" : "title.trigram",  
"size" : 1,  
"direct\_generator" : [ {  
"field" : "title.trigram",  
"suggest\_mode" : "always"  
}, {  
"field" : "title.reverse",  
"suggest\_mode" : "always",  
"pre\_filter" : "reverse",  
"post\_filter" : "reverse"  
}, {  
"field" : "title.trigram",  
"suggest\_mode" : "always",  
"post\_filter" : "suggestion\_synonyms"  
} ]  
}  
}  
}  
}

Am I missing something in the direct\_generator and its pre and post filter's logic?

Thanks in advance for any light that you may shed on this.

---

<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:** [February 22, 2018, 10:25pm UTC](https://discuss.elastic.co/t/inject-synonyms-direct-generator-in-phrase-suggester/117131/2 "2018-02-22T22:25:27Z")

</div>

Closed on February 22, 2018, 10:25pm UTC

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