Skip to content

saimedhi/opensearch-python-client-demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenSearch Python Client Demo

Makes requests to Amazon OpenSearch using the OpenSearch Python Client. Supports OpenSearch Serverless since opensearch-py 2.2.1.

Install Prerequisites

Pyenv

Use pyenv to manage multiple versions of Python. This can be installed with pyenv-installer on Linux and MacOS, and pyenv-win on Windows.

curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

Follow the intructions to add pyenv init into your .bashrc, reopen a new shell.

Python 3.9

Python projects in this repository use Python 3.x. The latest version at the time of writing this is 3.11.1. See the Python Beginners Guide if you have never worked with the language.

$ python3 --version
Python 3.11.1

If you are using pyenv.

pyenv install 3.11.1
pyenv global 3.11.1

Pipenv

This project uses pipenv, which is typically installed with pip install --user pipenv. Pipenv automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages. It also generates the ever-important Pipfile.lock, which is used to produce deterministic builds.

$ pip install pipenv

$ pipenv --version
pipenv, version 2022.12.19

On Windows, run pyenv rehash if pipenv cannot be found. This rehashes pyenv shims, creating a pipenv file in /.pyenv/pyenv-win/shims/.

Install Packages

Install dependencies.

cd sync
pipenv install

Running

Create an OpenSearch domain in (AWS) which support IAM based AuthN/AuthZ.

export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=
export AWS_REGION=us-west-2

export SERVICE=es # use "aoss" for OpenSearch Serverless.
export ENDPOINT=https://....us-west-2.es.amazonaws.com

pipenv run python example.py

This will output the version of OpenSearch and a search result.

opensearch: 2.3.0
{'director': 'Bennett Miller', 'title': 'Moneyball', 'year': 2011}

The sync and the async examples will create an index, add a document, search for it, then cleanup. There's also an example of inserting and searching for vectors in k-nn.py and another example making direct transport calls instead of a higher level DSL in transport.py.

License

This project is licensed under the Apache v2.0 License.

Copyright

Copyright OpenSearch Contributors. See NOTICE for details.

About

OpenSearch Python Client Demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%