Synonyms not getting applied

Hello Team,

I have below document in the index

{
  
  "name" :"test",
  "products": [
      {
        "pname" : "p1",
        "qty" : "10 pcs"
      },
      {
        "pname" : " p3 ",
        "qty" : "10 PCS"
       
      }
 ]
}

and i have below index settings

PUT /tst
{
    "settings": {
        "index" : {
            "analysis" : {
                "analyzer" : {
                    "synonym" : {
                        "tokenizer" : "standard",
                        "filter" : ["synonym"]
                    }
                },
                "filter" : {
                    "synonym" : {
                        "type" : "synonym",
                        "lenient": true,
                        "synonyms" : ["pcs,PCS  => piece"]
                    }
                }
            }
        }
    }
}

But when i try to execute search it re turns 0 results

POST tst/_search
{
  
  "query": {
    
      "query_string": {
        "default_field": "products.qty", 
        "query": "piece"
      }
  }
  
}

But below query returns 1 result (as expected)

POST tst/_search
{
  
  "query": {
    
      "query_string": {
        "default_field": "products.qty", 
        "query": "pcs"
      }
  }
  
}

could you please help to understand how synonyms work and if anything i am missing for configuring the synonyms.

Thank you for your help.

Thank you,
Aditya

You defined an analyzer but did not apply it to your field as you did not define a mapping.

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