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 and figure out how to use it:
> python manage.py shell > from elasticsearch_dsl import Search > from elasticsearch_dsl.connections import connections > connections.create_connection(hosts=['localhost:9200']) <Elasticsearch([{u...