Query DSL - Regexp Query

Regexp Query

Returns documents that contain terms matching a regular expression.

返回包含与正则表达式匹配的词条的文档 。

A regular expression is a way to match patterns in data using placeholder characters, called operators. For a list of operators supported by the regexp query, see Regular expression syntax.

正则表达式是一种使用占位符匹配数据中的模式的方法,也称为正则运算。regexp查询支持的运算符的列表 ,请参见正则表达式语法

Example request

The following search returns documents where the user field contains any term that begins with k and ends with y. The .* operators match any characters of any length, including no characters. Matching terms can include ky, kay, and kimchy.

下面的搜索返回user字段包含以k开头以y结尾的词条的文档。.*运算符匹配任意长度的任意字符,包括无字符。匹配的词条可以包括kykay,和kimchy

GET /_search
{
    "query": {
        "regexp": {
            "user": {
                "value": "k.*y",
                "flags" : "ALL",
                "max_determinized_states": 10000,
                "rewrite": "constant_score"
            }
        }
    }
}

Copy as cURLView in Console

Top-level parameters for regexp

regexp的一级参数

  • field

    (Required, object) Field you wish to search.

    (必填,对象)您要搜索的字段。

Parameters for field

  • value

    (Required, string) Regular expression for terms you wish to find in the provided field. For a list of supported operators, see Regular expression syntax.

    (必需,字符串)为 field中词条准备的正则表达式。支持的运算符的列表,请参见正则表达式语法

    By default, regular expressions are limited to 1,000 characters. You can change this limit using the index.max_regex_length setting.

    默认情况下,正则表达式限制为1,000个字符。您可以使用index.max_regex_length 设置更改此限制。

    The performance of the regexp query can vary based on the regular expression provided. To improve performance, avoid using wildcard patterns, such as .* or .*?+, without a prefix or suffix.

    警告:regexp查询的性能可以根据提供的正则表达式而有所不同。为了提高性能,应避免使用没有前缀或后缀的通配符模式,如.*.*?+

  • flags

    (Optional, string) Enables optional operators for the regular expression. For valid values and more information, see Regular expression syntax.

    (可选,字符串)为正则表达式启用可选运算符。其有效值和更多信息,请参见正则表达式语法

  • max_determinized_states

    (Optional, integer) Maximum number of automaton states required for the query. Default is 10000.

    (可选,整数) 查询所需的automaton states最大数量 。默认值为10000

    Elasticsearch uses Apache Lucene internally to parse regular expressions. Lucene converts each regular expression to a finite automaton containing a number of determinized states.

    Elasticsearch在内部使用Apache Lucene解析正则表达式。Lucene将每个正则表达式转换为包含许多确定状态的有限自动机。

    You can use this parameter to prevent that conversion from unintentionally consuming too many resources. You may need to increase this limit to run complex regular expressions.

    您可以使用此参数来防止该转换无意中消耗过多的资源。您可能需要增加此限制去运行复杂的正则表达式。

  • rewrite

    (Optional, string) Method used to rewrite the query. For valid values and more information, see the rewrite parameter.

    (可选,字符串)用于重写查询的方法。其有效值和更多信息,请参阅rewrite参数

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值