Indexing Data and Document Management 🔍
Data in Elasticsearch is stored as JSON documents within indexes. To index a document:
Using REST API:
PUT /my_index/_doc/1
{
"name": "Jane Doe",
"age": 30,
"roles": ["admin", "user"]
}
This creates a document with ID 1 inside my_index
. It's important to understand the structure:
| Field | Type | Description |
|---------|---------|--------------|
| name | text | User's name |
| age | integer | User's age |
| roles | array | User roles |
Elasticsearch automatically creates an index if it doesn’t exist during indexing, but predefining index mappings helps optimize search relevance and performance.