How to search with synonym analyzer

Here are my index setting and mapping

M using the synonym analyzer over the fields and in search i want to search in all the fields of an index.

analysis": {
"filter": {
"synonym": {
"type": "synonym",
"synonyms_path": "D:\MyElasticSearch\elasticsearch-1.5.2\config\synonyms.txt",
"ignore_case": "true"
}
},
"analyzer": {
"synonym": {
"filter": [
"synonym"
],
"tokenizer": "whitespace"
}
}
}
Here is the mapping

"BrandDesc": {
"type": "string",
"index": "not_analyzed",
"analyzer": "synonym",
"fields": {
"raw": {
"type": "string",
"analyzer": "synonym"
}
}
},
when i search with the query with normal query string it's giving me count say 1200

GET newpcdb_anlyz/_search
{
"query": {
"query_string": {
"query": "engine"
}
}
}
But same when I query with analyzer synonyms its giving me less count,(it should give more than 1200 as it will include engine synonyms also in search)

GET newpcdb_anlyz/_search
{
"query": {
"query_string": {
"query": "engine",
"analyzer": "synonym"
}
}
}
M I missing something

Search matching occurs when the tokens in your search match those in your index.
The tool for debugging how a query is (or isn't) matching is the explain API [1].
It should show you the tokens your query is executing at a low level.
If some of the tokens are unexpected you can use the analyze API [2] to debug what tokens your query and your document produce.

[1] https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-explain.html
[2] https://www.elastic.co/guide/en/elasticsearch/reference/5.0/_testing_analyzers.html

Thanks Mark for your remark's,I will chek with the above API & will get back ,if I have any queries.

1 Like

Hi Mark

I have debugged the query and found that

GET /newpcdb_prasad/newpcdb_prasad_type/180080/_explain

{
"query" : {
"query_string": {
"query": "machine"
}
}
}

If I use this query m getting matched as true but when I search with analyzer m getting the match as false.

GET /newpcdb_prasad/newpcdb_prasad_type/180080/_explain

{
"query" : {
"query_string": {
"query": "machine",
"analyzer": "synonym"
}
}
}

getting the response as match false.

However, when I check what kind of tokens have been generated by analyzing test I do found machine in document 180080

GET newpcdb_prasad/_analyze?text=Forney .......some text....&analyzer=synonym&tokenizer=whitespace

m getting a token of a machine

{
  "token": "machine",
  "start_offset": 254,
  "end_offset": 261,
  "type": "SYNONYM",
  "position": 43
},

Could you please help me out , ....as its is priority issue to me

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