chapter five

5 Working with documents

 

This chapter covers

  • Indexing, retrieving, and reindexing documents
  • Manipulating and tweaking responses
  • Updating and deleting documents with APIs and query methods
  • Working with scripted updates
  • Indexing documents in bulk

It is time to work with and understand operations on documents in Elasticsearch. Documents are indexed, fetched, updated, or deleted as per the requirement. We can load the data into Elasticsearch either from various stores such as databases and files or from real time streams. Similarly, we can update or modify the data that exists in Elasticsearch. If needed, we can even delete and purge the documents. For example, we may have a product catalog database that needs to be imported into Elasticsearch to enable search capabilities on the products.

Elasticsearch exposes a set of APIs for working with our documents:

  • The document indexing APIs—Indexes documents into Elasticsearch
  • The read and search APIs—Allows clients to fetch documents from Elasticsearch
  • The update APIs—Allows us to modify the fields of a document
  • The delete APIs—Removes documents from the store

5.1 Indexing documents

5.1.1 Document APIs

5.1.2 Mechanics of indexing

5.1.3 Customizing the refresh

5.2 Retrieving documents

5.2.1 Using the single document API

5.2.2 Retrieving multiple documents

5.3 Manipulating responses

5.3.1 Removing metadata from the response

5.3.2 Suppressing the source document

5.3.3 Including and excluding fields

5.4 Updating documents

5.4.1 Document update mechanics

5.4.2 The _update API

5.4.3 Scripted updates

5.4.4 Replacing documents

5.4.5 Upsert

5.4.6 Updating by a query

5.5 Deleting documents

5.5.1 Deleting with an ID