0
0
ElasticsearchConceptBeginner · 3 min read

What is Document in Elasticsearch: Definition and Examples

In Elasticsearch, a document is a basic unit of information that can be indexed and searched. It is a JSON object that contains fields with data, similar to a row in a database table but more flexible and schema-free.
⚙️

How It Works

Think of a document in Elasticsearch like a single page in a large book. Each page (document) holds information about one item, such as a product, a user, or an article. Unlike traditional databases where rows have fixed columns, Elasticsearch documents are JSON objects that can have different fields and structures.

When you add a document to Elasticsearch, it is stored in an index and made searchable. Elasticsearch breaks down the document's fields into terms and builds an inverted index, which helps quickly find documents matching search queries. This process is similar to how a library catalog helps you find books by keywords.

💻

Example

This example shows a simple Elasticsearch document representing a book with fields like title, author, and year.

json
{
  "title": "The Great Gatsby",
  "author": "F. Scott Fitzgerald",
  "year": 1925
}
🎯

When to Use

Use documents in Elasticsearch when you need to store and search flexible, structured data quickly. They are ideal for applications like product catalogs, user profiles, logs, or articles where you want fast full-text search and filtering.

For example, an online store can store each product as a document with fields like name, description, price, and category. Elasticsearch then allows customers to search and filter products instantly.

Key Points

  • A document is a JSON object representing a single item of data.
  • Documents are stored in indexes and are searchable.
  • They are flexible and can have different fields in each document.
  • Documents enable fast and powerful search capabilities in Elasticsearch.

Key Takeaways

A document is the basic searchable unit in Elasticsearch, stored as a JSON object.
Documents are flexible and can have different fields, unlike fixed database rows.
They are indexed to enable fast full-text search and filtering.
Use documents to represent items like products, users, or articles in search applications.