Extension of Elasticsearch for Flask with a simple integration
Project description
Flask-ESearch
This is a Flask extension proving simple integration with Elasticsearch using python 3
Requirements
- Flask >= 1.XXX
- Elasticsearch>=6.4.6, <=7.7.1
- Python 3.6 or later
How to use
-
Install the package:
pip install Flask-ESearch
-
In your main app file:
from datetime import datetime from flask import Flask, make_response from flask_esearch import ESearch app = Flask(__name__) # CREATE A ESearch CLIENT es = ESearch() es.init_app(app) @app.route('/') def hello_world(): doc = { 'author': 'kimchy', 'text': 'Elasticsearch: cool. bonsai cool.', 'timestamp': datetime.now(), } try: res = es.index(index="test-index", id=1, body=doc) return make_response(print(res['result']), 200) except Exception: res = es.get(index="test-index", id=1) return make_response(res['_source'], 200) app.run(debug=True, port=5001)
The above is an example of a Flask app integrating Flask-ESearch and an endpoint
- The instance allows to perform Elasticsearch queries. More info here.
- Testing access
http://127.0.0.1:5001/
.- If is the first access, will show
Created
or else the record inserted
- If is the first access, will show
Custom Settings
In order to add your elasticsearch settings, the package allows to change those 2 properties and override them in your settings file.
Name | Type | Default Value |
---|---|---|
ELASTICSEARCH_HOST | string | localhost:9200 |
ELASTICSEARCH_HTTP_AUTH | string | None |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-ESearch-0.1.0.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for Flask_ESearch-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f34171325e367128d356b842390f8a777061ac6e282de3deb74dc2fdca4464f3 |
|
MD5 | 95c658659a41a75dcde113a1ed6ccbe7 |
|
BLAKE2b-256 | 53f551b06e53139194da9c44175c248324039b209c9e2cc2576494abea586ecb |