# Synonym filter not working query time?

**URL:** <https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638>\
**Category:** Elasticsearch\
**Created:** [November 8, 2012, 8:46pm UTC](https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638 "2012-11-08T20:46:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Irving](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irving/32/2834_2.png) [@Irving](https://discuss.elastic.co/u/Irving)\
**Post date:** [November 8, 2012, 8:46pm UTC](https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638/1 "2012-11-08T20:46:09Z")

</div>

Hi everyone,

I'm trying to get synonyms to work, but for some reason I'm unable to  
create the index with synonym settings (acknowledge=False) and end up with  
a cluster health state of red. The log file also doesn't show any errors.  
[2012-11-08 20:33:01,265][INFO][cluster.metadata] [Lora Danish]  
[test] creating index, cause [api], shards [5]/[1], mappings []  
[2012-11-08 20:33:01,462][DEBUG][gateway.s3] [Lora Danish]  
writing to gateway  
org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058 ...  
[2012-11-08 20:33:01,604][DEBUG][gateway.s3] [Lora Danish]  
wrote to gateway  
org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058, took 142ms

Index settings on ec2 cluster (3 nodes in cluster):  
curl -XPUT 'http://[ec2]:9200/test/' -d  
'{  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"name\_analyzer": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": ["lowercase", "stop", "snowball",  
"asciifolding", "synonym"]  
}  
},  
"filter": {  
"synonym": {  
"type": "synonym",  
"synonyms\_path": "synonyms.txt",  
"ignore\_case": "true"  
}  
}  
}  
}  
}  
}'  
{"ok":true,"acknowledged":false}

But if I take away the synonyms, I get acknowledged=True:  
curl -XPUT 'http://[ec2]:9200/test/' -d  
'{  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"name\_analyzer": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": ["lowercase", "stop", "snowball",  
"asciifolding"]  
}  
}  
}  
}  
}  
}'  
{"ok":true,"acknowledged":true}

Also, however, if I run it locally, I get acknowledged=True as well:  
curl -XPUT 'http://[ec2]:9200/test/' -d  
'{  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"name\_analyzer": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": ["lowercase", "stop", "snowball",  
"asciifolding", "synonym"]  
}  
},  
"filter": {  
"synonym": {  
"type": "synonym",  
"synonyms\_path": "synonyms.txt",  
"ignore\_case": "true"  
}  
}  
}  
}  
}  
}'  
{"ok":true,"acknowledged":true}

synonyms.txt on the ec2 master and on local  
pain head, head pain, head hurt, head throb, throb head =\> headache

Any thoughts? Thanks!  
Irving

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 14, 2012, 5:14pm UTC](https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638/2 "2012-11-14T17:14:45Z")

</div>

Where is the synonyms.txt in the filesystem? It should be relative to the  
config directory (es.path.conf).

--  
Ivan

On Thu, Nov 8, 2012 at 12:46 PM, Irving [irving@step4md.com](mailto:irving@step4md.com) wrote:

> Hi everyone,
> 
> I'm trying to get synonyms to work, but for some reason I'm unable to  
> create the index with synonym settings (acknowledge=False) and end up with  
> a cluster health state of red. The log file also doesn't show any errors.  
> [2012-11-08 20:33:01,265][INFO][cluster.metadata] [Lora Danish]  
> [test] creating index, cause [api], shards [5]/[1], mappings   
> [2012-11-08 20:33:01,462][DEBUG][gateway.s3] [Lora Danish]  
> writing to gateway  
> org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058 ...  
> [2012-11-08 20:33:01,604][DEBUG][gateway.s3] [Lora Danish]  
> wrote to gateway  
> org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058, took  
> 142ms
> 
> Index settings on ec2 cluster (3 nodes in cluster):  
> curl -XPUT 'http://[ec2]:9200/test/' -d  
> '{  
> "settings": {  
> "index": {  
> "analysis": {  
> "analyzer": {  
> "name\_analyzer": {  
> "type": "custom",  
> "tokenizer": "standard",  
> "filter": ["lowercase", "stop", "snowball",  
> "asciifolding", "synonym"]  
> }  
> },  
> "filter": {  
> "synonym": {  
> "type": "synonym",  
> "synonyms\_path": "synonyms.txt",  
> "ignore\_case": "true"  
> }  
> }  
> }  
> }  
> }  
> }'  
> {"ok":true,"acknowledged":false}
> 
> But if I take away the synonyms, I get acknowledged=True:  
> curl -XPUT 'http://[ec2]:9200/test/' -d  
> '{  
> "settings": {  
> "index": {  
> "analysis": {  
> "analyzer": {  
> "name\_analyzer": {  
> "type": "custom",  
> "tokenizer": "standard",  
> "filter": ["lowercase", "stop", "snowball",  
> "asciifolding"]  
> }  
> }  
> }  
> }  
> }  
> }'  
> {"ok":true,"acknowledged":true}
> 
> Also, however, if I run it locally, I get acknowledged=True as well:  
> curl -XPUT 'http://[ec2]:9200/test/' -d  
> '{  
> "settings": {  
> "index": {  
> "analysis": {  
> "analyzer": {  
> "name\_analyzer": {  
> "type": "custom",  
> "tokenizer": "standard",  
> "filter": ["lowercase", "stop", "snowball",  
> "asciifolding", "synonym"]  
> }  
> },  
> "filter": {  
> "synonym": {  
> "type": "synonym",  
> "synonyms\_path": "synonyms.txt",  
> "ignore\_case": "true"  
> }  
> }  
> }  
> }  
> }  
> }'  
> {"ok":true,"acknowledged":true}
> 
> synonyms.txt on the ec2 master and on local  
> pain head, head pain, head hurt, head throb, throb head =\> headache
> 
> Any thoughts? Thanks!  
> Irving
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 14, 2012, 7:52pm UTC](https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638/3 "2012-11-14T19:52:21Z")

</div>

The synonym path is getting resolved as absolute path first and then  
against config directory. So, in your case the synonyms.txt file should be  
in 'config' directory all data nodes. When it fails do you see any error  
messages in log files on other nodes?

On Wednesday, November 14, 2012 12:14:51 PM UTC-5, Ivan Brusic wrote:

> Where is the synonyms.txt in the filesystem? It should be relative to the  
> config directory (es.path.conf).
> 
> --  
> Ivan
> 
> On Thu, Nov 8, 2012 at 12:46 PM, Irving \<[irv...@step4md.com](mailto:irv...@step4md.com) \<javascript:\>\>wrote:
> 
> > Hi everyone,
> > 
> > I'm trying to get synonyms to work, but for some reason I'm unable to  
> > create the index with synonym settings (acknowledge=False) and end up with  
> > a cluster health state of red. The log file also doesn't show any errors.  
> > [2012-11-08 20:33:01,265][INFO][cluster.metadata] [Lora Danish]  
> > [test] creating index, cause [api], shards [5]/[1], mappings   
> > [2012-11-08 20:33:01,462][DEBUG][gateway.s3] [Lora Danish]  
> > writing to gateway  
> > org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058 ...  
> > [2012-11-08 20:33:01,604][DEBUG][gateway.s3] [Lora Danish]  
> > wrote to gateway  
> > org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058, took 142ms
> > 
> > Index settings on ec2 cluster (3 nodes in cluster):  
> > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > '{  
> > "settings": {  
> > "index": {  
> > "analysis": {  
> > "analyzer": {  
> > "name\_analyzer": {  
> > "type": "custom",  
> > "tokenizer": "standard",  
> > "filter": ["lowercase", "stop", "snowball",  
> > "asciifolding", "synonym"]  
> > }  
> > },  
> > "filter": {  
> > "synonym": {  
> > "type": "synonym",  
> > "synonyms\_path": "synonyms.txt",  
> > "ignore\_case": "true"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }'  
> > {"ok":true,"acknowledged":false}
> > 
> > But if I take away the synonyms, I get acknowledged=True:  
> > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > '{  
> > "settings": {  
> > "index": {  
> > "analysis": {  
> > "analyzer": {  
> > "name\_analyzer": {  
> > "type": "custom",  
> > "tokenizer": "standard",  
> > "filter": ["lowercase", "stop", "snowball",  
> > "asciifolding"]  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }'  
> > {"ok":true,"acknowledged":true}
> > 
> > Also, however, if I run it locally, I get acknowledged=True as well:  
> > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > '{  
> > "settings": {  
> > "index": {  
> > "analysis": {  
> > "analyzer": {  
> > "name\_analyzer": {  
> > "type": "custom",  
> > "tokenizer": "standard",  
> > "filter": ["lowercase", "stop", "snowball",  
> > "asciifolding", "synonym"]  
> > }  
> > },  
> > "filter": {  
> > "synonym": {  
> > "type": "synonym",  
> > "synonyms\_path": "synonyms.txt",  
> > "ignore\_case": "true"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }'  
> > {"ok":true,"acknowledged":true}
> > 
> > synonyms.txt on the ec2 master and on local  
> > pain head, head pain, head hurt, head throb, throb head =\> headache
> > 
> > Any thoughts? Thanks!  
> > Irving
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Irving\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irving_2/32/2612_2.png) [@Irving\_2](https://discuss.elastic.co/u/Irving_2)\
**Post date:** [November 16, 2012, 1:20am UTC](https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638/4 "2012-11-16T01:20:48Z")

</div>

Ah, the synonym file was in the config directory of only the master, but  
not in the rest of the data nodes. That solved it, thanks!

As a follow up question related more to the original prompt title, why  
isn't the synonym filter applied to the supplied query? The analyzer for  
synonyms only seem to be applied during index time, but when I apply the  
analyzer to the query, it doesn't seem to work.  
index settings as in previous post  
synonyms.txt: pain head, head pain, head hurt, head throb, throb head =\>headach

curl -XPUT [http://localhost:9200/test/items/\_mapping](http://localhost:9200/test/items/_mapping) -d  
'{  
"items": {  
"properties": {  
"name": {  
"type": "string",  
"analyzer": "name\_analyzer"  
}  
}  
}  
}'  
{"ok":true,"acknowledged":true}

Indexing some documents:  
curl -XPUT [http://localhost:9200/test/items/1](http://localhost:9200/test/items/1) -d '{ "name": "headache" }'  
{"ok":true,"\_index":"test2","\_type":"items","\_id":"1","\_version":1}  
curl -XPUT [http://localhost:9200/test/items/2](http://localhost:9200/test/items/2) -d '{ "name": "back pain" }'  
{"ok":true,"\_index":"test2","\_type":"items","\_id":"2","\_version":1}  
curl -XPUT [http://localhost:9200/test/items/3](http://localhost:9200/test/items/3) -d '{ "name": "head hurts" }'  
{"ok":true,"\_index":"test2","\_type":"items","\_id":"3","\_version":1}

The analyzer looks fine:  
curl -XGET [http://localhost:9200/test/\_analyze?analyzer=name\_analyzer](http://localhost:9200/test/_analyze?analyzer=name_analyzer) -d  
"head hurts"  
{"tokens":[{"token":"headach","start\_offset":0,"end\_offset":10,"type":  
"SYNONYM","position":1}]}

A normal query for a synonym term works as expected since the documents  
have the synonym filter applied during index time:  
curl -XGET [http://localhost:9200/test/items/\_search](http://localhost:9200/test/items/_search) -d  
'{  
"query": {  
"query\_string": {  
"query":"headaches",  
"analyzer":"name\_analyzer",  
"default\_field":"name"  
}  
}  
}'  
{"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},  
"hits":{"total":2,"max\_score":0.30685282,"hits":[{"\_index":"test2","\_type":  
"items","\_id":"1","\_score":0.30685282, "\_source" : { "name": "headache" }},{  
"\_index":"test2","\_type":"items","\_id":"3","\_score":0.30685282, "\_source" :  
{ "name": "head hurts" }}]}}

But then this query doesn't work as expected. Why wouldn't it map the query  
"head hurts" to the synonym "headach"?  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

- query time synonym filter doesn't work? \*  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
curl -XGET [http://localhost:9200/test/items/\_search](http://localhost:9200/test/items/_search) -d  
'{  
"query": {  
"query\_string": {  
"query":"head hurts",  
"analyzer":"name\_analyzer",  
"default\_field":"name"  
}  
}  
}'  
{"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},  
"hits":{"total":0,"max\_score":null,"hits":}}

Thanks!  
Irving

On Wednesday, November 14, 2012 11:52:21 AM UTC-8, Igor Motov wrote:

> The synonym path is getting resolved as absolute path first and then  
> against config directory. So, in your case the synonyms.txt file should be  
> in 'config' directory all data nodes. When it fails do you see any error  
> messages in log files on other nodes?
> 
> On Wednesday, November 14, 2012 12:14:51 PM UTC-5, Ivan Brusic wrote:
> 
> > Where is the synonyms.txt in the filesystem? It should be relative to the  
> > config directory (es.path.conf).
> > 
> > --  
> > Ivan
> > 
> > On Thu, Nov 8, 2012 at 12:46 PM, Irving [irv...@step4md.com](mailto:irv...@step4md.com) wrote:
> > 
> > > Hi everyone,
> > > 
> > > I'm trying to get synonyms to work, but for some reason I'm unable to  
> > > create the index with synonym settings (acknowledge=False) and end up with  
> > > a cluster health state of red. The log file also doesn't show any errors.  
> > > [2012-11-08 20:33:01,265][INFO][cluster.metadata] [Lora  
> > > Danish] [test] creating index, cause [api], shards [5]/[1], mappings   
> > > [2012-11-08 20:33:01,462][DEBUG][gateway.s3] [Lora  
> > > Danish] writing to gateway  
> > > org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058 ...  
> > > [2012-11-08 20:33:01,604][DEBUG][gateway.s3] [Lora  
> > > Danish] wrote to gateway  
> > > org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058, took 142ms
> > > 
> > > Index settings on ec2 cluster (3 nodes in cluster):  
> > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > '{  
> > > "settings": {  
> > > "index": {  
> > > "analysis": {  
> > > "analyzer": {  
> > > "name\_analyzer": {  
> > > "type": "custom",  
> > > "tokenizer": "standard",  
> > > "filter": ["lowercase", "stop", "snowball",  
> > > "asciifolding", "synonym"]  
> > > }  
> > > },  
> > > "filter": {  
> > > "synonym": {  
> > > "type": "synonym",  
> > > "synonyms\_path": "synonyms.txt",  
> > > "ignore\_case": "true"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }'  
> > > {"ok":true,"acknowledged":false}
> > > 
> > > But if I take away the synonyms, I get acknowledged=True:  
> > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > '{  
> > > "settings": {  
> > > "index": {  
> > > "analysis": {  
> > > "analyzer": {  
> > > "name\_analyzer": {  
> > > "type": "custom",  
> > > "tokenizer": "standard",  
> > > "filter": ["lowercase", "stop", "snowball",  
> > > "asciifolding"]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }'  
> > > {"ok":true,"acknowledged":true}
> > > 
> > > Also, however, if I run it locally, I get acknowledged=True as well:  
> > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > '{  
> > > "settings": {  
> > > "index": {  
> > > "analysis": {  
> > > "analyzer": {  
> > > "name\_analyzer": {  
> > > "type": "custom",  
> > > "tokenizer": "standard",  
> > > "filter": ["lowercase", "stop", "snowball",  
> > > "asciifolding", "synonym"]  
> > > }  
> > > },  
> > > "filter": {  
> > > "synonym": {  
> > > "type": "synonym",  
> > > "synonyms\_path": "synonyms.txt",  
> > > "ignore\_case": "true"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }'  
> > > {"ok":true,"acknowledged":true}
> > > 
> > > synonyms.txt on the ec2 master and on local  
> > > pain head, head pain, head hurt, head throb, throb head =\> headache
> > > 
> > > Any thoughts? Thanks!  
> > > Irving
> > > 
> > > --

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 16, 2012, 1:31am UTC](https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638/5 "2012-11-16T01:31:49Z")

</div>

That's because query\_string parses the query before it reaches the  
analyzer. The query\_string parser basically looks at the query and splits  
it into two clauses "head" and "hurts" first and only then sends each  
clause individually through analyzer. If you don't care about handling full  
lucene query syntax, you can use the match query instead.

On Thursday, November 15, 2012 8:20:48 PM UTC-5, Irving wrote:

> Ah, the synonym file was in the config directory of only the master, but  
> not in the rest of the data nodes. That solved it, thanks!
> 
> As a follow up question related more to the original prompt title, why  
> isn't the synonym filter applied to the supplied query? The analyzer for  
> synonyms only seem to be applied during index time, but when I apply the  
> analyzer to the query, it doesn't seem to work.  
> index settings as in previous post  
> synonyms.txt: pain head, head pain, head hurt, head throb, throb head =\>headach
> 
> curl -XPUT [http://localhost:9200/test/items/\_mapping](http://localhost:9200/test/items/_mapping) -d  
> '{  
> "items": {  
> "properties": {  
> "name": {  
> "type": "string",  
> "analyzer": "name\_analyzer"  
> }  
> }  
> }  
> }'  
> {"ok":true,"acknowledged":true}
> 
> Indexing some documents:  
> curl -XPUT [http://localhost:9200/test/items/1](http://localhost:9200/test/items/1) -d '{ "name": "headache" }'  
> {"ok":true,"\_index":"test2","\_type":"items","\_id":"1","\_version":1}  
> curl -XPUT [http://localhost:9200/test/items/2](http://localhost:9200/test/items/2) -d '{ "name": "back pain" }'  
> {"ok":true,"\_index":"test2","\_type":"items","\_id":"2","\_version":1}  
> curl -XPUT [http://localhost:9200/test/items/3](http://localhost:9200/test/items/3) -d '{ "name": "head hurts"  
> }'  
> {"ok":true,"\_index":"test2","\_type":"items","\_id":"3","\_version":1}
> 
> The analyzer looks fine:  
> curl -XGET [http://localhost:9200/test/\_analyze?analyzer=name\_analyzer](http://localhost:9200/test/_analyze?analyzer=name_analyzer) -d  
> "head hurts"  
> {"tokens":[{"token":"headach","start\_offset":0,"end\_offset":10,"type":  
> "SYNONYM","position":1}]}
> 
> A normal query for a synonym term works as expected since the documents  
> have the synonym filter applied during index time:  
> curl -XGET [http://localhost:9200/test/items/\_search](http://localhost:9200/test/items/_search) -d  
> '{  
> "query": {  
> "query\_string": {  
> "query":"headaches",  
> "analyzer":"name\_analyzer",  
> "default\_field":"name"  
> }  
> }  
> }'  
> {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0  
> },"hits":{"total":2,"max\_score":0.30685282,"hits":[{"\_index":"test2",  
> "\_type":"items","\_id":"1","\_score":0.30685282, "\_source" : { "name":  
> "headache" }},{"\_index":"test2","\_type":"items","\_id":"3","\_score":  
> 0.30685282, "\_source" : { "name": "head hurts" }}]}}
> 
> But then this query doesn't work as expected. Why wouldn't it map the  
> query "head hurts" to the synonym "headach"?  
> /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> - query time synonym filter doesn't work? \*  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
> curl -XGET [http://localhost:9200/test/items/\_search](http://localhost:9200/test/items/_search) -d  
> '{  
> "query": {  
> "query\_string": {  
> "query":"head hurts",  
> "analyzer":"name\_analyzer",  
> "default\_field":"name"  
> }  
> }  
> }'  
> {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0  
> },"hits":{"total":0,"max\_score":null,"hits":}}
> 
> Thanks!  
> Irving
> 
> On Wednesday, November 14, 2012 11:52:21 AM UTC-8, Igor Motov wrote:
> 
> > The synonym path is getting resolved as absolute path first and then  
> > against config directory. So, in your case the synonyms.txt file should be  
> > in 'config' directory all data nodes. When it fails do you see any error  
> > messages in log files on other nodes?
> > 
> > On Wednesday, November 14, 2012 12:14:51 PM UTC-5, Ivan Brusic wrote:
> > 
> > > Where is the synonyms.txt in the filesystem? It should be relative to  
> > > the config directory (es.path.conf).
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Thu, Nov 8, 2012 at 12:46 PM, Irving [irv...@step4md.com](mailto:irv...@step4md.com) wrote:
> > > 
> > > > Hi everyone,
> > > > 
> > > > I'm trying to get synonyms to work, but for some reason I'm unable to  
> > > > create the index with synonym settings (acknowledge=False) and end up with  
> > > > a cluster health state of red. The log file also doesn't show any errors.  
> > > > [2012-11-08 20:33:01,265][INFO][cluster.metadata] [Lora  
> > > > Danish] [test] creating index, cause [api], shards [5]/[1], mappings   
> > > > [2012-11-08 20:33:01,462][DEBUG][gateway.s3] [Lora  
> > > > Danish] writing to gateway  
> > > > org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058 ...  
> > > > [2012-11-08 20:33:01,604][DEBUG][gateway.s3] [Lora  
> > > > Danish] wrote to gateway  
> > > > org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058, took 142ms
> > > > 
> > > > Index settings on ec2 cluster (3 nodes in cluster):  
> > > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > > '{  
> > > > "settings": {  
> > > > "index": {  
> > > > "analysis": {  
> > > > "analyzer": {  
> > > > "name\_analyzer": {  
> > > > "type": "custom",  
> > > > "tokenizer": "standard",  
> > > > "filter": ["lowercase", "stop", "snowball",  
> > > > "asciifolding", "synonym"]  
> > > > }  
> > > > },  
> > > > "filter": {  
> > > > "synonym": {  
> > > > "type": "synonym",  
> > > > "synonyms\_path": "synonyms.txt",  
> > > > "ignore\_case": "true"  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }'  
> > > > {"ok":true,"acknowledged":false}
> > > > 
> > > > But if I take away the synonyms, I get acknowledged=True:  
> > > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > > '{  
> > > > "settings": {  
> > > > "index": {  
> > > > "analysis": {  
> > > > "analyzer": {  
> > > > "name\_analyzer": {  
> > > > "type": "custom",  
> > > > "tokenizer": "standard",  
> > > > "filter": ["lowercase", "stop", "snowball",  
> > > > "asciifolding"]  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }'  
> > > > {"ok":true,"acknowledged":true}
> > > > 
> > > > Also, however, if I run it locally, I get acknowledged=True as well:  
> > > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > > '{  
> > > > "settings": {  
> > > > "index": {  
> > > > "analysis": {  
> > > > "analyzer": {  
> > > > "name\_analyzer": {  
> > > > "type": "custom",  
> > > > "tokenizer": "standard",  
> > > > "filter": ["lowercase", "stop", "snowball",  
> > > > "asciifolding", "synonym"]  
> > > > }  
> > > > },  
> > > > "filter": {  
> > > > "synonym": {  
> > > > "type": "synonym",  
> > > > "synonyms\_path": "synonyms.txt",  
> > > > "ignore\_case": "true"  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }'  
> > > > {"ok":true,"acknowledged":true}
> > > > 
> > > > synonyms.txt on the ec2 master and on local  
> > > > pain head, head pain, head hurt, head throb, throb head =\> headache
> > > > 
> > > > Any thoughts? Thanks!  
> > > > Irving
> > > > 
> > > > --

--

---

<div class="post-metadata">

**Author:** ![Irving\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irving_2/32/2612_2.png) [@Irving\_2](https://discuss.elastic.co/u/Irving_2)\
**Post date:** [November 16, 2012, 11:31pm UTC](https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638/6 "2012-11-16T23:31:50Z")

</div>

That makes sense now. Thanks, I'll give match query a try and see if it  
suits our purposes.

On Thursday, November 15, 2012 5:31:49 PM UTC-8, Igor Motov wrote:

> That's because query\_string parses the query before it reaches the  
> analyzer. The query\_string parser basically looks at the query and splits  
> it into two clauses "head" and "hurts" first and only then sends each  
> clause individually through analyzer. If you don't care about handling full  
> lucene query syntax, you can use the match query instead.
> 
> On Thursday, November 15, 2012 8:20:48 PM UTC-5, Irving wrote:
> 
> > Ah, the synonym file was in the config directory of only the master, but  
> > not in the rest of the data nodes. That solved it, thanks!
> > 
> > As a follow up question related more to the original prompt title, why  
> > isn't the synonym filter applied to the supplied query? The analyzer for  
> > synonyms only seem to be applied during index time, but when I apply the  
> > analyzer to the query, it doesn't seem to work.  
> > index settings as in previous post  
> > synonyms.txt: pain head, head pain, head hurt, head throb, throb head =\>headach
> > 
> > curl -XPUT [http://localhost:9200/test/items/\_mapping](http://localhost:9200/test/items/_mapping) -d  
> > '{  
> > "items": {  
> > "properties": {  
> > "name": {  
> > "type": "string",  
> > "analyzer": "name\_analyzer"  
> > }  
> > }  
> > }  
> > }'  
> > {"ok":true,"acknowledged":true}
> > 
> > Indexing some documents:  
> > curl -XPUT [http://localhost:9200/test/items/1](http://localhost:9200/test/items/1) -d '{ "name": "headache" }'  
> > {"ok":true,"\_index":"test2","\_type":"items","\_id":"1","\_version":1}  
> > curl -XPUT [http://localhost:9200/test/items/2](http://localhost:9200/test/items/2) -d '{ "name": "back pain"  
> > }'  
> > {"ok":true,"\_index":"test2","\_type":"items","\_id":"2","\_version":1}  
> > curl -XPUT [http://localhost:9200/test/items/3](http://localhost:9200/test/items/3) -d '{ "name": "head hurts"  
> > }'  
> > {"ok":true,"\_index":"test2","\_type":"items","\_id":"3","\_version":1}
> > 
> > The analyzer looks fine:  
> > curl -XGET [http://localhost:9200/test/\_analyze?analyzer=name\_analyzer](http://localhost:9200/test/_analyze?analyzer=name_analyzer) -d  
> > "head hurts"  
> > {"tokens":[{"token":"headach","start\_offset":0,"end\_offset":10,"type":  
> > "SYNONYM","position":1}]}
> > 
> > A normal query for a synonym term works as expected since the documents  
> > have the synonym filter applied during index time:  
> > curl -XGET [http://localhost:9200/test/items/\_search](http://localhost:9200/test/items/_search) -d  
> > '{  
> > "query": {  
> > "query\_string": {  
> > "query":"headaches",  
> > "analyzer":"name\_analyzer",  
> > "default\_field":"name"  
> > }  
> > }  
> > }'  
> > {"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":  
> > 0},"hits":{"total":2,"max\_score":0.30685282,"hits":[{"\_index":"test2",  
> > "\_type":"items","\_id":"1","\_score":0.30685282, "\_source" : { "name":  
> > "headache" }},{"\_index":"test2","\_type":"items","\_id":"3","\_score":  
> > 0.30685282, "\_source" : { "name": "head hurts" }}]}}
> > 
> > But then this query doesn't work as expected. Why wouldn't it map the  
> > query "head hurts" to the synonym "headach"?  
> > /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> > 
> > - query time synonym filter doesn't work? \*  
> > \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
> > curl -XGET [http://localhost:9200/test/items/\_search](http://localhost:9200/test/items/_search) -d  
> > '{  
> > "query": {  
> > "query\_string": {  
> > "query":"head hurts",  
> > "analyzer":"name\_analyzer",  
> > "default\_field":"name"  
> > }  
> > }  
> > }'  
> > {"took":1,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":  
> > 0},"hits":{"total":0,"max\_score":null,"hits":}}
> > 
> > Thanks!  
> > Irving
> > 
> > On Wednesday, November 14, 2012 11:52:21 AM UTC-8, Igor Motov wrote:
> > 
> > > The synonym path is getting resolved as absolute path first and then  
> > > against config directory. So, in your case the synonyms.txt file should be  
> > > in 'config' directory all data nodes. When it fails do you see any error  
> > > messages in log files on other nodes?
> > > 
> > > On Wednesday, November 14, 2012 12:14:51 PM UTC-5, Ivan Brusic wrote:
> > > 
> > > > Where is the synonyms.txt in the filesystem? It should be relative to  
> > > > the config directory (es.path.conf).
> > > > 
> > > > --  
> > > > Ivan
> > > > 
> > > > On Thu, Nov 8, 2012 at 12:46 PM, Irving [irv...@step4md.com](mailto:irv...@step4md.com) wrote:
> > > > 
> > > > > Hi everyone,
> > > > > 
> > > > > I'm trying to get synonyms to work, but for some reason I'm unable to  
> > > > > create the index with synonym settings (acknowledge=False) and end up with  
> > > > > a cluster health state of red. The log file also doesn't show any errors.  
> > > > > [2012-11-08 20:33:01,265][INFO][cluster.metadata] [Lora  
> > > > > Danish] [test] creating index, cause [api], shards [5]/[1], mappings   
> > > > > [2012-11-08 20:33:01,462][DEBUG][gateway.s3] [Lora  
> > > > > Danish] writing to gateway  
> > > > > org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058 ...  
> > > > > [2012-11-08 20:33:01,604][DEBUG][gateway.s3] [Lora  
> > > > > Danish] wrote to gateway  
> > > > > org.elasticsearch.gateway.shared.SharedStorageGateway$2@aeb7058, took 142ms
> > > > > 
> > > > > Index settings on ec2 cluster (3 nodes in cluster):  
> > > > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > > > '{  
> > > > > "settings": {  
> > > > > "index": {  
> > > > > "analysis": {  
> > > > > "analyzer": {  
> > > > > "name\_analyzer": {  
> > > > > "type": "custom",  
> > > > > "tokenizer": "standard",  
> > > > > "filter": ["lowercase", "stop", "snowball",  
> > > > > "asciifolding", "synonym"]  
> > > > > }  
> > > > > },  
> > > > > "filter": {  
> > > > > "synonym": {  
> > > > > "type": "synonym",  
> > > > > "synonyms\_path": "synonyms.txt",  
> > > > > "ignore\_case": "true"  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }'  
> > > > > {"ok":true,"acknowledged":false}
> > > > > 
> > > > > But if I take away the synonyms, I get acknowledged=True:  
> > > > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > > > '{  
> > > > > "settings": {  
> > > > > "index": {  
> > > > > "analysis": {  
> > > > > "analyzer": {  
> > > > > "name\_analyzer": {  
> > > > > "type": "custom",  
> > > > > "tokenizer": "standard",  
> > > > > "filter": ["lowercase", "stop", "snowball",  
> > > > > "asciifolding"]  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }'  
> > > > > {"ok":true,"acknowledged":true}
> > > > > 
> > > > > Also, however, if I run it locally, I get acknowledged=True as well:  
> > > > > curl -XPUT 'http://[ec2]:9200/test/' -d  
> > > > > '{  
> > > > > "settings": {  
> > > > > "index": {  
> > > > > "analysis": {  
> > > > > "analyzer": {  
> > > > > "name\_analyzer": {  
> > > > > "type": "custom",  
> > > > > "tokenizer": "standard",  
> > > > > "filter": ["lowercase", "stop", "snowball",  
> > > > > "asciifolding", "synonym"]  
> > > > > }  
> > > > > },  
> > > > > "filter": {  
> > > > > "synonym": {  
> > > > > "type": "synonym",  
> > > > > "synonyms\_path": "synonyms.txt",  
> > > > > "ignore\_case": "true"  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }'  
> > > > > {"ok":true,"acknowledged":true}
> > > > > 
> > > > > synonyms.txt on the ec2 master and on local  
> > > > > pain head, head pain, head hurt, head throb, throb head =\> headache
> > > > > 
> > > > > Any thoughts? Thanks!  
> > > > > Irving
> > > > > 
> > > > > --

--

---

<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, 3:03am UTC](https://discuss.elastic.co/t/synonym-filter-not-working-query-time/9638/7 "2017-07-06T03:03:55Z")

</div>


