本地英文版地址: ../en/query-dsl-match-query.html
返回与提供的文本、数字、日期或布尔值相 匹配(match) 的文档。 匹配前会分析提供的文本。
match
查询是执行全文搜索的标准查询,包括一些 模糊(fuzzy) 匹配选项。
-
query
-
(必需的) 你希望在提供的
<field>
中查找的文本(text)、数字(number)、布尔值(bool)或日期(date)。match
查询会在执行搜索前 analyzes 任何提供的文本。 这意味着match
查询可以在text
字段中搜索已分析的 词元(token),而不是精确的 词项(term)。 -
analyzer
-
(可选, string) analyzer(分析器) 用于将
query
中的文本转换为 词元(token)。 默认为映射到<field>
的 索引时使用的分析器(index-time analyzer)。 如果没有映射分析器,则使用索引的默认分析器。 -
auto_generate_synonyms_phrase_query
-
(可选, boolean) 如果为
true
,将自动为 多词项同义词(multi-term synonyms) 创建 match phrase(短语匹配) 查询。 默认值为true
。有关示例请参考 在match查询中使用同义词。
-
fuzziness
- (可选, string) 匹配时允许的最大编辑距离。 可用的值及更多信息请参考 模糊性(fuzziness)。 有关示例请参考 match查询中的模糊性。
-
max_expansions
-
(可选, integer) 查询可以扩展到的最大 词项(term) 数。默认值为
50
。 -
prefix_length
-
(可选, integer) 模糊匹配的起始字符保持不变的分数。默认值为
0
。 -
fuzzy_transpositions
-
(可选, boolean) 如果为
true
,模糊匹配的编辑包括两个相邻字符的交换(ab → ba)。默认值为true
。 -
fuzzy_rewrite
-
(可选, string) 用于重写查询的方法。 可用的值及更多信息请参考
rewrite
参数。如果参数
fuzziness
的值不是0
,默认情况下,match
查询使用的rewrite
方法是top_terms_blended_freqs_${max_expansions}
。 -
lenient
宽容的 -
(可选, boolean)
如果为
true
,则忽略基于格式的错误,例如为 numeric 字段提供 text 格式的query
值。 默认值为false
。 -
operator
-
(可选, string) 用于解释
query
值中文本的布尔逻辑。有效值有:-
OR
(默认值) -
例如,查询值
capital of Hungary
被解释为capital OR of OR Hungary
。 -
AND
-
例如,查询值
capital of Hungary
被解释为capital AND of AND Hungary
。
-
-
minimum_should_match
-
(可选, string) 要返回的文档必须匹配的最小子句数。 可用的值及更多信息请参考
minimum_should_match
参数。 -
zero_terms_query
-
(可选, string) 指示如果
analyzer
删除所有 词元(token) (例如使用stop
过滤器时),是否不返回任何文档。有效值有:-
none
(默认值) -
如果
analyzer
删除所有 词元(token),则不返回任何文档。 -
all
-
返回所有文档, 与
match_all
查询类似。
有关示例请参考 零词项查询(zero terms query)。
-
可以通过组合 <field>
和 query
参数来简化 match 查询语法。例如:
GET /_search { "query": { "match" : { "message" : "this is a test" } } }
match
查询属于 boolean
类型。
这意味着对所提供的文本进行分析,并且分析过程从所提供的文本中构造一个 boolean 查询。
参数 operator
可以设置为 or
或 and
,以控制 boolean 子句(默认为 or
)。
可以使用 minimum_should_match
参数设置要匹配的可选 should
子句的最小数量。
下面是一个带有 operator
参数的示例:
GET /_search { "query": { "match" : { "message" : { "query" : "this is a test", "operator" : "and" } } } }
可以设置 analyzer
来控制使用哪个分析器对文本执行分析过程。
它默认为字段的显式映射定义,或默认的搜索分析器。
可以将参数 lenient
设置为 true
,以忽略由数据类型不匹配导致的异常,例如尝试使用 text 查询字符串查询 numeric 字段。
默认值为 false
。
fuzziness
(模糊性) 允许基于被查询的字段类型进行模糊匹配。
有关允许的设置,请参考 模糊性。
在这种情况下,可以设置 prefix_length
和 max_expansions
来控制模糊处理过程。
如果设置了模糊选项,查询将使用 fuzzy_rewrite
参数允许的 top_terms_blended_freqs_${max_expansions}
作为其 重写方法(rewrite method) 去控制如何重写查询。
默认情况下允许模糊换位(ab
→ ba
),但可以通过将 fuzzy_transpositions
设置为 false
来禁用。
模糊匹配不适用于具有同义词的词项(term),也不适用于分析过程在同一位置产生多个词元(token)的情况。 在底层,这些词项(temr)被扩展为一个混合了词项频率的特殊同义词查询,它不支持模糊扩展。
GET /_search { "query": { "match" : { "message" : { "query" : "this is a testt", "fuzziness": "AUTO" } } } }
如果所使用的分析器像 stop
过滤器一样删除查询中的所有词元(token),那么默认行为是根本不匹配任何文档。
为了改变这种情况,可以使用 zero_terms_query
选项,它接受 none
(默认值) 和 all
(对应于 match_all
查询)。
GET /_search { "query": { "match" : { "message" : { "query" : "to be or not to be", "operator" : "and", "zero_terms_query": "all" } } } }
在 7.3.0 中废弃。
此选项可以省略,因为 匹配(match) 可以有效地跳过文档块,而无需任何配置,前提是不跟踪命中的总数。
匹配查询支持 cutoff_frequency
,它允许指定一个绝对或相对的文档频率,其中高频词项被移到可选的子查询中,并且只有在 or
运算符时有一个低频(低于截止值)词项匹配 或 and
运算符时所有低频词项都匹配 时才被计分。
该查询允许在运行时动态处理 stopwords
(停止词) ,它是独立于域(domain)的,并且不需要停止词文件。
它防止对高频词项进行评分/迭代,并且仅在更重要/更低频率的词项匹配文档时才考虑这些词项。
然而,如果所有查询项都高于给定的 cutoff_frequency
,则该查询会自动转换为纯的结合(and
)查询,以确保快速执行。
cutoff_frequency
的值,在 [0, 1) 范围内时是一个相对于文档总数的值,而在 >= 1.0 时是一个绝对值。
下面这个示例显示了一个全部由 停止词(stopword) 组成的查询:
GET /_search { "query": { "match" : { "message" : { "query" : "to be or not to be", "cutoff_frequency" : 0.001 } } } }
cutoff_frequency
选项在每个分片级别上执行。
这意味着当在文档数很少的测试索引上试用它时,你应该遵循“相关性被破坏”中的建议。
match
查询通过 synonym_graph 词元过滤器支持多词项的同义词扩展。
当使用这个过滤器时,解析器为每个多词项的同义词创建一个短语(phrase)查询。
例如,同义词 "ny, new york"
将产生:
(ny OR ("new york"))
也可以用连接词来匹配多个词项同义词:
GET /_search { "query": { "match" : { "message": { "query" : "ny city", "auto_generate_synonyms_phrase_query" : false } } } }
上面的例子创建了一个 boolean 查询:
(ny OR (new AND york)) city
它匹配带有词项 ny
或连接词 new AND york
的文档。
默认情况下,参数 auto_generate_synonyms_phrase_query
设置为 true
。
- Elasticsearch权威指南: 其他版本:
- Elasticsearch是什么?
- 7.7版本的新特性
- 开始使用Elasticsearch
- 安装和设置
- 升级Elasticsearch
- 搜索你的数据
- 查询领域特定语言(Query DSL)
- SQL access(暂时不翻译)
- Overview
- Getting Started with SQL
- Conventions and Terminology
- Security
- SQL REST API
- SQL Translate API
- SQL CLI
- SQL JDBC
- SQL ODBC
- SQL Client Applications
- SQL Language
- Functions and Operators
- Comparison Operators
- Logical Operators
- Math Operators
- Cast Operators
- LIKE and RLIKE Operators
- Aggregate Functions
- Grouping Functions
- Date/Time and Interval Functions and Operators
- Full-Text Search Functions
- Mathematical Functions
- String Functions
- Type Conversion Functions
- Geo Functions
- Conditional Functions And Expressions
- System Functions
- Reserved keywords
- SQL Limitations
- 聚合
- 度量(metric)聚合
- 桶(bucket)聚合
- adjacency_matrix 聚合
- auto_date_histogram 聚合
- children 聚合
- composite 聚合
- date_histogram 聚合
- date_range 聚合
- diversified_sampler 聚合
- filter 聚合
- filters 聚合
- geo_distance 聚合
- geohash_grid 聚合
- geotile_grid 聚合
- global 聚合
- histogram 聚合
- ip_range 聚合
- missing 聚合
- nested 聚合
- parent 聚合
- range 聚合
- rare_terms 聚合
- reverse_nested 聚合
- sampler 聚合
- significant_terms 聚合
- significant_text 聚合
- terms 聚合
- 给范围字段分桶的微妙之处
- 管道(pipeline)聚合
- 矩阵(matrix)聚合
- 重度缓存的聚合
- 只返回聚合的结果
- 聚合元数据
- Returning the type of the aggregation
- 使用转换对聚合结果进行索引
- 脚本
- 映射
- 删除的映射类型
- 字段数据类型
- alias(别名)
- array(数组)
- binary(二进制)
- boolean(布尔)
- date(日期)
- date_nanos(日期纳秒)
- dense_vector(密集矢量)
- histogram(直方图)
- flattened(扁平)
- geo_point(地理坐标点)
- geo_shape(地理形状)
- IP
- join(联结)
- keyword(关键词)
- nested(嵌套)
- numeric(数值)
- object(对象)
- percolator(渗透器)
- range(范围)
- rank_feature(特征排名)
- rank_features(特征排名)
- search_as_you_type(输入即搜索)
- Sparse vector
- Text
- Token count
- Shape
- Constant keyword
- Meta-Fields
- Mapping parameters
- Dynamic Mapping
- Text analysis
- Overview
- Concepts
- Configure text analysis
- Built-in analyzer reference
- Tokenizer reference
- Char Group Tokenizer
- Classic Tokenizer
- Edge n-gram tokenizer
- Keyword Tokenizer
- Letter Tokenizer
- Lowercase Tokenizer
- N-gram tokenizer
- Path Hierarchy Tokenizer
- Path Hierarchy Tokenizer Examples
- Pattern Tokenizer
- Simple Pattern Tokenizer
- Simple Pattern Split Tokenizer
- Standard Tokenizer
- Thai Tokenizer
- UAX URL Email Tokenizer
- Whitespace Tokenizer
- Token filter reference
- Apostrophe
- ASCII folding
- CJK bigram
- CJK width
- Classic
- Common grams
- Conditional
- Decimal digit
- Delimited payload
- Dictionary decompounder
- Edge n-gram
- Elision
- Fingerprint
- Flatten graph
- Hunspell
- Hyphenation decompounder
- Keep types
- Keep words
- Keyword marker
- Keyword repeat
- KStem
- Length
- Limit token count
- Lowercase
- MinHash
- Multiplexer
- N-gram
- Normalization
- Pattern capture
- Pattern replace
- Phonetic
- Porter stem
- Predicate script
- Remove duplicates
- Reverse
- Shingle
- Snowball
- Stemmer
- Stemmer override
- Stop
- Synonym
- Synonym graph
- Trim
- Truncate
- Unique
- Uppercase
- Word delimiter
- Word delimiter graph
- Character filters reference
- Normalizers
- Index modules
- Ingest node
- Pipeline Definition
- Accessing Data in Pipelines
- Conditional Execution in Pipelines
- Handling Failures in Pipelines
- Enrich your data
- Processors
- Append Processor
- Bytes Processor
- Circle Processor
- Convert Processor
- CSV Processor
- Date Processor
- Date Index Name Processor
- Dissect Processor
- Dot Expander Processor
- Drop Processor
- Enrich Processor
- Fail Processor
- Foreach Processor
- GeoIP Processor
- Grok Processor
- Gsub Processor
- HTML Strip Processor
- Inference Processor
- Join Processor
- JSON Processor
- KV Processor
- Lowercase Processor
- Pipeline Processor
- Remove Processor
- Rename Processor
- Script Processor
- Set Processor
- Set Security User Processor
- Split Processor
- Sort Processor
- Trim Processor
- Uppercase Processor
- URL Decode Processor
- User Agent processor
- ILM: Manage the index lifecycle
- Monitor a cluster
- Frozen indices
- Roll up or transform your data
- Set up a cluster for high availability
- Snapshot and restore
- Secure a cluster
- Overview
- Configuring security
- User authentication
- Built-in users
- Internal users
- Token-based authentication services
- Realms
- Realm chains
- Active Directory user authentication
- File-based user authentication
- LDAP user authentication
- Native user authentication
- OpenID Connect authentication
- PKI user authentication
- SAML authentication
- Kerberos authentication
- Integrating with other authentication systems
- Enabling anonymous access
- Controlling the user cache
- Configuring SAML single-sign-on on the Elastic Stack
- Configuring single sign-on to the Elastic Stack using OpenID Connect
- User authorization
- Built-in roles
- Defining roles
- Security privileges
- Document level security
- Field level security
- Granting privileges for indices and aliases
- Mapping users and groups to roles
- Setting up field and document level security
- Submitting requests on behalf of other users
- Configuring authorization delegation
- Customizing roles and authorization
- Enabling audit logging
- Encrypting communications
- Restricting connections with IP filtering
- Cross cluster search, clients, and integrations
- Tutorial: Getting started with security
- Tutorial: Encrypting communications
- Troubleshooting
- Some settings are not returned via the nodes settings API
- Authorization exceptions
- Users command fails due to extra arguments
- Users are frequently locked out of Active Directory
- Certificate verification fails for curl on Mac
- SSLHandshakeException causes connections to fail
- Common SSL/TLS exceptions
- Common Kerberos exceptions
- Common SAML issues
- Internal Server Error in Kibana
- Setup-passwords command fails due to connection failure
- Failures due to relocation of the configuration files
- Limitations
- Alerting on cluster and index events
- Command line tools
- How To
- Glossary of terms
- REST APIs
- API conventions
- cat APIs
- cat aliases
- cat allocation
- cat anomaly detectors
- cat count
- cat data frame analytics
- cat datafeeds
- cat fielddata
- cat health
- cat indices
- cat master
- cat nodeattrs
- cat nodes
- cat pending tasks
- cat plugins
- cat recovery
- cat repositories
- cat shards
- cat segments
- cat snapshots
- cat task management
- cat templates
- cat thread pool
- cat trained model
- cat transforms
- Cluster APIs
- Cluster allocation explain
- Cluster get settings
- Cluster health
- Cluster reroute
- Cluster state
- Cluster stats
- Cluster update settings
- Nodes feature usage
- Nodes hot threads
- Nodes info
- Nodes reload secure settings
- Nodes stats
- Pending cluster tasks
- Remote cluster info
- Task management
- Voting configuration exclusions
- Cross-cluster replication APIs
- Document APIs
- Enrich APIs
- Explore API
- Index APIs
- Add index alias
- Analyze
- Clear cache
- Clone index
- Close index
- Create index
- Delete index
- Delete index alias
- Delete index template
- Flush
- Force merge
- Freeze index
- Get field mapping
- Get index
- Get index alias
- Get index settings
- Get index template
- Get mapping
- Index alias exists
- Index exists
- Index recovery
- Index segments
- Index shard stores
- Index stats
- Index template exists
- Open index
- Put index template
- Put mapping
- Refresh
- Rollover index
- Shrink index
- Split index
- Synced flush
- Type exists
- Unfreeze index
- Update index alias
- Update index settings
- Index lifecycle management API
- Ingest APIs
- Info API
- Licensing APIs
- Machine learning anomaly detection APIs
- Add events to calendar
- Add jobs to calendar
- Close jobs
- Create jobs
- Create calendar
- Create datafeeds
- Create filter
- Delete calendar
- Delete datafeeds
- Delete events from calendar
- Delete filter
- Delete forecast
- Delete jobs
- Delete jobs from calendar
- Delete model snapshots
- Delete expired data
- Estimate model memory
- Find file structure
- Flush jobs
- Forecast jobs
- Get buckets
- Get calendars
- Get categories
- Get datafeeds
- Get datafeed statistics
- Get influencers
- Get jobs
- Get job statistics
- Get machine learning info
- Get model snapshots
- Get overall buckets
- Get scheduled events
- Get filters
- Get records
- Open jobs
- Post data to jobs
- Preview datafeeds
- Revert model snapshots
- Set upgrade mode
- Start datafeeds
- Stop datafeeds
- Update datafeeds
- Update filter
- Update jobs
- Update model snapshots
- Machine learning data frame analytics APIs
- Create data frame analytics jobs
- Create inference trained model
- Delete data frame analytics jobs
- Delete inference trained model
- Evaluate data frame analytics
- Explain data frame analytics API
- Get data frame analytics jobs
- Get data frame analytics jobs stats
- Get inference trained model
- Get inference trained model stats
- Start data frame analytics jobs
- Stop data frame analytics jobs
- Migration APIs
- Reload search analyzers
- Rollup APIs
- Search APIs
- Security APIs
- Authenticate
- Change passwords
- Clear cache
- Clear roles cache
- Create API keys
- Create or update application privileges
- Create or update role mappings
- Create or update roles
- Create or update users
- Delegate PKI authentication
- Delete application privileges
- Delete role mappings
- Delete roles
- Delete users
- Disable users
- Enable users
- Get API key information
- Get application privileges
- Get builtin privileges
- Get role mappings
- Get roles
- Get token
- Get users
- Has privileges
- Invalidate API key
- Invalidate token
- OpenID Connect Prepare Authentication API
- OpenID Connect authenticate API
- OpenID Connect logout API
- SAML prepare authentication API
- SAML authenticate API
- SAML logout API
- SAML invalidate API
- SSL certificate
- Snapshot and restore APIs
- Snapshot lifecycle management API
- Transform APIs
- Usage API
- Watcher APIs
- Definitions
- Breaking changes
- Release notes
- Elasticsearch version 7.7.1
- Elasticsearch version 7.7.0
- Elasticsearch version 7.6.2
- Elasticsearch version 7.6.1
- Elasticsearch version 7.6.0
- Elasticsearch version 7.5.2
- Elasticsearch version 7.5.1
- Elasticsearch version 7.5.0
- Elasticsearch version 7.4.2
- Elasticsearch version 7.4.1
- Elasticsearch version 7.4.0
- Elasticsearch version 7.3.2
- Elasticsearch version 7.3.1
- Elasticsearch version 7.3.0
- Elasticsearch version 7.2.1
- Elasticsearch version 7.2.0
- Elasticsearch version 7.1.1
- Elasticsearch version 7.1.0
- Elasticsearch version 7.0.0
- Elasticsearch version 7.0.0-rc2
- Elasticsearch version 7.0.0-rc1
- Elasticsearch version 7.0.0-beta1
- Elasticsearch version 7.0.0-alpha2
- Elasticsearch version 7.0.0-alpha1