我有一个大型的名字数据库,主要来自苏格兰。我们目前正在生产一个原型来取代现有的一个搜索软件。这仍在制作中,我们的目标是让我们的结果尽可能地接近当前搜索的结果。ElasticSearch - 寻找人名
我希望有人能帮助我,我进入一个搜索弹性搜索,查询是“迈克尔Heaney”,我得到了一些野生的结果。目前的搜索返回两个主要的姓氏,这些是 - “Heaney”和“Heavey”都带有“Michael”的名字,我可以在Elastic Search中获得“Heaney”结果,但是我无法获得“Heavey”,ES也返回没有姓氏“迈克尔”的人,但我明白,这是由于它是模糊查询的一部分。我知道这是一个狭义的用例,因为它只有一个搜索,但得到这个结果并知道我可以如何获得它会有所帮助。
谢谢。
映射
{
"jr": {
"_all": {
"enabled": true,
"index_analyzer": "index_analyzer",
"search_analyzer": "search_analyzer"
},
"properties": {
"pty_forename": {
"type": "string",
"index": "analyzed",
"boost": 2,
"index_analyzer": "index_analyzer",
"search_analyzer": "search_analyzer",
"store": "yes"
},
"pty_full_name": {
"type": "string",
"index": "analyzed",
"boost": 4,
"index_analyzer": "index_analyzer",
"search_analyzer": "search_analyzer",
"store": "yes"
},
"pty_surname": {
"type": "string",
"index": "analyzed",
"boost": 4,
"index_analyzer": "index_analyzer",
"search_analyzer": "search_analyzer",
"store": "yes"
}
}
}
}'
指数设置
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"index_analyzer": {
"tokenizer": "standard",
"filter": [
"standard",
"my_delimiter",
"lowercase",
"stop",
"asciifolding",
"porter_stem",
"my_metaphone"
]
},
"search_analyzer": {
"tokenizer": "standard",
"filter": [
"standard",
"my_metaphone",
"synonym",
"lowercase",
"stop",
"asciifolding",
"porter_stem"
]
}
},
"filter": {
"synonym": {
"type": "synonym",
"synonyms_path": "synonyms/synonyms.txt"
},
"my_delimiter": {
"type": "word_delimiter",
"generate_word_parts": true,
"catenate_words": false,
"catenate_numbers": false,
"catenate_all": false,
"split_on_case_change": false,
"preserve_original": false,
"split_on_numerics": false,
"stem_english_possessive": false
},
"my_metaphone": {
"type": "phonetic",
"encoder": "metaphone",
"replace": false
}
}
}
}
}'
模糊
{
"from":0, "size":100,
"query": {
"bool": {
"should": [
{
"fuzzy": {
"pty_surname": {
"min_similarity": 0.2,
"value": "Heaney",
"prefix_length": 0,
"boost": 5
}
}
},
{
"fuzzy": {
"pty_forename": {
"min_similarity": 1,
"value": "Michael",
"prefix_length": 0,
"boost": 1
}
}
}
]
}
}
}
谢谢亚历克斯。让我把所有这些信息都收集起来,然后我会回报。答案看起来很彻底。 – Nate
我们刚刚发表了一篇关于模糊搜索的文章,这也可能是有趣的:https://www.found.no/foundation/fuzzy-search/ –
将书签。非常感谢您的帮助,我学到了很多东西。 – Nate