让我直接跳到代码。
PUT /test_1
{
"settings": {
"analysis": {
"filter": {
"synonym": {
"type": "synonym",
"synonyms": [
"university of tokyo => university_of_tokyo, u_tokyo",
"university" => "college, educational_institute, school"
],
"tokenizer": "whitespace"
}
},
"analyzer": {
"my_analyzer": {
"tokenizer": "whitespace",
"filter": [
"shingle",
"synonym"
]
}
}
}
}
}
输出
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Token filter [shingle] cannot be used to parse synonyms"
}
],
"type": "illegal_argument_exception",
"reason": "Token filter [shingle] cannot be used to parse synonyms"
},
"status": 400
}
基本上,
假设我有以下 index_time 同义词
"university => university, college, educational_institute, school"
"tokyo => tokyo, japan_capitol"
"university of tokyo => university_of_tokyo, u_tokyo"
如果我搜索“大学”,我希望匹配“东京大学”,
但由于索引仅包含“东京大学”=> university_of_tokyo, u_tokyo .....搜索失败
我期待如果我使用分析器{'filter': ["single", "synonym"]}
university of tokyo -shingle-> university -synonyms-> college, institue
如何获得所需的行为?