Skip to content

laysauchoa/opensearch-python-dive-in

Repository files navigation

OpenSearch Python dive in

OpenSearch® with Python

This repository contains code examples related to OpenSearch with Python queries.

Quickstart

To run those examples, you need:

Repository structure

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

Dataset

You can download the Kaggle recipe dataset, and save the file as recipes.json in this current folder.

Search queries

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:

Test an analyzer

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

Dependencies

Install all dependencies:

pip install -r requirements.txt

Service URI

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>

License

License: CC BY 4.0

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.

Trademarks

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.

Do you have questions?

Feel free to open an issue with your question on Issues or drop me a message at [email protected].

More OpenSearch® resources