# Synonym file loaded successfully, but search not returning results with synonyms

**URL:** <https://discuss.elastic.co/t/synonym-file-loaded-successfully-but-search-not-returning-results-with-synonyms/9882>\
**Category:** Elasticsearch\
**Created:** [November 29, 2012, 10:38am UTC](https://discuss.elastic.co/t/synonym-file-loaded-successfully-but-search-not-returning-results-with-synonyms/9882 "2012-11-29T10:38:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wishnaveen](https://avatars.discourse-cdn.com/v4/letter/w/dc4da7/32.png) [@wishnaveen](https://discuss.elastic.co/u/wishnaveen)\
**Post date:** [November 29, 2012, 10:38am UTC](https://discuss.elastic.co/t/synonym-file-loaded-successfully-but-search-not-returning-results-with-synonyms/9882/1 "2012-11-29T10:38:53Z")

</div>

Hi,

I have built index using below settings....

getClient().admin().indices().create(new  
CreateIndexRequest(indexName).settings(buildIndexSettings())).actionGet();

private Settings buildIndexSettings() {  
final ImmutableSettings.Builder settings = ImmutableSettings  
.settingsBuilder();  
settings.loadFromSource(buildAnalyzerSettings());  
return settings.build();  
}

```
private String buildAnalyzerSettings() {
    try {
        return XContentFactory.jsonBuilder()
                              .startObject()
                                  .startObject("analysis")
                                      .startObject("filter")
                                          .startObject("cmf_synonym")
                                              .field("synonyms_path", 

```

"synonyms-cmf.txt")  
.field("ignore\_case",  
"true")  
.field("type", "synonym")  
.endObject()  
.endObject()  
.startObject("analyzer")  
.startObject("index")  
.field("filter", new  
String[] { "standard", "lowercase", "cmf\_synonym"})  
.field("tokenizer",  
"standard")  
.endObject()  
.startObject("search")  
.field("filter", new  
String[] { "standard", "lowercase"})  
.field("tokenizer",  
"standard")  
.endObject()  
.endObject()  
.endObject()  
.endObject().string();  
} catch (Exception e) {  
throw new RuntimeException(  
"Not able to create analyzer settings for index", e);  
}  
}

I am indexing data after creating new index with above settings.  
index created successfully with all the settings loaded. I kept the synonym  
file at ES server config folder.

in synonym file I have a synonym like this  
_senior, sr_  
but when I search the results with _senior_ I am getting 5 results, where  
as searching with _sr_ returns nothing.

I am not getting any error logs also.. Unable to identify the issue.

Please some one suggest me if I am doing anything wrong. If details are not  
enough, please let me know.

Thanks,  
Navvi.

--

---

<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 29, 2012, 12:44pm UTC](https://discuss.elastic.co/t/synonym-file-loaded-successfully-but-search-not-returning-results-with-synonyms/9882/2 "2012-11-29T12:44:07Z")

</div>

Your command simply defines two analyzers, one with the name "search" and  
another one with the name "index". You need to refer to these analyzers  
when you create mapping.

On Thursday, November 29, 2012 5:38:53 AM UTC-5, navvi wrote:

> Hi,
> 
> I have built index using below settings....
> 
> getClient().admin().indices().create(new  
> CreateIndexRequest(indexName).settings(buildIndexSettings())).actionGet();
> 
> private Settings buildIndexSettings() {  
> final ImmutableSettings.Builder settings = ImmutableSettings  
> .settingsBuilder();  
> settings.loadFromSource(buildAnalyzerSettings());  
> return settings.build();  
> }
> 
> ```
> private String buildAnalyzerSettings() {
> try {
> return XContentFactory.jsonBuilder()
> .startObject()
> .startObject("analysis")
> .startObject("filter")
> .startObject("cmf_synonym")
> .field("synonyms_path", 
> 
> ```
> 
> "synonyms-cmf.txt")  
> .field("ignore\_case",  
> "true")  
> .field("type", "synonym")  
> .endObject()  
> .endObject()  
> .startObject("analyzer")  
> .startObject("index")  
> .field("filter", new  
> String { "standard", "lowercase", "cmf\_synonym"})  
> .field("tokenizer",  
> "standard")  
> .endObject()  
> .startObject("search")  
> .field("filter", new  
> String { "standard", "lowercase"})  
> .field("tokenizer",  
> "standard")  
> .endObject()  
> .endObject()  
> .endObject()  
> .endObject().string();  
> } catch (Exception e) {  
> throw new RuntimeException(  
> "Not able to create analyzer settings for index", e);  
> }  
> }
> 
> I am indexing data after creating new index with above settings.  
> index created successfully with all the settings loaded. I kept the  
> synonym file at ES server config folder.
> 
> in synonym file I have a synonym like this  
> _senior, sr_  
> but when I search the results with _senior_ I am getting 5 results, where  
> as searching with _sr_ returns nothing.
> 
> I am not getting any error logs also.. Unable to identify the issue.
> 
> Please some one suggest me if I am doing anything wrong. If details are  
> not enough, please let me know.
> 
> Thanks,  
> Navvi.

--

---

<div class="post-metadata">

**Author:** ![Srinivas\_Muriki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinivas_muriki/32/19244_2.png) [@Srinivas\_Muriki](https://discuss.elastic.co/u/Srinivas_Muriki)\
**Post date:** [June 19, 2017, 3:28am UTC](https://discuss.elastic.co/t/synonym-file-loaded-successfully-but-search-not-returning-results-with-synonyms/9882/3 "2017-06-19T03:28:37Z")

</div>

Hi ,  
I am facing issue in synonyms where search with substring like "raju t"  
I synonym file i have given synonyms like below.  
srinivas m,srinivas muriki,mahesh kumar,manasa muriki=\>Lajawaab  
"raju tal"=\>Lajawaab  
Television,TV=\>TV  
TV=\>Television  
when I search with "raju tal" i am getting results .  
But When I search with substring of raju tal i am not gettin results.  
Below are the mapping and setting .

DELETE hotstar\_autosuggestion

PUT hotstar\_autosuggestion  
{  
"settings": {  
"analysis": {  
"analyzer": {

```
    "keyword_edge":{
                "type":"custom",
                "tokenizer":"standard",
               "filter":[
                   "ngramone",
                   "lowercase"
                   
                   ]
                
            },
            "search_standard_edge":{
                "type":"custom",
                "tokenizer":"standard",
               "filter":["my_synonym_filter","ngramone","lowercase"]
                
            }
    },
    "filter": {
    "my_synonym_filter": {
      "type": "synonym", 
      "synonyms_path" : "synonyms.txt"
    },
     "ngramone": {
                "type": "edge_ngram",
                "min_gram": 1,
                "max_gram": 30 ,
                  "token_chars":[
                    "letter",
                      "digit",
                      "punctuation",
                      "symbol"
                    
                ]
            }
    }
}
},
"mappings": {
    "hotstar":{
        "properties": {
            "title":{
                "fields": {
                "titleone":{
                    "type": "string"
                },
                 "titletwo":{
                    "type": "string"
                }
                },
                "type": "multi_field"
                
            },
            "search_keywords":{
                "type": "string"
            }
        }
    }
}
}

```

POST hotstar\_autosuggestion/\_analyze  
{  
"analyzer":"comma\_analyzer",  
"text":"srilatha,edula"

}

POST /hotstar\_autosuggestion/hotstar/\_bulk  
{ "index": { "\_id": 22}}  
{ "title": "capgemini manasa muriki","search\_keywords":["horror Movies","mythology movies"]}  
{ "index": { "\_id": 21}}  
{ "title": "manasa muriki","search\_keywords":["horror Movies","mythology movies"]}  
{ "index": { "\_id": 25}}  
{ "title": "raju tal","search\_keywords":["horror Movies","mythology movies"]}  
{ "index": { "\_id": 24}}  
{ "title": "telugu television","search\_keywords":["horror Movies","mythology movies"]}  
{ "index": { "\_id": 23}}  
{ "title": "telugu tv","search\_keywords":["horror Movies","mythology movies"]}  
{ "index": { "\_id": 19}}  
{ "title": "accenture solutions pvt limited","search\_keywords":["horror Movies","kannada movies"]}  
{ "index": { "\_id": 20}}  
{ "title": "srinivas muriki accenture private siana","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 18}}  
{ "title": "srinivas muriki accenture private siana","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 17}}  
{ "title": "srinivas muriki siana","search\_keywords":["English Movies","Telugu Movies"]}  
{"index": { "\_id": 16}}  
{ "title": "srinivas muriki siana chaik","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 10}}  
{ "title": "hum saath deena saath hain","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 12}}  
{ "title": "srinivas muriki","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 13}}  
{ "title": "srilatha edula accenture","search\_keywords":["English Movies","Telugu Movies"]}  
{"index": { "\_id": 14}}  
{ "title": "accenture private limited","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 15}}  
{ "title": "team srilatha edula accenture","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 11}}  
{ "title": "Aur Baati Hum","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 1}}  
{ "title": "Aur Baati Hum","search\_keywords":["English Movies","Telugu Movies"]}  
{ "index": { "\_id": 2}}  
{ "title": "Ek Boond Ishq","search\_keywords":["Hindi Movies","Malayalam Movies"]}  
{ "index": { "\_id": 3}}  
{ "title": "diya aur baati hum","search\_keywords":["Drama Movies","Comedy Movies"]}  
{ "index": { "\_id": 4}}  
{ "title": "Sanyukta-Randhir: His versus Hers!","search\_keywords":["family Movies","action Movies"]}  
{ "index": { "\_id": 5}}  
{ "title":"Tara-Mrityunjay Sizzle up","search\_keywords":["horror Movies","kannada Movies"]}  
{ "index": { "\_id": 6}}  
{ "title":"Kalavati steals the show","search\_keywords":["mythology Movies","kannada Movies"]}  
{ "index": { "\_id": 7}}  
{ "title":"Lajawaab Laajo","search\_keywords":["tamil Movies","marati Movies"]}  
{ "index": { "\_id": 8}}  
{ "title": "Sandhya-Sooraj draw closer","search\_keywords":["gujarathi Movies","marati Movies"]}  
{ "index": { "\_id": 9}}  
{ "title":"Ishita & Raman""s Bond","search\_keywords":["action Movies","marati Movies"]}

POST hotstar\_autosuggestion/hotstar/\_search  
{  
"query" : {  
"bool": {  
"should": [  
{  
"match\_phrase\_prefix": {  
"title.titleone": "raju tal"  
}  
},  
{  
"match\_phrase\_prefix": {  
"search\_keywords": "raju tal"  
}  
},  
{  
"match\_phrase": {  
"title.titletwo": {  
"query": "raju tal",  
"analyzer": "search\_standard\_edge"  
}  
}  
}  
]  
}  
}  
}

---

<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:** [June 20, 2017, 10:58am UTC](https://discuss.elastic.co/t/synonym-file-loaded-successfully-but-search-not-returning-results-with-synonyms/9882/4 "2017-06-20T10:58:41Z")

</div>

I think it might be better to use completion suggester instead of ngram and search for that. It might be also a good idea to open an new topic for this instead of resurrecting the old one, since your question seems to be completely unrelated to the original topic question that was asked here 4 years ago.

---

<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 4, 2022, 4:01am UTC](https://discuss.elastic.co/t/synonym-file-loaded-successfully-but-search-not-returning-results-with-synonyms/9882/5 "2022-11-04T04:01:24Z")

</div>


