CRUD-Operationen mit Dokumenten
Beherrschen Sie die Create-, Read-, Update- und Delete-Operationen für Dokumente mithilfe der REST API von Elasticsearch, einschließlich partieller Aktualisierungen.
CRUD-Operationen mit Dokumenten ist eine kostenlose Elasticsearch & Full Text Search Systems-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Elasticsearch & Full Text Search Systems-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Elasticsearch & Full Text Search Systems-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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/101Full 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/101Quick 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) orPOST(auto ID). - Read (Get): Retrieve documents by ID using
GET. - Update: Replace documents entirely with
PUTor perform efficient partial updates withPOST /_update. - Delete: Remove documents by ID using
DELETE.
These operations form the backbone of interacting with your Elasticsearch data.
Häufig gestellte Fragen
Ist die Lektion „CRUD-Operationen mit Dokumenten“ kostenlos?
Ja — der vollständige Text von „CRUD-Operationen mit Dokumenten“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Elasticsearch & Full Text Search Systems-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Elasticsearch & Full Text Search Systems-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „CRUD-Operationen mit Dokumenten“?
Beherrschen Sie die Create-, Read-, Update- und Delete-Operationen für Dokumente mithilfe der REST API von Elasticsearch, einschließlich partieller Aktualisierungen. Du übst Elasticsearch & Full Text Search Systems mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Elasticsearch & Full Text Search Systems zu starten?
Keine Vorkenntnisse erforderlich. Elasticsearch & Full Text Search Systems auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „CRUD-Operationen mit Dokumenten“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Elasticsearch & Full Text Search Systems-Lektion Code schreiben und ausführen?
Ja. Jede Elasticsearch & Full Text Search Systems-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Dokumente in Elasticsearch indexieren
- CRUD-Operationen mit Dokumenten
- Grundlagen von Mappings und Datentypen
- Massenindizierung und die Bulk API