Full-text search with Elasticsearch
Elasticsearch is a search server based on Lucene, which is an open source information-retrieval library. Elasticsearch provides a distributed full-text search engine with a RESTful web interface and schema-free JSON documents. In this recipe, we will implement full-text search using Elasticsearch for our Flask application.
Getting ready
We will use a Python library called pyelasticsearch
, which makes dealing with Elasticsearch a lot easier:
$ pip install pyelasticsearch
We also need to install the Elasticsearch server itself. This can be downloaded from http://www.elasticsearch.org/download/. Unpack the package downloaded and run the following command:
$ bin/elasticsearch
This will start the Elasticsearch server on http://localhost:9200/
by default.
How to do it…
To perform the integration, we will start by adding the Elasticsearch object to the application's configuration, that is, my_app/__init__.py
:
from pyelasticsearch import ElasticSearch from...