同步操作将从 Hutool/elasticsearch-definitive-guide-cn 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
match
queryThe match
query is the ``go-to'' query — the first query that you should
reach for whenever you need to query any field. It is a high-level full-text
query meaning that it knows how to deal with both full-text fields and exact-
value fields.
That said, the main use case for the match
query is for full text search. So
let’s take a look at how full text search works with a simple example.
First, we’ll create a new index and index some documents using the
bulk
API:
DELETE /my_index (1)
PUT /my_index
{ "settings": { "number_of_shards": 1 }} (2)
POST /my_index/my_type/_bulk
{ "index": { "_id": 1 }}
{ "title": "The quick brown fox" }
{ "index": { "_id": 2 }}
{ "title": "The quick brown fox jumps over the lazy dog" }
{ "index": { "_id": 3 }}
{ "title": "The quick brown fox jumps over the quick dog" }
{ "index": { "_id": 4 }}
{ "title": "Brown fox brown dog" }
Delete the index in case it already exists.
Later on, in [relevance-is-broken], we will explain why we created this index with only one primary shard.
Our first example explains what happens when we use the match
query to
search within a full-text field for a single word:
GET /my_index/my_type/_search
{
"query": {
"match": {
"title": "QUICK!"
}
}
}
Elasticsearch executes the above match
query as follows:
Check the field type
The title
field is a full-text (analyzed
) string
field, which means that
the query string should be analyzed too.
Analyze the query string
The query string "QUICK!"
is passed through the standard analyzer which
results in the single term "quick"
. Because we have a just a single term,
the match
query can be executed as a single low-level term
query.
Find matching docs
The term
query looks up "quick"
in the inverted index and retrieves the
list of documents that contain that term, in this case documents 1
, 2
, and
3
.
Score each doc
The term
query calculates the relevance _score
for each matching document,
by combining the term frequency (how often "quick"
appears in the title
field of each document), with the inverse document frequency (how often
"quick"
appears in the title
field in all documents in the index), and the
length of each field (shorter fields are considered more relevant).
See [relevance-intro].
This process gives us the following (abbreviated) results:
"hits": [
{
"_id": "3",
"_score": 0.53033006, (1)
"_source": {
"title": "The quick brown fox jumps over the quick dog"
}
},
{
"_id": "1",
"_score": 0.5, (2)
"_source": {
"title": "The quick brown fox"
}
},
{
"_id": "2",
"_score": 0.375, (2)
"_source": {
"title": "The quick brown fox jumps over the lazy dog"
}
}
]
Doc 3
is most relevant because it contains the term "quick"
twice.
Doc 1
is more relevant than doc 2
because its title
field is shorter.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。