Managing documents
The APIs for managing the documents (index, update, and delete) are the most important ones after the search ones. In this recipe, we will see how to use them in a standard way and in bulk actions to improve the performance.
Getting ready
You need a working ElasticSearch cluster and required packages of 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.
How to do it...
The main operations to manage documents are as follows:
index
: This stores a document in ElasticSearch. It is mapped on the Index API call.update
: This allows updating some values in a document. This operation is composed internally (via the Lucene nature) by deleting the previous document and reindexing of the document with the new values. It is mapped on the Update API call.delete
: This deletes a document from the index. It is mapped on the Delete API call.
With the ElasticSearch Python client...