产品动态
产品公告
安全公告
myindex使用了synonym.txt同义词文件,当该同义词文件的内容变更并重新上传后,现有的索引myindex不会动态加载更新后的同义词,需要对现有索引进行reindex操作,否则更新后的同义词文件只对新建的索引生效。utf-8编码,扩展名为.txt。例如:快乐水,可乐 => 可乐,快乐水elasticsearch,es => es


synonym.txt作为测试文件,文件内容为elasticsearch,es => esPUT /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}]}
tokenes的类型是SYNONYM同义词。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"}}}}}
"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}]}
tokenes的类型是SYNONYM同义词。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"]}}]}}
文档反馈