The APIs for managing documents (indexing, updating, and deleting) are the most important APIs after the search ones. In this recipe, we will see how to use them in a standard way and in bulk actions to improve performance.
You need a working ElasticSearch cluster and the packages used in the Creating a client recipe of this chapter.
The full code of this recipe is in the chapter_11/document_management.py
and chapter_11/document_management_pyes.py
files, available in the code bundle of this book and on GitHub (https://github.com/aparo/elasticsearch-cookbook-second-edition).
There are three main operations to manage documents, as follows:
index
: This stores a document in ElasticSearch. It is mapped on the Index API call.update
: This allows you to update some values in a document. This operation is composed internally (via Lucene) by deleting the previous documents and reindexing the document with new values. It is mapped to the Update API call...