Elasticsearch 常见 Query 搜索
Elasticsearch 常见 Query 搜索,部分内容来自 B 站中华石杉 Elasticsearch 顶尖高手系列课程核心知识篇,英文内容来自官方文档。
match all
The most simple query, which matches all documents, giving them all a _score of 1.0
The _score can be changed with the boost parameter:
Match None Query
This is the inverse of the match_all query, which matches no document
Full text queries
The full text query enable you to search analyzed text fields such as the body of an email. The query string is processed using the same analyzer that was applied to the field during indexing.
match
Returns documents that match a provided text, number, date or boolean value. The provided text is analyzed before matching.
The match query is the standard query for performing a full-text search, include options for fuzzy matching.
The match query is of type boolean. It means that the text provided is analyzed and the analysis process constructs a boolean query from the provided text.
The operator parameter can be set to or or and to control the boolean clauses (defaults to or).
之前的查询可以查到 7 条数据,修改为 and 之后,就一条也没有了。
multi match
The multi_match query builds on the match query to allow multi-field queries:
fields and per-field boosting
Fields can be specified with wildcards.
individual fields can be boosted with the caret(^) notation
If no fields are provided, the multi_match query defaults to the index.query.default_field index settings, which in turn defaults to *.* extracts all fields in the mapping that are eligible to term queries and filters the metadata fields. All extracted fields are then combined to build a query.
There is a limit on the number of fields that can be queried at once. It is defined by the indices.query.bool.max_clause_count Search settings which defaults to 1024.
Term-level queries
You can use term-level queries to find documents based on precise values in structured data.
Term-level queries do not analyze search terms, it match the exact terms stored in a field.
Term-level queries still normalize search terms for keyword fields with the normalizer property.
Types of term-level queries
exists query
fuzzy query
ids query
prefix query
range query
regexp query
term query
terms query
type query
wildcard query
range query
Return documents that contain terms within a provided range.
Using the range query with date fields
Example query using time_zone parameter
Term query
Returns documents that contain an exact term in a provided field.
You can use the term query to find document based on a precise value such as a price, a product ID, or a username.
Avoid using the term query for text fields.
To search text field values, use the match query instead.
Terms query
Returns documents that contain one or more exact terms in a provided field.
The terms query is the same as the term query, except you can search for multiple values.
Terms lookup
Terms lookup fetches the field values of an existing document. Elasticsearch then uses those values as search terms. This can be helpful when searching for a large set of terms.
exist query
Returns documents that contain an indexed value for a field.
Find documents missing indexed values
To find documents that are missing an indexed value for a field, use the must_not boolean query with the exists query.
版权声明: 本文为 InfoQ 作者【escray】的原创文章。
原文链接:【http://xie.infoq.cn/article/7307d6d59b011e0504ce41c51】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
评论