Grundlagen von Mappings und Datentypen
Lernen Sie das Konzept von Mappings kennen, erfahren Sie, wie Elasticsearch Datentypen ableitet, und definieren Sie einfache explizite Mappings für Ihre Felder.
Grundlagen von Mappings und Datentypen ist eine kostenlose Elasticsearch & Full Text Search Systems-Lektion auf CoddyKit. Dies ist Lektion 3 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.
Mapping: Your Data's Blueprint
When you put data into Elasticsearch, it needs to understand what kind of data each piece is. This is where mapping comes in.
Mapping is like a schema that defines the fields in your documents and their data types, such as text, numbers, or dates.
Why Mapping Matters
Think of mapping as a blueprint for your search engine. It tells Elasticsearch:
- How to store each field
- How to index (prepare for search) each field
- How each field can be searched and analyzed
Without proper mapping, your searches might not work as expected!
Dynamic Mapping: Elasticsearch's Guess
Elasticsearch is smart! If you index a document without defining a mapping first, it tries to guess the data type for each field. This is called dynamic mapping.
It's convenient for quick starts, but not always ideal for precise control over your data.
Dynamic Mapping Example
Let's see dynamic mapping in action. We'll index a document into a new index called my_books. Elasticsearch will automatically create the index and guess the field types.
PUT /my_books/_doc/1
{
"title": "The Art of Search",
"author": "Jane Doe",
"published_year": 2023,
"is_available": true,
"pages": 320
}Inspecting Dynamic Mappings
After indexing, we can retrieve the automatically generated mapping for my_books to see what data types Elasticsearch inferred for each field.
You'll see types like text, keyword, long, and boolean.
GET /my_books/_mappingLimitations of Dynamic Mapping
While handy, dynamic mapping has limits. For example, Elasticsearch might map a city name as text (for full-text search) when you really need it as a keyword (for exact filtering).
This can lead to inefficient searches or unexpected results. That's why explicit mapping is crucial.
Defining Explicit Mappings
Explicit mapping means you define the schema yourself before indexing documents. This gives you full control over how your data is stored and indexed.
You define mappings when you create an index, inside the mappings object, under properties.
PUT /my_custom_index
{
"mappings": {
"properties": {
"field_name": { "type": "data_type" }
}
}
}Common Data Types: Text & Keyword
Two fundamental types are text and keyword:
text: Used for full-text search (e.g., book descriptions). Text is analyzed, broken into words, and processed.keyword: Used for exact value matching, filtering, and sorting (e.g., product IDs, tags). Keywords are stored as-is.
Explicit Mapping Example: Text & Keyword
Here’s how you'd explicitly map a product_name for search and a product_id for exact filtering.
Notice how we create the index with the mapping before adding any documents.
PUT /products_v1
{
"mappings": {
"properties": {
"product_name": { "type": "text" },
"product_id": { "type": "keyword" }
}
}
}Quick Check: Choosing Data Types
You're building an Elasticsearch index for an e-commerce platform. Which data types would be most appropriate for the following fields to enable efficient searching and filtering?
Recap: Mastering Your Data's Structure
Great job! You've learned the basics of Elasticsearch mapping.
- Mapping defines the structure and types of your document fields.
- Dynamic mapping is Elasticsearch's auto-guessing feature.
- Explicit mapping gives you full control, letting you define types like
text(for search) andkeyword(for exact matches), and numeric types likeintegerandfloat.
Controlling your mappings is key to powerful and accurate search!
Häufig gestellte Fragen
Ist die Lektion „Grundlagen von Mappings und Datentypen“ kostenlos?
Ja — der vollständige Text von „Grundlagen von Mappings und Datentypen“ 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 „Grundlagen von Mappings und Datentypen“?
Lernen Sie das Konzept von Mappings kennen, erfahren Sie, wie Elasticsearch Datentypen ableitet, und definieren Sie einfache explizite Mappings für Ihre Felder. 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 3 von 4.
Wie lange dauert die Lektion „Grundlagen von Mappings und Datentypen“?
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