System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) · บทเรียน

Elasticsearch: การทำดัชนีและการค้นหา

เรียนรู้พื้นฐานของ Elasticsearch ซึ่งเป็นเครื่องมือค้นหาและวิเคราะห์ข้อมูลแบบกระจาย ทำความเข้าใจวิธีทำดัชนีเอกสารและดำเนินการค้นหาพื้นฐาน

บทเรียน 1 จาก 412 ขั้นตอน

Elasticsearch: การทำดัชนีและการค้นหา เป็นบทเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Welcome to Elasticsearch!

Welcome to the first lesson on the ELK Stack! We'll start with Elasticsearch, the 'E' in ELK.

Elasticsearch is a powerful, open-source distributed search and analytics engine. It's designed to store, search, and analyze large volumes of data quickly.

  • Distributed: Runs across multiple servers.
  • Real-time: Data is available for search almost instantly.
  • Scalable: Easily handles growing data needs.

Data as JSON Documents

Elasticsearch stores data as JSON documents. Think of a document as a single record, like a row in a database, but more flexible.

Each document is a collection of fields (key-value pairs) and can contain various data types, including text, numbers, dates, and even other JSON objects.

Here's a simple example of a document:

{"user": "alice", "message": "Hello CoddyKit!"}

Understanding Indices

In Elasticsearch, documents are organized into indices. An index is like a database in a relational database system, or a collection in a NoSQL database.

You can have multiple indices, and each index can store documents that are somewhat related. For example, you might have one index for 'logs' and another for 'products'.

  • An index is a logical namespace.
  • It groups similar documents.
  • You search within specific indices.

Indexing Your First Document

Indexing is the process of adding or updating documents in an Elasticsearch index. When you index a document, Elasticsearch stores it and makes it searchable.

Each document needs a unique ID within its index. If you don't provide one, Elasticsearch will generate it for you.

We use HTTP API calls, typically with PUT or POST requests, to interact with Elasticsearch.

Indexing a Document Example

Let's index a simple log document into an index called my_logs. We'll specify an ID of 1.

Try running this command (assuming Elasticsearch is running on localhost:9200):

curl -X PUT "localhost:9200/my_logs/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "timestamp": "2023-10-27T10:00:00Z",
  "level": "info",
  "message": "Application started successfully"
}'

Retrieving Documents by ID

Once a document is indexed, you can retrieve it using its unique ID. This is useful when you know exactly which document you want.

To retrieve a document, you send an HTTP GET request to the specific index and document ID endpoint.

This operation is very fast as Elasticsearch can directly fetch the document.

Retrieving a Document Example

Let's retrieve the document we just indexed with ID 1 from the my_logs index.

Run this command to see the stored document:

curl -X GET "localhost:9200/my_logs/_doc/1?pretty"

Introduction to Searching

The real power of Elasticsearch comes from its searching capabilities. Instead of knowing an ID, you often want to find documents based on their content.

You can search across all documents in an index (or multiple indices) using various query types. Elasticsearch uses a query language based on JSON.

  • Find documents by keywords.
  • Filter by date ranges or specific values.
  • Combine multiple search criteria.

Basic Search: Match All

The simplest search query is the match_all query. It returns all documents in the specified index.

This is often used to verify that documents are indexed correctly or as a starting point for more complex queries.

You send an HTTP GET request to the _search endpoint of your index.

Match All Query Example

Let's search for all documents in our my_logs index. You'll see the document we indexed earlier.

Run this command:

curl -X GET "localhost:9200/my_logs/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "match_all": {}
  }
}'

Quick Check on Indexing

You've learned about documents, indices, and how to index and retrieve data. Let's test your understanding of indexing.

Recap: Indexing and Basic Search

Great job! In this lesson, you've learned the fundamentals of Elasticsearch:

  • Elasticsearch is a distributed search and analytics engine.
  • Data is stored as JSON documents.
  • Documents are organized into indices.
  • Indexing adds or updates documents using PUT/POST requests.
  • Documents can be retrieved by ID using GET requests.
  • Basic searching can be done with queries like match_all.

Next, we'll dive deeper into Logstash, the 'L' in ELK, to ingest and process data!

เริ่มต้นได้ฟรี

เรียนรู้ System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “Elasticsearch: การทำดัชนีและการค้นหา” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “Elasticsearch: การทำดัชนีและการค้นหา” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “Elasticsearch: การทำดัชนีและการค้นหา”

เรียนรู้พื้นฐานของ Elasticsearch ซึ่งเป็นเครื่องมือค้นหาและวิเคราะห์ข้อมูลแบบกระจาย ทำความเข้าใจวิธีทำดัชนีเอกสารและดำเนินการค้นหาพื้นฐาน คุณปฏิบัติ System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “Elasticsearch: การทำดัชนีและการค้นหา” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) นี้ได้ไหม

ได้ บทเรียน System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. Elasticsearch: การทำดัชนีและการค้นหา
  2. Logstash: การรับและประมวลผลข้อมูล
  3. Kibana: การแสดงผลและแดชบอร์ด
  4. Beats: ตัวส่งข้อมูลขนาดเล็ก
← กลับไปที่ System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)