# How to setup synonym using ES 5.6.2

**URL:** https://discuss.elastic.co/t/how-to-setup-synonym-using-es-5-6-2/104909
**Category:** Elasticsearch
**Created:** [October 23, 2017, 2:22pm UTC](https://discuss.elastic.co/t/how-to-setup-synonym-using-es-5-6-2/104909 "2017-10-23T14:22:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Shahrul\_Azhar](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@Shahrul\_Azhar](https://discuss.elastic.co/u/Shahrul_Azhar)
#### Post date: [October 23, 2017, 2:22pm UTC](https://discuss.elastic.co/t/how-to-setup-synonym-using-es-5-6-2/104909/1 "2017-10-23T14:22:06Z")

</div>

hi,

Can someone assiSt me how to setup synonym using ES 5.6.2?  
I have to import data from oracle into index in ES

Currently, what i'm doing is:

step 1:

1. // file logstash-ora-01.conf

input {  
jdbc {  
jdbc\_validate\_connection =\> true  
jdbc\_connection\_string =\> "jdbc:oracle:thin:@192.168.1.43:1521/PDBORCL"  
jdbc\_user =\> "propadvisor"  
jdbc\_password =\> "propadvisor"  
jdbc\_driver\_library =\> "ojdbc8.jar"  
jdbc\_driver\_class =\> "Java::oracle.jdbc.driver.OracleDriver"  
statement =\> "SELECT my\_property\_id, my\_long\_address\_t from myproperty"  
}  
}  
output {  
stdout { codec =\> rubydebug }  
elasticsearch {  
index =\> "pa\_index22"  
document\_type =\> "logsData22"  
}  
}

step 2

1. file synonyms.txt

taman, tman, tmn  
jalan, jln, jlan  
kampung, kg, kampg, kmpg, kampong  
bukit, bkt  
batu, bt  
peti surat, pt  
lorong, lrg, lorg

1. my query

POST pa\_index22/\_search  
{  
"query": {  
"bool": {  
"should": [  
{ "match": { "my\_long\_address\_t" : "tmn" }}  
]  
}  
}  
}

result

{  
"took": 0,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 0,  
"max\_score": null,  
"hits": []  
}  
}

i dont know where to put the synonym configuration inside my existing index.  
Please help me..

---

<div class="post-metadata">

### Author: ![ParitoshBh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paritoshbh/32/22487_2.png) [@ParitoshBh](https://discuss.elastic.co/u/ParitoshBh)
#### Post date: [October 23, 2017, 6:51pm UTC](https://discuss.elastic.co/t/how-to-setup-synonym-using-es-5-6-2/104909/2 "2017-10-23T18:51:00Z")

</div>

You need to add synonym filter to the mapping. Using a more general example to show its usage,

```auto
        $params['body']['settings'] = [
          'analysis' => [
            'filter' => [
              'filter_synonym' => [
                'type' => 'synonym',
                'synonyms_path' => 'some_dir/synonym.txt',
                'tokenizer' => 'keyword',
                'expand' => true
              ]
            ]
          ]
        ];

```

The `synonyms_path` is located at `/etc/elasticsearch`.

More on [synonym token filter](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/analysis-synonym-tokenfilter.html).

---

<div class="post-metadata">

### Author: ![Shahrul\_Azhar](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@Shahrul\_Azhar](https://discuss.elastic.co/u/Shahrul_Azhar)
#### Post date: [October 24, 2017, 2:29am UTC](https://discuss.elastic.co/t/how-to-setup-synonym-using-es-5-6-2/104909/3 "2017-10-24T02:29:36Z")

</div>

Hi, thanks for replying this message

I already follw this step....

1. POST /pa\_index22/\_close

2. 

PUT /pa\_index22/\_settings  
{  
"index" : {  
"analysis" : {  
"filter" : {  
"synonym" : {  
"type" : "synonym",  
"synonyms\_path" : "synonyms.txt",  
"tokenizer" : "whitespace"  
}  
},  
"analyzer" : {  
"synonym" : {  
"tokenizer" : "whitespace",  
"filter" : ["synonym"]  
}  
}  
}  
}  
}

1. POST /pa\_index22/\_open

but, the configuration still not take effect  
when i run this command

GET /pa\_index22/\_mapping?pretty

{  
"pa\_index22": {  
"mappings": {  
"logsData22": {  
"properties": {  
"@timestamp": {  
"type": "date"  
},  
"@version": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"my\_long\_address\_t": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"my\_property\_id": {  
"type": "long"  
}  
}  
}  
}  
}  
}

please assist me where i'm doing the wrong... ☹

---

<div class="post-metadata">

### Author: ![Shahrul\_Azhar](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@Shahrul\_Azhar](https://discuss.elastic.co/u/Shahrul_Azhar)
#### Post date: [October 25, 2017, 5:23am UTC](https://discuss.elastic.co/t/how-to-setup-synonym-using-es-5-6-2/104909/4 "2017-10-25T05:23:54Z")

</div>

Nevermind... i find it myself

synonyms.txt  
#-----------------------------------------------------------------  
taman, tmn, tamn, tman  
jalan, jln, jlan  
kampung, kg, kampg, kmpg, kampong, kmpg  
bukit, bkt, bkt  
batu, bt, bt  
peti surat, pt, pt  
lorong, lrg, lorg  
#--------------------------------------------------------

1. close current index ----- \> POST /pa\_index22/\_close

2. Update current index with this setting

PUT /pa\_index/\_settings  
{  
"settings": {  
"index" : {  
"analysis" : {  
"analyzer" : {  
"synonym\_graph" : {  
"tokenizer" : "standard",  
"filter" : ["synonym\_graph"]  
}  
},  
"filter" : {  
"synonym\_graph" : {  
"type" : "synonym\_graph",  
"synonyms\_path" : "synonyms.txt"  
}  
}  
}  
}  
}  
}

1. Open back the index ----\> POST /pa\_index/\_open

2. Verify weather our setting is take effect or not  
-------------\> GET /pa\_index/\_analyze?analyzer=synonym\_graph&text=lrg

output  
{  
"tokens": [  
{  
"token": "lorong",  
"start\_offset": 0,  
"end\_offset": 3,  
"type": "SYNONYM",  
"position": 0  
},  
{  
"token": "lorg",  
"start\_offset": 0,  
"end\_offset": 3,  
"type": "SYNONYM",  
"position": 0  
},  
{  
"token": "lrg",  
"start\_offset": 0,  
"end\_offset": 3,  
"type": "",  
"position": 0  
}  
]  
}

1. It already take value from synonyms.txt when i search lrg, so it take lrg, lorong, lorg

2. Also, we can run this statement to know the explanation  
------\>  
GET /pa\_index/\_validate/query?explain  
{  
"query": {  
"match": {  
"text": {  
"query": "lrg",  
"analyzer": "synonym\_graph"  
}  
}  
}  
}

output:  
{  
"valid": true,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"failed": 0  
},  
"explanations": [  
{  
"index": "pa\_index",  
"valid": true,  
"explanation": "Synonym(text:lorg text:lorong text:lrg)"  
}  
]  
}

1. So, perform our search query  
------\>  
POST pa\_index/\_search  
{  
"query" : {  
"query\_string" : {  
"query" : "lrg meranti",  
"analyzer" : "synonym\_graph",  
"fields" : ["my\_long\_address\_t"],  
"auto\_generate\_phrase\_queries" : true  
}  
}  
}

output:  
{  
"took": 17,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 315873,  
"max\_score": 14.444332,  
"hits": [  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9NhdcDQlb49cpwsCNW",  
"\_score": 14.444332,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T08:35:37.812Z",  
"my\_long\_address\_t": "4344C, LORONG MERANTI,LORONG MERANTI, LORONG MER",  
"my\_property\_id": 1936  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9Ni631Qlb49cpws5ue",  
"\_score": 14.415924,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T08:42:00.514Z",  
"my\_long\_address\_t": "43343A, LORONG MERANTI,LORONG MERANTI, LORONG MERANTI",  
"my\_property\_id": 1286  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9Niw7cQlb49cpws0JU",  
"\_score": 13.769295,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T08:41:19.805Z",  
"my\_long\_address\_t": "2344C,LORONG MERANTI, LORONG MERANTI",  
"my\_property\_id": 1290  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9OOcgJQlb49cpw9WB1",  
"\_score": 13.769295,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T11:52:10.458Z",  
"my\_long\_address\_t": "54349,LORONG MERANTI, LORONG MERANTI",  
"my\_property\_id": 21389  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9OOZh\_Qlb49cpw9Vhk",  
"\_score": 13.769295,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T11:51:58.304Z",  
"my\_long\_address\_t": "27BB,LORONG MERANTI, LORONG MERANTI",  
"my\_property\_id": 2125  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9NifSWQlb49cpwspvy",  
"\_score": 13.671318,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T08:40:07.527Z",  
"my\_long\_address\_t": "54449,LORONG MERANTI, LORONG MERANTI",  
"my\_property\_id": 1079  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9Nh7x3Qlb49cpwsVh5",  
"\_score": 13.451371,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T08:37:42.088Z",  
"my\_long\_address\_t": "443C, LORONG MERANTI,LORONG MERANTI, LORONG MERANTI, 55200",  
"my\_property\_id": 16652  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9NixqMQlb49cpws0cY",  
"\_score": 13.364031,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T08:41:22.796Z",  
"my\_long\_address\_t": "10A, LORONG MERANTI 2,LORONG MERANTI, LORONG MERANTI, 55200",  
"my\_property\_id": 16702  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9OO-YNQlb49cpw9eZi",  
"\_score": 13.364031,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T11:54:29.214Z",  
"my\_long\_address\_t": "47CAC, LORONG MERANTI,LORONG MERANTI, LORONG MERANTI, 55200",  
"my\_property\_id": 21001  
}  
},  
{  
"\_index": "pa\_index",  
"\_type": "logsData",  
"\_id": "AV9Nh\_sRQlb49cpwsYGd",  
"\_score": 13.355483,  
"\_source": {  
"@version": "1",  
"@timestamp": "2017-10-24T08:37:58.114Z",  
"my\_long\_address\_t": "183 LORONG MERANTI,LORONG MERANTI, LORONG MERANTI, 554200",  
"my\_property\_id": 13961  
}  
}  
]  
}  
}

---

<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: [November 22, 2017, 5:24am UTC](https://discuss.elastic.co/t/how-to-setup-synonym-using-es-5-6-2/104909/5 "2017-11-22T05:24:36Z")

</div>

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