ElasticSearch同义词返回多个结果

时间:2016-04-22 14:10:54

标签: elasticsearch

假设我在索引中有两个文件:

{
  "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"
}

当我搜索puppycanine时,我会在我的索引映射中映射为dog的同义词,我会得到dog和{{1}的结果}。

dog - hypoallergenicpuppy查询的所需输出将返回canine。有没有办法强制查询只返回同义词中的完全匹配?

1 个答案:

答案 0 :(得分:0)

您使用过标准标记器。如果您想将名称视为仅单值字段(就像它提供的那样),您可以指定关键字标记符而不是标准。