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
结尾的词条的文档。.*
运算符匹配任意长度的任意字符,包括无字符。匹配的词条可以包括ky
,kay
,和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
参数。