# Synonyms and prefix query

**URL:** <https://discuss.elastic.co/t/synonyms-and-prefix-query/11352>\
**Category:** Elasticsearch\
**Created:** [March 28, 2013, 12:16pm UTC](https://discuss.elastic.co/t/synonyms-and-prefix-query/11352 "2013-03-28T12:16:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fadel\_Chafai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fadel_chafai/32/1105_2.png) [@Fadel\_Chafai](https://discuss.elastic.co/u/Fadel_Chafai)\
**Post date:** [March 28, 2013, 12:16pm UTC](https://discuss.elastic.co/t/synonyms-and-prefix-query/11352/1 "2013-03-28T12:16:30Z")

</div>

hi

how i can combine a prefix query and a synonyme filter ?

this is my query :

{  
"query": {  
"query\_string": {  
"query": "samsung",  
"analyzer": "synonym",  
"fields": [  
"name\_fr.name\_fr",  
"name\_fr.whitespace",  
"name\_fr.edge\_ngram\_front",  
"name\_fr.edge\_ngram\_back",  
"name\_fr.shingle",  
"name\_fr.shingle\_strip\_ws",  
"name\_fr.shingle\_strip\_apos\_and\_ws",  
"name\_fr.analyzer\_fr",  
"manufacturer",  
"description\_fr.description\_fr",  
"description\_fr.synonym",  
"description\_fr.whitespace",  
"description\_fr.edge\_ngram\_front",  
"description\_fr.edge\_ngram\_back",  
"description\_fr.shingle",  
"description\_fr.shingle\_strip\_ws",  
"description\_fr.shingle\_strip\_apos\_and\_ws",  
"description\_fr.analyzer\_fr",  
]  
}  
},  
"min\_score": 0.2,  
"size": 8,  
"filter": {  
"synonym": {  
"type": "synonym"  
},  
"and": [  
{  
"prefix": {  
"name\_fr.shingle\_strip\_ws": "samsung"  
}  
},  
{  
"query": {  
"query\_string": {  
"query": "_exists_:type\_products\_fr"  
}  
}  
}  
]  
}  
}

but I have an exception

nested: QueryParsingException[[magento] No filter registered for [synonym]];

thank you

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 28, 2013, 1:22pm UTC](https://discuss.elastic.co/t/synonyms-and-prefix-query/11352/2 "2013-03-28T13:22:30Z")

</div>

Hey,

The exception you are getting, is actually telling the truth a bit, however  
it is pretty hard to extract useful information out of it.

You are trying to use the synonym feature on query time, but this is not  
possible. The synonym feature is a tokenfilter and has to be configured,  
before you start indexing your documents. It is not to be used on query  
time at all.

Consider this example:

curl -X DELETE 'localhost:9200/mytest'  
curl -XPUT 'localhost:9200/mytest' -d '{  
"settings" : {  
"analysis" : {  
"analyzer" : {  
"my\_analyzer" : {  
"tokenizer" : "standard",  
"filter" : ["lowercase", "your\_synonym\_filter"]  
}  
},  
"filter" : {  
"your\_synonym\_filter" : {  
"type" : "synonym",  
"synonyms" : [  
"foo, bar"  
]  
}  
}  
}  
}  
}'

curl -X PUT localhost:9200/mytest/sometype/\_mapping -d ' { "sometype" : {  
"properties" : { "name" : { "type" : "string", "analyzer":"my\_analyzer"} }  
} }'

curl -X PUT localhost:9200/mytest/sometype/1 -d '{ "name" : "what a  
wonderful bar" }'

curl -X POST localhost:9200/mytest/sometype/\_search -d '{ "query" : {  
"match" : { "name" : "bar" } } }'  
curl -X POST localhost:9200/mytest/sometype/\_search -d '{ "query" : {  
"match" : { "name" : "foo" } } }'

When configuring the synonym filter in your index configuration, you can  
search either for foo or bar and the indexed document will be returned in  
both queries.

Hope this helps...

On Thu, Mar 28, 2013 at 1:16 PM, Fadel Chafai [fadelmohamed@gmail.com](mailto:fadelmohamed@gmail.com)wrote:

> hi
> 
> how i can combine a prefix query and a synonyme filter ?
> 
> this is my query :
> 
> {  
> "query": {  
> "query\_string": {  
> "query": "samsung",  
> "analyzer": "synonym",  
> "fields": [  
> "name\_fr.name\_fr",  
> "name\_fr.whitespace",  
> "name\_fr.edge\_ngram\_front",  
> "name\_fr.edge\_ngram\_back",  
> "name\_fr.shingle",  
> "name\_fr.shingle\_strip\_ws",  
> "name\_fr.shingle\_strip\_apos\_and\_ws",  
> "name\_fr.analyzer\_fr",  
> "manufacturer",  
> "description\_fr.description\_fr",  
> "description\_fr.synonym",  
> "description\_fr.whitespace",  
> "description\_fr.edge\_ngram\_front",  
> "description\_fr.edge\_ngram\_back",  
> "description\_fr.shingle",  
> "description\_fr.shingle\_strip\_ws",  
> "description\_fr.shingle\_strip\_apos\_and\_ws",  
> "description\_fr.analyzer\_fr",  
> ]  
> }  
> },  
> "min\_score": 0.2,  
> "size": 8,  
> "filter": {  
> "synonym": {  
> "type": "synonym"  
> },  
> "and": [  
> {  
> "prefix": {  
> "name\_fr.shingle\_strip\_ws": "samsung"  
> }  
> },  
> {  
> "query": {  
> "query\_string": {  
> "query": "_exists_:type\_products\_fr"  
> }  
> }  
> }  
> ]  
> }  
> }
> 
> but I have an exception
> 
> nested: QueryParsingException[[magento] No filter registered for  
> [synonym]];
> 
> thank you
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Fadel\_Chafai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fadel_chafai/32/1105_2.png) [@Fadel\_Chafai](https://discuss.elastic.co/u/Fadel_Chafai)\
**Post date:** [March 29, 2013, 8:36am UTC](https://discuss.elastic.co/t/synonyms-and-prefix-query/11352/3 "2013-03-29T08:36:03Z")

</div>

hi alexander,

yes i configured synonyms before indexing this is my settings :

- index.analysis.analyzer.synonym.tokenizer: whitespace
- index.analysis.analyzer.edge\_ngram\_back.tokenizer: standard
- index.analysis.filter.shingle.output\_unigrams: true
- index.analysis.analyzer.shingle\_strip\_apos\_and\_ws.filter.3: length
- index.analysis.analyzer.shingle\_strip\_apos\_and\_ws.filter.2:  
strip\_whitespaces
- index.analysis.filter.snowball\_fr.type: snowball
- index.analysis.analyzer.shingle\_strip\_apos\_and\_ws.filter.4: lowercase
- index.analysis.filter.shingle.type: shingle
- index.analysis.filter.strip\_whitespaces.type: pattern\_replace
- index.analysis.analyzer.shingle\_strip\_apos\_and\_ws.filter.1:  
strip\_apostrophes
- index.analysis.analyzer.shingle\_strip\_apos\_and\_ws.filter.0: shingle
- index.analysis.filter.edge\_ngram\_front.min\_gram: 2
- index.analysis.filter.edge\_ngram\_back.side: back
- index.analysis.filter.length.min: 2
- index.analysis.filter.strip\_apostrophes.replacement:
- index.analysis.filter.strip\_whitespaces.pattern: \s
- index.analysis.filter.edge\_ngram\_front.max\_gram: 10
- index.analysis.analyzer.shingle\_strip\_ws.tokenizer: standard
- index.analysis.analyzer.edge\_ngram\_front.tokenizer: standard
- index.analysis.analyzer.edge\_ngram\_back.filter.1: edge\_ngram\_back
- index.analysis.analyzer.edge\_ngram\_back.filter.2: lowercase
- index.analysis.analyzer.edge\_ngram\_back.filter.0: length
- index.number\_of\_shards: 1
- index.analysis.filter.length.type: length
- index.analysis.filter.strip\_apostrophes.pattern: '
- index.analysis.analyzer.synonym.filter.0: synonym
- index.analysis.analyzer.shingle.filter.2: lowercase
- index.analysis.analyzer.shingle.filter.0: shingle
- index.analysis.filter.shingle.max\_shingle\_size: 20
- index.analysis.analyzer.shingle.filter.1: length
- index.analysis.filter.edge\_ngram\_back.max\_gram: 10
- index.analysis.analyzer.edge\_ngram\_front.filter.0: length
- index.analysis.filter.synonym.synonyms\_path: analysis/synonym.txt
- index.analysis.analyzer.edge\_ngram\_front.filter.1: edge\_ngram\_front
- index.analysis.analyzer.analyzer\_fr.tokenizer: standard
- index.analysis.analyzer.edge\_ngram\_front.filter.2: lowercase
- index.version.created: 191099
- index.analysis.analyzer.whitespace.tokenizer: standard
- index.analysis.analyzer.shingle.tokenizer: standard
- index.analysis.filter.snowball\_fr.language: French
- index.analysis.analyzer.whitespace.filter.0: lowercase
- index.number\_of\_replicas: 1
- index.analysis.analyzer.analyzer\_fr.type: custom
- index.analysis.filter.edge\_ngram\_front.type: edgeNGram
- index.analysis.analyzer.shingle\_strip\_apos\_and\_ws.tokenizer: standard
- index.analysis.filter.synonym.type: synonym
- index.analysis.filter.strip\_apostrophes.type: pattern\_replace
- index.analysis.filter.edge\_ngram\_back.type: edgeNGram
- index.analysis.analyzer.shingle\_strip\_ws.filter.3: lowercase
- index.analysis.analyzer.shingle\_strip\_ws.filter.2: length
- index.analysis.analyzer.shingle\_strip\_ws.filter.1: strip\_whitespaces
- index.analysis.analyzer.analyzer\_fr.filter.0: length
- index.analysis.analyzer.shingle\_strip\_ws.filter.0: shingle
- index.analysis.filter.strip\_whitespaces.replacement:
- index.analysis.analyzer.analyzer\_fr.filter.1: lowercase
- index.analysis.filter.edge\_ngram\_front.side: front
- index.analysis.analyzer.analyzer\_fr.filter.2: snowball\_fr
- index.analysis.filter.edge\_ngram\_back.min\_gram: 2

thank you

On Thursday, March 28, 2013 12:16:30 PM UTC, Fadel Chafai wrote:

> hi
> 
> how i can combine a prefix query and a synonyme filter ?
> 
> this is my query :
> 
> {  
> "query": {  
> "query\_string": {  
> "query": "samsung",  
> "analyzer": "synonym",  
> "fields": [  
> "name\_fr.name\_fr",  
> "name\_fr.whitespace",  
> "name\_fr.edge\_ngram\_front",  
> "name\_fr.edge\_ngram\_back",  
> "name\_fr.shingle",  
> "name\_fr.shingle\_strip\_ws",  
> "name\_fr.shingle\_strip\_apos\_and\_ws",  
> "name\_fr.analyzer\_fr",  
> "manufacturer",  
> "description\_fr.description\_fr",  
> "description\_fr.synonym",  
> "description\_fr.whitespace",  
> "description\_fr.edge\_ngram\_front",  
> "description\_fr.edge\_ngram\_back",  
> "description\_fr.shingle",  
> "description\_fr.shingle\_strip\_ws",  
> "description\_fr.shingle\_strip\_apos\_and\_ws",  
> "description\_fr.analyzer\_fr",  
> ]  
> }  
> },  
> "min\_score": 0.2,  
> "size": 8,  
> "filter": {  
> "synonym": {  
> "type": "synonym"  
> },  
> "and": [  
> {  
> "prefix": {  
> "name\_fr.shingle\_strip\_ws": "samsung"  
> }  
> },  
> {  
> "query": {  
> "query\_string": {  
> "query": "_exists_:type\_products\_fr"  
> }  
> }  
> }  
> ]  
> }  
> }
> 
> but I have an exception
> 
> nested: QueryParsingException[[magento] No filter registered for  
> [synonym]];
> 
> thank you

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Fadel\_Chafai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fadel_chafai/32/1105_2.png) [@Fadel\_Chafai](https://discuss.elastic.co/u/Fadel_Chafai)\
**Post date:** [March 29, 2013, 8:58am UTC](https://discuss.elastic.co/t/synonyms-and-prefix-query/11352/4 "2013-03-29T08:58:45Z")

</div>

this query works fine 🙂

{  
"query": {  
"query\_string": {  
"query": "nabili",  
"analyzer": "synonym",  
"fields": [  
"name\_fr.name\_fr",  
"name\_fr.whitespace",  
"name\_fr.edge\_ngram\_front",  
"name\_fr.edge\_ngram\_back",  
"name\_fr.shingle",  
"name\_fr.shingle\_strip\_ws",  
"name\_fr.shingle\_strip\_apos\_and\_ws",  
"name\_fr.analyzer\_fr",  
"manufacturer",  
"description\_fr.description\_fr",  
"description\_fr.synonym",  
"description\_fr.whitespace",  
"description\_fr.edge\_ngram\_front",  
"description\_fr.edge\_ngram\_back",  
"description\_fr.shingle",  
"description\_fr.shingle\_strip\_ws",  
"description\_fr.shingle\_strip\_apos\_and\_ws",  
"description\_fr.analyzer\_fr",  
"isbn\_fr",  
"manufacturer\_facet",  
"article\_code\_manufacturer",  
"ean",  
"book\_author"  
]  
}  
},  
"min\_score": 0.2,  
"size": 8,  
"filter": {  
"and": [  
{  
"query": {  
"query\_string": {  
"query": "_exists_:type\_products\_fr"  
}  
}  
}  
]  
}  
}

so the problem is with the prefix filter ☹

On Thursday, March 28, 2013 12:16:30 PM UTC, Fadel Chafai wrote:

> hi
> 
> how i can combine a prefix query and a synonyme filter ?
> 
> this is my query :
> 
> {  
> "query": {  
> "query\_string": {  
> "query": "samsung",  
> "analyzer": "synonym",  
> "fields": [  
> "name\_fr.name\_fr",  
> "name\_fr.whitespace",  
> "name\_fr.edge\_ngram\_front",  
> "name\_fr.edge\_ngram\_back",  
> "name\_fr.shingle",  
> "name\_fr.shingle\_strip\_ws",  
> "name\_fr.shingle\_strip\_apos\_and\_ws",  
> "name\_fr.analyzer\_fr",  
> "manufacturer",  
> "description\_fr.description\_fr",  
> "description\_fr.synonym",  
> "description\_fr.whitespace",  
> "description\_fr.edge\_ngram\_front",  
> "description\_fr.edge\_ngram\_back",  
> "description\_fr.shingle",  
> "description\_fr.shingle\_strip\_ws",  
> "description\_fr.shingle\_strip\_apos\_and\_ws",  
> "description\_fr.analyzer\_fr",  
> ]  
> }  
> },  
> "min\_score": 0.2,  
> "size": 8,  
> "filter": {  
> "synonym": {  
> "type": "synonym"  
> },  
> "and": [  
> {  
> "prefix": {  
> "name\_fr.shingle\_strip\_ws": "samsung"  
> }  
> },  
> {  
> "query": {  
> "query\_string": {  
> "query": "_exists_:type\_products\_fr"  
> }  
> }  
> }  
> ]  
> }  
> }
> 
> but I have an exception
> 
> nested: QueryParsingException[[magento] No filter registered for  
> [synonym]];
> 
> thank you

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:43am UTC](https://discuss.elastic.co/t/synonyms-and-prefix-query/11352/5 "2017-07-06T02:43:43Z")

</div>


