同义词的几个关键点:
- 显示映射改为等同同义词。
- 同义词只用于搜索,使用synonym_graph,尽量少用于索引时间。
- 更新同义词的流程为关闭,更新,打开索引。
- 同义词最好以文件的形式存储在config目录,配置updateable=true,synonyms_path
GET my_synonyms/_settings
GET my_synonyms/_mapping
DELETE my_synonyms
PUT my_synonyms
{
"settings": {
"analysis": {
"analyzer": {
"my_synonyms_analyze": {
"tokenizer": "standard",
"filter": [
"my_synonyms_filter"
]
}
},
"filter": {
"my_synonyms_filter": {
"type": "synonym",
"synonyms": [
"elk,elkb,elasticsearch"
]
}
}
}
},
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "standard",
"search_analyzer": "my_synonyms_analyze"
}
}
}
}
POST my_synonyms/_close
PUT my_synonyms/_settings
{
"analysis": {
"filter": {
"my_synonyms_filter": {
"type": "synonym_graph",
"synonyms": [
"elk,elkb,elastic"
]
}
}
}
}
POST my_synonyms/_open
POST my_synonyms/_doc/1
{
"content":"elk is very powerful"
}
POST my_synonyms/_doc/2
{
"content":"elkb is very powerful"
}
POST my_synonyms/_doc/3
{
"content":"Elastic Stack is very powerful"
}
POST my_synonyms/_search
{
"query": {
"match": {
"content": "elkb"
}
}
}