Elasticsearch & Full Text Search Systems · درس

عمليات CRUD باستخدام المستندات

أتقن عمليات إنشاء المستندات وقراءتها وتحديثها وحذفها باستخدام REST API الخاص بـ Elasticsearch، بما في ذلك التحديثات الجزئية.

الدرس 2 من 412 خطوة

عمليات CRUD باستخدام المستندات درس مجاني في Elasticsearch & Full Text Search Systems على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Elasticsearch & Full Text Search Systems، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Elasticsearch & Full Text Search Systems 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What are CRUD Operations?

In the world of data, CRUD is a fundamental concept. It stands for Create, Read, Update, and Delete.

These are the four basic operations you perform on data in any system, including Elasticsearch. Mastering them is key to managing your search documents effectively.

Indexing New Documents

Adding a new document to Elasticsearch is called indexing. You can index documents:

  • By letting Elasticsearch generate a unique ID (using POST).
  • By providing your own custom ID (using PUT).

The document content is sent as a JSON body.

Example: Indexing a Book

Let's index a book document. We'll use PUT and specify books/_doc/101 to give it a custom ID of 101.

PUT /books/_doc/101
{
  "title": "The Hitchhiker's Guide to the Galaxy",
  "author": "Douglas Adams",
  "year": 1979
}

Retrieving Documents

To fetch a document, you use the Get API. You just need to know its unique ID (_id) and the index it's in.

Elasticsearch will return the document's source (_source) along with metadata like its _index, _id, and _version.

Example: Getting Our Book

Now, let's retrieve the book we just indexed using its ID.

GET /books/_doc/101

Full Document Replacement

One way to update a document is to completely replace it. You use the PUT method with the same document ID.

Be careful! Any fields missing from your new PUT request will be deleted from the original document.

Example: Adding a Genre

Let's add a genre field to our book. Notice how we provide the full document again, including existing fields.

PUT /books/_doc/101
{
  "title": "The Hitchhiker's Guide to the Galaxy",
  "author": "Douglas Adams",
  "year": 1979,
  "genre": "Science Fiction"
}

Efficient Partial Updates

For small changes, fully replacing a document is inefficient. Elasticsearch provides the _update API for partial updates.

This allows you to send only the fields you want to change, making the operation faster and using less bandwidth. You use the POST method.

Example: Changing a Field

Let's update just the year field of our book using the _update API and the "doc" parameter. This merges the changes.

POST /books/_update/101
{
  "doc": {
    "year": 1980
  }
}

Removing Documents

To permanently remove a document from your index, you use the Delete API. Simply specify the index and the document's ID.

Once deleted, the document is gone and cannot be retrieved.

DELETE /books/_doc/101

Quick Check

You have a document with fields name, age, and city. You want to change only the city field to a new value. Which is the most efficient and recommended way to do this in Elasticsearch?

Recap: CRUD in Elasticsearch

Great job! You've learned the essential CRUD operations for managing documents in Elasticsearch:

  • Create (Index): Add new documents with PUT (custom ID) or POST (auto ID).
  • Read (Get): Retrieve documents by ID using GET.
  • Update: Replace documents entirely with PUT or perform efficient partial updates with POST /_update.
  • Delete: Remove documents by ID using DELETE.

These operations form the backbone of interacting with your Elasticsearch data.

البدء مجانًا

تعلم Elasticsearch & Full Text Search Systems مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «عمليات CRUD باستخدام المستندات» مجاني؟

نعم — نص درس «عمليات CRUD باستخدام المستندات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Elasticsearch & Full Text Search Systems، انتقل إلى CoddyKit PRO. تتضمن دورة Elasticsearch & Full Text Search Systems 4 دروس في المجموع.

ماذا ستتعلم في «عمليات CRUD باستخدام المستندات»؟

أتقن عمليات إنشاء المستندات وقراءتها وتحديثها وحذفها باستخدام REST API الخاص بـ Elasticsearch، بما في ذلك التحديثات الجزئية. تتمرن على Elasticsearch & Full Text Search Systems مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Elasticsearch & Full Text Search Systems؟

لا تُشترط خبرة سابقة. Elasticsearch & Full Text Search Systems على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «عمليات CRUD باستخدام المستندات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Elasticsearch & Full Text Search Systems هذا؟

نعم. كل درس في Elasticsearch & Full Text Search Systems يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. فهرسة المستندات في Elasticsearch
  2. عمليات CRUD باستخدام المستندات
  3. أساسيات التخطيط وأنواع البيانات
  4. الفهرسة الدفعية وواجهة Bulk API
← العودة إلى Elasticsearch & Full Text Search Systems