This repository contains code examples related to OpenSearch with Python queries.
To run those examples, you need:
- Python 3.7+
- An OpenSearch® cluster. It can be set it up manually or you can use a fully managed service, such as Aiven for OpenSearch®
- OpenSearch® cluster Service URI
This repository contains the following:
├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.rst ├── LICENSE ├── README.rst ├── __init__.py ├── analyzer.py ├── config.py ├── helpers.py ├── images │ └── opensearch-python.png ├── index.py ├── recipes.json ├── requirements.txt └── search.py
- config.py, basic information to connect to the cluster
- index.py, contains methods that manipulate the index
- search.py, contains search queries methods
- helpers.py, response handler of search requests
- analyzer.py, test built-in analyzers with user input
You can download the Kaggle recipe dataset, and save the file as recipes.json
in this current folder.
The available search options can be found by using the --help command:
python search.py --help
Find the arguments to be passed to a certain function by running:
python search.py OPTION --help
OPTION can be:
OpenSearch comes with a set of built-in analyzers:
- standard
- simple
- whitespace
- stop
- keyword
- pattern
- fingerprint
- languages
You can use analyzer.py
to test how an analyzer works. As a result, you will be able to see which tokens it generates.
The available analyzer options can be found by using the --help command:
python analyzer.py --help
Find the arguments to be passed to a certain function by running:
python analyzer.py OPTION --help
Install all dependencies:
pip install -r requirements.txt
To connect with your cluster, you need the Service URI of your OpenSearch cluster. You can find the connection details in the section Overview on Aiven web console. Notice that service_uri
contains credentials; therefore, should be treated with care.
This project uses dotenv
Python library to manage the environment variables.
Replace your SERVICE_URI
on .env file with yours as string:
SERVICE_URI=<https://<user>:<password>@<host>:<port>
I created this repository to make OpenSearch® easy to use for Python developers. You can use this work by following the CC-BY license. Please attribute it by mentioning “OpenSearch® and Python by @laysauchoa”.
This work is licensed under a Creative Commons Attribution 4.0 International License.
OpenSearch® and Python are trademarks and property of their respective owners. All product and service names used in this website are for identification purposes only and do not imply endorsement.
Feel free to open an issue with your question on Issues or drop me a message at [email protected]
.