A document is Elasticsearch’s basic unit of stored information: a JSON object indexed into a logical collection called an index. A document models one business item, such as a book, news article, student, product, or event. Its fields hold the values that Elasticsearch analyzes for search and analytics. section 3.2.1 section 3.1.2
JSON represents data with quoted field names and typed values such as strings, integers, and booleans. Documents can contain nested objects, letting related values stay together; a student’s address, for example, can be an object inside the student document. During indexing, Elasticsearch parses the JSON and applies the index’s mapping rules to convert values into suitable types for analysis and storage. section 3.2.1
Listing 2.1 Indexing a book document into the books index
PUT books/_doc/1 #1
{ #2
"title":"Effective Java", #2
"author":"Joshua Bloch", #2
"release_date":"2001-06-01", #2
"amazon_rating":4.7, #2
"best_seller":true, #2
"prices": { #2
"usd":9.95, #2
"gbp":7.95, #2
"eur":8.95 #2
} #2
}
Index a book document by sending a PUT request to an index, the _doc endpoint, and an ID. The JSON request body becomes the document; title, author, date, rating, boolean, and nested prices are its fields. section 2.1.2
Retrieve a document by ID
After indexing a document, retrieve it with GET books/_doc/1. The response includes the original JSON under _source plus metadata such as the index, ID, found status, and version. Use GET books/_source/1 when only the original document is needed. section 2.2.2
Documents support operations at different scales:
- Use single-document APIs to index, fetch, update, or delete an individual item, such as an order or tweet. section 5.0
- Use multi-document and query-based APIs for batch imports, matching updates or deletes, and reindexing between indexes. section 5.0
- Expect text analysis before storage; it prepares document data for full-text search, analytics, and relevance features. section 5.1
A document ID is essential for direct retrieval. IDs may be supplied by the client or generated by Elasticsearch. For several known IDs, use an ids query through _search; use _search without criteria to retrieve all documents in an index. For large imports, prefer the _bulk API rather than operating one document at a time. section 2.2.2 section 5.0







