Fuzzy Query
模糊查询
Returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance.
返回包含与搜索词条相似的词条的文档(以Levenshtein编辑距离衡量)。
An edit distance is the number of one-character changes needed to turn one term into another. These changes can include:
编辑距离是将一个词条转换为另一个词条所需的单字符改变的次数。这些改变可以包括:
-
Changing a character (box → fox)
-
Removing a character (black → lack)
-
Inserting a character (sic → sick)
-
Transposing two adjacent characters (act → cat)
-
改变字符(b ox→ f ox)
-
删除字符(black→lack)
-
插入字符(sic→sic k)
-
置换两个相邻字符(ac t→ ca t)
To find similar terms, the fuzzy
query creates a set of all possible variations, or expansions, of the search term within a specified edit distance. The query then returns exact matches for each expansion.
为了找到相似的词条,fuzzy
查询会在指定的编辑距离内创建搜索词条所有可能的变体或扩展集合。然后查询就根据该集合进行完全匹配。
Example requests
Simple example
简单的例子
GET /_search
{
"query": {
"fuzzy": {
"user": {
"value": "ki"
}
}
}
}
Copy as cURLView in Console
Example using advanced parameters
高级参数的例子
GET /_search
{
"query": {
"fuzzy": {
"user": {
"value": "ki",
"fuzziness": "AUTO",
"max_expansions": 50,
"prefix_length": 0,
"transpositions": true,
"rewrite": "constant_score"
}
}
}
}
Copy as cURLView in Console
Top-level parameters for fuzzy
-
field
(Required, object) Field you wish to search.
(必需,对象)您要搜索的字段。
Parameters for field
field
的参数
-
value
(Required, string) Term you wish to find in the provided
field
.(必需,字符串)您希望在
field
中找到的词条。 -
fuzziness
(Optional, string) Maximum edit distance allowed for matching. See Fuzziness for valid values and more information.
(可选,字符串)匹配允许的最大编辑距离。其有效值和更多信息,请参见模糊性。
-
max_expansions
(Optional, integer) Maximum number of variations created. Defaults to
50
.Avoid using a high value in themax_expansions
parameter, especially if theprefix_length
parameter value is0
. High values in themax_expansions
parameter can cause poor performance due to the high number of variations examined.(可选,整数)创建变体的最大数量。默认为
50
。警告:避免在
max_expansions
参数中使用较高的值,尤其是当prefix_length
参数值为0
时。如果max_expansions
参数值过高,由于需要检查的变体数量过多,可能会导致性能不佳。 -
prefix_length
(Optional, integer) Number of beginning characters left unchanged when creating expansions. Defaults to
0
.(可选,整数)创建变体时保留不变的开始字符数。默认为
0
。 -
transpositions
(Optional, boolean) Indicates whether edits include transpositions of two adjacent characters (ab → ba). Defaults to
true
.(可选,布尔值)指示编辑是否包括两个相邻字符的置换(ab→ba)。默认为
true
。 -
rewrite
(Optional, string) Method used to rewrite the query. For valid values and more information, see the
rewrite
parameter.(可选,字符串)用于重写查询的方法。其有效值和更多信息,请参阅
rewrite
参数。