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
- Python >= 3.8
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(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.5.0.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file Flask-ESearch-0.5.0.tar.gz
.
File metadata
- Download URL: Flask-ESearch-0.5.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22c2b20d0841ff39ff7ff491df6d361753297d42c2f6aae5f97364664663cb71 |
|
MD5 | 606228c8aa0b874afc9b0331a119652f |
|
BLAKE2b-256 | d624cfe706d4a8fef7163dbd9a6b30f82d0230538074400163d8386f3576063c |
File details
Details for the file Flask_ESearch-0.5.0-py2.py3-none-any.whl
.
File metadata
- Download URL: Flask_ESearch-0.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5006825d23576e4bb5e9ef6d56b389ecf5bd8c29fb1d8e23843b6e752eaadd5b |
|
MD5 | 872118409d033c284f0fdbfa5d7fe36f |
|
BLAKE2b-256 | 77183ec9ab10aece4f610efc5eafc83683c4cce9ceb4dceec4b90b57208df939 |