Query DSL - Fuzzy Query

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 the max_expansions parameter, especially if the prefix_length parameter value is 0. High values in the max_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参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值