ElasticSearch 同义词

参考:

1. 自定义同义词 token filter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
PUT /myindex
{
"settings": {
"analysis": {
// 自定义同义词token filter
"filter": {
"chinese_synonym_filter": {
// type设置为"synonym"
"type": "synonym",
// 指定同义词文件
"synonyms_path": "analysis/chinese_synonym.txt"
}
},
// 自定义analyzer,在ik_max_word的基础上使用同义词filter
"analyzer": {
"ik_max_word_synonym": {
"type": "custom",
"tokenizer": "ik_max_word",
"filter": ["chinese_synonym_filter"]
}
}
}
},

"mappings": {
"mytype": {
"properties": {
// 测试字段
"title": {
"type": "text",
"analyzer": "ik_max_word_synonym"
}
}
}
}
}

测试

1
2
3
4
5
GET myindex/_analyze
{
"text": ["一个人无论怎么努力"],
"analyzer": "ik_max_word_synonym"
}

panchaoxin wechat
关注我的公众号
支持一下