Searching from Python

Now that we have a basic understanding of how we can use Elasticsearch to insert and search on our documents, let's see how to do the same from Python. We could use the HTTP API of Elasticsearch from Python and query for the documents but there is a better way. There are a number of libraries that provide an abstraction over the HTTP API for Elasticsearch. Underneath, they are simply using the HTTP API, but the abstractions that they provide make it easier for us to communicate with Elasticsearch. The library that we will be using here is elasticsearch_dsl. Make sure that your virtual environment is activated, and install it using pip:

> pip install elasticsearch_dsl

Next, let's start a Django shell so that we can play around ...

Get Django Project Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.