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


(wishnaveen) #1

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.

--


(Igor Motov) #2

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.

--


(Srinivas Muriki) #3

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"
}
}
}
]
}
}
}


(Igor Motov) #4

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.