myindex uses the synonym.txt synonym file, but the file is modified and uploaded again, then the existing index myindex will not dynamically load the updated synonyms. You need to reindex the existing index; otherwise, the updated synonym file will take effect only for new indices..txt file extension; for example:coke,cola => cola,cokeelasticsearch,es => es


filter filter to configure synonyms and the synonym.txt as the testing file, and the file content is elasticsearch,es => es.PUT /my_index{"settings": {"index": {"analysis": {"analyzer": {"my_ik": {"type": "custom","tokenizer": "ik_smart","filter": ["my_synonym"]}},"filter": {"my_synonym": {"type": "synonym","synonyms_path": "analysis/synonym.txt"}}}}},"mappings": {"_doc": {"properties": {"content": {"type": "text","analyzer": "my_ik","search_analyzer": "my_ik"}}}}}
GET /my_index/_analyze{"analyzer": "my_ik","text":"tencet elasticsearch service"}
{"tokens": [{"token": "tencet","start_offset": 0,"end_offset": 6,"type": "ENGLISH","position": 0},{"token": "es","start_offset": 7,"end_offset": 20,"type": "SYNONYM","position": 1},{"token": "service","start_offset": 21,"end_offset": 28,"type": "ENGLISH","position": 2}]}
token and es are in SYNONYM type.POST /my_index/_doc/1{"content": "tencet elasticsearch service"}POST /my_index/_doc/2{"content": "hello es"}
GET my_index/_search{"query" : { "match" : { "content" : "es" }},"highlight" : {"pre_tags" : ["<tag1>", "<tag2>"],"post_tags" : ["</tag1>", "</tag2>"],"fields" : {"content": {}}}}
{"took": 4,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 2,"max_score": 0.25811607,"hits": [{"_index": "my_index","_type": "_doc","_id": "2","_score": 0.25811607,"_source": {"content": "hello es"},"highlight": {"content": ["hello <tag1>es</tag1>"]}},{"_index": "my_index","_type": "_doc","_id": "1","_score": 0.25316024,"_source": {"content": "tencet elasticsearch service"},"highlight": {"content": ["tencet <tag1>elasticsearch</tag1> service"]}}]}}
PUT /my_index{"settings": {"index": {"analysis": {"analyzer": {"my_ik": {"type": "custom","tokenizer": "ik_smart","filter": ["my_synonym"]}},"filter": {"my_synonym": {"type": "synonym","synonyms": ["elasticsearch,es => es"],}}}}},"mappings": {"_doc": {"properties": {"content": {"type": "text","analyzer": "my_ik","search_analyzer": "my_ik"}}}}}
filter, synonyms instead of a synonym file are directly referenced: "synonyms": ["elasticsearch,es => es"]GET /my_index/_analyze{"analyzer": "my_ik","text":"tencet elasticsearch service"}
{"tokens": [{"token": "tencet","start_offset": 0,"end_offset": 6,"type": "ENGLISH","position": 0},{"token": "es","start_offset": 7,"end_offset": 20,"type": "SYNONYM","position": 1},{"token": "service","start_offset": 21,"end_offset": 28,"type": "ENGLISH","position": 2}]}
token and es are in SYNONYM type.POST /my_index/_doc/1{"content": "tencet elasticsearch service"}POST /my_index/_doc/2{"content": "hello es"}
GET my_index/_search{"query" : { "match" : { "content" : "es" }},"highlight" : {"pre_tags" : ["<tag1>", "<tag2>"],"post_tags" : ["</tag1>", "</tag2>"],"fields" : {"content": {}}}}
{"took": 4,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 2,"max_score": 0.25811607,"hits": [{"_index": "my_index","_type": "_doc","_id": "2","_score": 0.25811607,"_source": {"content": "hello es"},"highlight": {"content": ["hello <tag1>es</tag1>"]}},{"_index": "my_index","_type": "_doc","_id": "1","_score": 0.25316024,"_source": {"content": "tencet elasticsearch service"},"highlight": {"content": ["tencet <tag1>elasticsearch</tag1> service"]}}]}}
Feedback