การเพิ่มน้ำหนักและการให้คะแนนความเกี่ยวข้อง
เรียนรู้เทคนิคการปรับคะแนนความเกี่ยวข้องของเอกสารโดยใช้การเพิ่มน้ำหนักให้คำค้น ฟิลด์ และฟังก์ชันให้คะแนนที่กำหนดเอง
การเพิ่มน้ำหนักและการให้คะแนนความเกี่ยวข้อง เป็นบทเรียน Elasticsearch & Full Text Search Systems ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Elasticsearch & Full Text Search Systems และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Why Relevancy Matters
When you search for something, you don't just want any results; you want the best results. This is where relevancy comes in!
Relevancy helps search engines, like Elasticsearch, decide which documents are most important or 'relevant' to your query and present them first.
Meet the _score
In Elasticsearch, every document that matches your search query gets a numeric value called the _score. This score represents how relevant that document is to your query.
- A higher
_scoremeans the document is considered more relevant. - Elasticsearch uses algorithms (like BM25) to calculate this score, considering factors like how often a term appears and its uniqueness.
Introduction to Boosting
While Elasticsearch calculates relevancy automatically, you often want to guide it. This is where boosting comes in!
Boosting allows you to manually increase or decrease the importance of specific query clauses or fields, directly influencing the _score of matching documents.
Boosting Entire Queries
You can apply a boost parameter to an entire query clause. A boost value greater than 1.0 increases its impact, while a value less than 1.0 decreases it.
The default boost value is 1.0, meaning no special emphasis.
Query Boost in Action
Let's say you're searching for 'coding' and want matches in the description field to be twice as important as other parts of your query.
You can add "boost": 2 to that specific match clause:
GET /my_index/_search
{
"query": {
"match": {
"description": {
"query": "coding",
"boost": 2
}
}
}
}Prioritizing Specific Fields
Often, a match in one field is inherently more valuable than a match in another. For example, finding a keyword in a document's title is usually more relevant than finding it in its content.
Field boosting lets you specify this importance directly within your query.
Field Boost Example
Using the ^ (caret) operator after a field name, you can assign a boost factor. Here, a match in title is 3 times more important than a match in description:
GET /my_index/_search
{
"query": {
"multi_match": {
"query": "quick brown fox",
"fields": [ "title^3", "description^1" ]
}
}
}Beyond Simple Boosting
For even more control over relevancy, Elasticsearch offers the function_score query. This powerful query type allows you to apply custom scoring logic to documents.
You can factor in things like a document's popularity, recency, or specific numeric field values to influence its _score.
function_score Basic Example
Here's a simple function_score example. It searches for 'elastic' and then boosts the score based on the views_count field, multiplying the base score by a factor derived from views_count.
GET /my_index/_search
{
"query": {
"function_score": {
"query": { "match": { "text": "elastic" } },
"field_value_factor": {
"field": "views_count",
"factor": 1.2,
"modifier": "log1p",
"missing": 1
},
"boost_mode": "multiply"
}
}
}Boost Your Knowledge!
Test your understanding of boosting and relevancy in Elasticsearch!
Relevancy Tuned!
Great job! You've learned how to take control of relevancy in Elasticsearch.
- The
_scoredictates a document's importance. - Query boosting lets you emphasize entire query clauses.
- Field boosting prioritizes matches in specific fields.
- The
function_scorequery provides advanced, custom relevancy adjustments.
By using these techniques, you can ensure your users always find the most relevant information first!
คำถามที่พบบ่อย
บทเรียน “การเพิ่มน้ำหนักและการให้คะแนนความเกี่ยวข้อง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การเพิ่มน้ำหนักและการให้คะแนนความเกี่ยวข้อง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Elasticsearch & Full Text Search Systems ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การเพิ่มน้ำหนักและการให้คะแนนความเกี่ยวข้อง”
เรียนรู้เทคนิคการปรับคะแนนความเกี่ยวข้องของเอกสารโดยใช้การเพิ่มน้ำหนักให้คำค้น ฟิลด์ และฟังก์ชันให้คะแนนที่กำหนดเอง คุณปฏิบัติ Elasticsearch & Full Text Search Systems ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Elasticsearch & Full Text Search Systems หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Elasticsearch & Full Text Search Systems บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “การเพิ่มน้ำหนักและการให้คะแนนความเกี่ยวข้อง” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Elasticsearch & Full Text Search Systems นี้ได้ไหม
ได้ บทเรียน Elasticsearch & Full Text Search Systems ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ตัววิเคราะห์ ตัวแยกโทเค็น และตัวกรอง
- การปรับแต่งตัววิเคราะห์ข้อความ
- การเพิ่มน้ำหนักและการให้คะแนนความเกี่ยวข้อง
- คำพ้องความหมายและการลดรูปคำ