# Synonyms in synonyms.txt not recognized

**URL:** <https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417>\
**Category:** Elasticsearch\
**Created:** [December 28, 2017, 8:49am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417 "2017-12-28T08:49:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 8:49am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/1 "2017-12-28T08:49:08Z")

</div>

I have created a synonyms.txt file as in [Synonym token filter | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html) .

Synonyms.txt contains :  
i-pod, i pod =\> ipod,  
sea biscuit, sea biscit =\> seabiscuit

I then use the following code to create a filter of an analyzer to use this file :

> curl -XPUT 'localhost:9200/test\_index?pretty' -H 'Content-Type: application/json' -d'  
> {  
> "settings": {  
> "index" : {  
> "analysis" : {  
> "analyzer" : {  
> "search\_synonyms" : {  
> "type" : "keyword",  
> "filter" : ["lowercase", "synonyms"]  
> }  
> },  
> "filter" : {  
> "synonyms" : {  
> "type" : "synonym",  
> "synonyms\_path" : "analysis/synonyms.txt"  
> }  
> }  
> }  
> }  
> }  
> }'

And I get:

> {  
> "acknowledged" : true,  
> "shards\_acknowledged" : true,  
> "index" : "test\_index"  
> }

But if I try the analyzer :

> curl -XGET 'localhost:9200/test\_index/\_analyze?pretty' -H 'Content-Type: application/json' -d'  
> {  
> "analyzer": "search\_synonyms",  
> "text": "i pod"  
> }'

I get :

> {  
> "tokens" : [  
> {  
> "token" : "i pod",  
> "start\_offset" : 0,  
> "end\_offset" : 5,  
> "type" : "word",  
> "position" : 0  
> }  
> ]  
> }

So the synonyms in the file are not recognized...  
Any thoughts or suggestions to make it work?  
Thank you in advance for your time.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 8:58am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/2 "2017-12-28T08:58:30Z")

</div>

You have a typo in your analyzer definition, which should be defined like this:

```
"search_synonyms" : {
  "type" : "custom",
  "tokenizer": "keyword",
  "filter" : ["lowercase", "synonyms"]
}
```

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 9:06am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/3 "2017-12-28T09:06:47Z")

</div>

I corrected my analyzer definition as you suggested.  
Deleted and re-created the index.  
Now I have this error showing up upon creation of the index :

> {  
> "error" : {  
> "root\_cause" : [  
> {  
> "type" : "illegal\_argument\_exception",  
> "reason" : "IOException while reading synonyms\_path\_path: /usr/share/elasticsearch/config/analysis/synonyms.txt"  
> }  
> ],  
> "type" : "illegal\_argument\_exception",  
> "reason" : "IOException while reading synonyms\_path\_path: /usr/share/elasticsearch/config/analysis/synonyms.txt",  
> "caused\_by" : {  
> "type" : "no\_such\_file\_exception",  
> "reason" : "/usr/share/elasticsearch/config/analysis/synonyms.txt"  
> }  
> },  
> "status" : 400  
> }

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 9:09am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/4 "2017-12-28T09:09:29Z")

</div>

> [@Aurelien\_Quillet](#):
>
> /usr/share/elasticsearch/config/analysis/synonyms.txt

Is your synonyms file at that location?

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 9:18am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/5 "2017-12-28T09:18:04Z")

</div>

Yes.

XXX@XXX:/usr/share/elasticsearch/config/analysis$ ll

> total 16  
> drwxr-xr-x 2 root root 4096 déc. 28 10:14 ./  
> drwxr-xr-x 3 root root 4096 déc. 26 15:39 ../  
> -rw-r--r-- 1 root root 60 déc. 28 10:14 out.txt  
> -rwxrwxrwx 1 root root 60 déc. 27 11:22 synonyms.txt\*

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 9:20am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/6 "2017-12-28T09:20:34Z")

</div>

Maybe make it readable by the `elasticsearch` user

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 9:26am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/7 "2017-12-28T09:26:32Z")

</div>

With the rights set as -rwxrwxrwx, doesn't everyone has the right to read and wright on the file?  
If not, then how can I change it so as to make readable by the elasticsearch user (which is me, so "root" no?) ?  
Actually, I am using a docker to run ES 6.1. Could that be a source of issues?

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 9:34am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/8 "2017-12-28T09:34:02Z")

</div>

In that case, are you sure that the file is present in the docker container? Have you mapped the volume?

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 10:09am UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/9 "2017-12-28T10:09:00Z")

</div>

Indeed, I did not think about that. Not knowing much about docker, I am actually trying to figure where I need to put the file synonyms.txt or how to map the docker so that it can go get the file.

IF it can help, here is my docker-compose file :

> version: '2.0'  
> services:  
> elasticsearch:  
> image: [docker.elastic.co/elasticsearch/elasticsearch:6.1.0](http://docker.elastic.co/elasticsearch/elasticsearch:6.1.0)  
> container\_name: elasticsearch  
> environment:  
> - cluster.name=docker-cluster  
> - bootstrap.memory\_lock=true  
> - "ES\_JAVA\_OPTS=-Xms512m -Xmx512m"  
> - "discovery.type=single-node"  
> ulimits:  
> memlock:  
> soft: -1  
> hard: -1  
> volumes:  
> - ./esdata1:/usr/share/elasticsearch/data  
> ports:  
> - 9200:9200  
> - 9300:9300  
> kibana:  
> image: [docker.elastic.co/kibana/kibana:6.1.0](http://docker.elastic.co/kibana/kibana:6.1.0)  
> container\_name: kibana  
> ports:  
> - 5601:5601

I tried without docker and I indeed have no problem getting the synonyms.txt file.  
So clearly a docker issue. And I am not finding how to fix it so far...

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 1:27pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/10 "2017-12-28T13:27:39Z")

</div>

> [@Aurelien\_Quillet](#):
>
> volumes:
> 
> - ./esdata1:/usr/share/elasticsearch/data

You simply need to add the following volume:

```
volumes:
- ./esconfig:/usr/share/elasticsearch/config

```

Where `esconfig` is your local config folder

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 2:39pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/11 "2017-12-28T14:39:49Z")

</div>

I modified docker-compose.yml as you suggested.  
I then did the following commands :

> sudo docker-compose stop  
> sudo docker-compose up -d --build  
> sudo docker ps -a

The response was :

> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES  
> f2cfd2187bea [docker.elastic.co/elasticsearch/elasticsearch:6.1.0](http://docker.elastic.co/elasticsearch/elasticsearch:6.1.0) "/usr/local/bin/do..." 3 minutes ago Exited (78) 2 seconds ago elasticsearch  
> 9b12332577eb [docker.elastic.co/kibana/kibana:6.1.0](http://docker.elastic.co/kibana/kibana:6.1.0) "/bin/bash /usr/lo..." 13 days ago Up 3 seconds 0.0.0.0:5601-\>5601/tcp kibana

ES is not running anymore with this docker. Am I missing something?

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 4:06pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/12 "2017-12-28T16:06:34Z")

</div>

What does the following command yield?

```
docker logs -f f2cfd2187bea --tail 1000
```

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 4:18pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/13 "2017-12-28T16:18:58Z")

</div>

> 2017-12-28 14:30:46,962 main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")  
> at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)  
> at java.lang.SecurityManager.checkPermission(SecurityManager.java:585)  
> at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1848)  
> at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:322)  
> at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)  
> at org.apache.logging.log4j.core.jmx.Server.register(Server.java:389)  
> at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:167)  
> at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:140)  
> at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:556)  
> at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)  
> at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:206)  
> at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:220)  
> at org.apache.logging.log4j.core.config.Configurator.initialize(Configurator.java:197)  
> at org.elasticsearch.common.logging.LogConfigurator.configureStatusLogger(LogConfigurator.java:171)  
> at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:140)  
> at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:119)  
> at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:290)  
> at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121)  
> at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112)  
> at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)  
> at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)  
> at org.elasticsearch.cli.Command.main(Command.java:90)  
> at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)  
> at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85)

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 4:20pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/14 "2017-12-28T16:20:43Z")

</div>

And this as well :  
ERROR: no log4j2.properties found; tried [/usr/share/elasticsearch/config] and its subdirectories

With a list of subdirectories.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 4:25pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/15 "2017-12-28T16:25:01Z")

</div>

Can you paste your current docker-compose file?

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 4:58pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/16 "2017-12-28T16:58:56Z")

</div>

> version: '2.0'  
> services:  
> elasticsearch:  
> image: [docker.elastic.co/elasticsearch/elasticsearch:6.1.0](http://docker.elastic.co/elasticsearch/elasticsearch:6.1.0)  
> container\_name: elasticsearch  
> environment:  
> - cluster.name=docker-cluster  
> - bootstrap.memory\_lock=true  
> - "ES\_JAVA\_OPTS=-Xms512m -Xmx512m"  
> - "discovery.type=single-node"  
> ulimits:  
> memlock:  
> soft: -1  
> hard: -1  
> volumes:  
> - ./esdata1:/usr/share/elasticsearch/data  
> - ./esconfig:/usr/share/elasticsearch/config  
> ports:  
> - 9200:9200  
> - 9300:9300  
> kibana:  
> image: [docker.elastic.co/kibana/kibana:6.1.0](http://docker.elastic.co/kibana/kibana:6.1.0)  
> container\_name: kibana  
> ports:  
> - 5601:5601

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 5:06pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/17 "2017-12-28T17:06:05Z")

</div>

And what does the local `esconfig` folder contain?

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 5:11pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/18 "2017-12-28T17:11:20Z")

</div>

I tried with it empty, and then after copying and pasting the content of the /usr/share/elasticsearch/config directory into it. Neither situation worked.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [December 28, 2017, 5:12pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/19 "2017-12-28T17:12:24Z")

</div>

You need to make sure that your `synonyms.txt` file ends up where it should within your container, the same way you did with the data folder.

---

<div class="post-metadata">

**Author:** ![Aurelien\_Quillet](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Aurelien\_Quillet](https://discuss.elastic.co/u/Aurelien_Quillet)\
**Post date:** [December 28, 2017, 5:14pm UTC](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417/20 "2017-12-28T17:14:10Z")

</div>

So, synonyms.txt needs to be in :  
/usr/share/elasticsearch/config/analysis/

or in :  
/esconfig/analysis/

?

[Next page](https://discuss.elastic.co/t/synonyms-in-synonyms-txt-not-recognized/113417.md?page=2)
