In Elasticsearch, a document is the basic unit of information that can be indexed and searched. A document is a JSON object that contains one or more fields, each of which contains a value. Here’s how a document works in Elasticsearch:
1. Creation of a document: To index a document in Elasticsearch, you send a PUT request to the index API with the JSON object as the request body. Elasticsearch automatically creates the index and stores the document in the index.
2. Storage and indexing of data: When you index a document in Elasticsearch, it is stored on one or more data nodes in the cluster. Elasticsearch automatically manages the distribution of the data across the nodes, ensuring that each node has a balanced workload and that data is replicated for redundancy.
3. Search and retrieval of data: When you perform a search in Elasticsearch, the search request is sent to one of the data nodes in the cluster, which coordinates the search across all the data nodes in the cluster. Elasticsearch searches through the indexed documents and returns the matching documents to the user.
4. Updating and deleting documents: You can update or delete a document in Elasticsearch by sending a POST or DELETE request to the index API with the document ID and the updated JSON object or a delete command. Elasticsearch automatically updates or deletes the document and reindexes the data.
5. Mapping and analysis of data: Elasticsearch automatically maps the fields in a document based on their data type, allowing you to search and filter on specific fields. Elasticsearch also provides powerful text analysis capabilities, such as stemming, stop word removal, and synonym expansion, that can be applied to the fields in a document.
6. Management and monitoring of documents: Elasticsearch provides various tools for managing and monitoring documents, such as the index stats API and the cat APIs. These tools allow you to check the health and status of the index, monitor resource usage, and troubleshoot issues.
Overall, documents are a critical component of Elasticsearch’s architecture, providing the building blocks for creating indexes and performing fast and accurate searches over large amounts of data. By storing, indexing, and searching documents in Elasticsearch, you can easily organize and retrieve information for a wide range of use cases, from e-commerce product catalogs to log analysis and monitoring.