假设我在索引中有两个文件:
{
"name": "dog"
}
和
{
"name": "dog - hypoallergenic"
}
我创建了一个同义词映射文件,如下所示:
PUT syn_test
{
"settings": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": ["puppy=>dog","canine=>dog","kitten=>cat","feline=>cat"]
}
},
"analyzer": {
"my_synonyms": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_synonym_filter"
]
}
}
}
},
"mappings": {
"animal": {
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "string",
"analyzer": "my_synonyms"
}
}
}
}
}
我已将两份文件编入索引:
POST syn_test/animal
{
"name": "dog - hypoallergenic"
}
POST syn_test/animal
{
"name": "dog"
}
当我搜索puppy
或canine
时,我会在我的索引映射中映射为dog
的同义词,我会得到dog
和{{1}的结果}。
dog - hypoallergenic
或puppy
查询的所需输出将返回canine
。有没有办法强制查询只返回同义词中的完全匹配?
答案 0 :(得分:0)
您使用过标准标记器。如果您想将名称视为仅单值字段(就像它提供的那样),您可以指定关键字标记符而不是标准。