Makes requests to Amazon OpenSearch using the OpenSearch Python Client. Supports OpenSearch Serverless since opensearch-py 2.2.1.
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 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
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 dependencies.
cd sync
pipenv install
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.
This project is licensed under the Apache v2.0 License.
Copyright OpenSearch Contributors. See NOTICE for details.