什么更有效率?模糊搜索还是范围搜索?
What is the more efficient? Fuzzy search or range search?
我有一个模糊查询及其等效的范围查询,并且两者 return 相同的搜索结果。
查询如下:
模糊搜索:
CURL -XGET 'localhost:9200/bank/_search?pretty' -d '
{
"sort": {
"balance": "desc"
},
"query": {
"fuzzy" : {
"balance" :{
"value" : 20000,
"fuzziness" : 10000
}
}
}
}'
范围搜索
CURL -XGET 'localhost:9200/bank/_search?pretty' -d '
{
"sort": {
"balance": "desc"
},
"query": {
"range" : {
"balance" : {
"gte" : 10000,
"lte" : 30000
}
}
}
}'
所以我的问题是哪一个更有效率?应该优先选择哪一个?
模糊查询使用"Levenshtein edit distance"。它是这样工作的:
The fuzzy query generates all possible matching terms that are within the maximum edit distance specified in fuzziness and then checks the term dictionary to find out which of those generated terms actually exist in the index.
所以发生的事情是创建所有可能的变体,然后检查它们是否存在。这可能比仅检查 gte
或 lte
更昂贵,尽管您的确切查询与索引大小当然很重要。
但更重要的是:第一个是否做了您认为的事情? Fuzzy 正在查看 levensteihn 距离,例如,如果您将 20000
与 90000
进行比较,那么它只会是 1
,所以我怀疑后者在您的结果集中,你甚至不想要。因此,尽管我确实有点怀疑,因为您似乎暗示它可以按您想要的方式工作,但我仍然会说模糊是效率最低的,因为它不会产生您正在寻找的实际结果。
我有一个模糊查询及其等效的范围查询,并且两者 return 相同的搜索结果。 查询如下:
模糊搜索:
CURL -XGET 'localhost:9200/bank/_search?pretty' -d '
{
"sort": {
"balance": "desc"
},
"query": {
"fuzzy" : {
"balance" :{
"value" : 20000,
"fuzziness" : 10000
}
}
}
}'
范围搜索
CURL -XGET 'localhost:9200/bank/_search?pretty' -d '
{
"sort": {
"balance": "desc"
},
"query": {
"range" : {
"balance" : {
"gte" : 10000,
"lte" : 30000
}
}
}
}'
所以我的问题是哪一个更有效率?应该优先选择哪一个?
模糊查询使用"Levenshtein edit distance"。它是这样工作的:
The fuzzy query generates all possible matching terms that are within the maximum edit distance specified in fuzziness and then checks the term dictionary to find out which of those generated terms actually exist in the index.
所以发生的事情是创建所有可能的变体,然后检查它们是否存在。这可能比仅检查 gte
或 lte
更昂贵,尽管您的确切查询与索引大小当然很重要。
但更重要的是:第一个是否做了您认为的事情? Fuzzy 正在查看 levensteihn 距离,例如,如果您将 20000
与 90000
进行比较,那么它只会是 1
,所以我怀疑后者在您的结果集中,你甚至不想要。因此,尽管我确实有点怀疑,因为您似乎暗示它可以按您想要的方式工作,但我仍然会说模糊是效率最低的,因为它不会产生您正在寻找的实际结果。