Python client for OpenSearch
Project description
OpenSearch DSL Python Client
Welcome!
opensearch-dsl-py is a community-driven, open source fork of elasticsearch-dsl-py licensed under the Apache v2.0 License. For more information, see opensearch.org.
Installation
pip install opensearch-dsl
Sample Code
from opensearchpy import OpenSearch
from opensearch_dsl import Search
host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
ca_certs_path = '/full/path/to/root-ca.pem' # Provide a CA bundle if you use intermediate CAs with your root CA.
# Optional client certificates if you don't want to use HTTP basic authentication.
# client_cert_path = '/full/path/to/client.pem'
# client_key_path = '/full/path/to/client-key.pem'
# Create the client with SSL/TLS enabled, but hostname verification disabled.
client = OpenSearch(
hosts = [{'host': host, 'port': port}],
http_compress = True, # enables gzip compression for request bodies
http_auth = auth,
# client_cert = client_cert_path,
# client_key = client_key_path,
use_ssl = True,
verify_certs = True,
ssl_assert_hostname = False,
ssl_show_warn = False,
ca_certs = ca_certs_path
)
index_name = 'my-dsl-index'
response = client.indices.create(index_name)
print('\nCreating index:')
print(response)
# Add a document to the index.
document = {
'title': 'python',
'description': 'beta',
'category': 'search'
}
id = '1'
response = client.index(
index = index_name,
body = document,
id = id,
refresh = True
)
print('\nAdding document:')
print(response)
# Search for the document.
s = Search(using=client, index=index_name) \
.filter("term", category="search") \
.query("match", title="python")
response = s.execute()
print('\nSearch results:')
for hit in response:
print(hit.meta.score, hit.title)
# Delete the document.
print('\nDeleting document:')
print(response)
# Delete the index.
response = client.indices.delete(
index = index_name
)
print('\nDeleting index:')
print(response)
Project Resources
- Project Website
- Downloads.
- Documentation
- Need help? Try Forums
- Project Principles
- Contributing to OpenSearch
- Maintainer Responsibilities
- Release Management
- Admin Responsibilities
- Security
Code of Conduct
This project has adopted the Amazon Open Source Code of Conduct. For more information see the Code of Conduct FAQ, or contact opensource-codeofconduct@amazon.com with any additional questions or comments.
License
This project is licensed under the Apache v2.0 License.
Copyright
Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file opensearch-dsl-1.0.0.tar.gz
.
File metadata
- Download URL: opensearch-dsl-1.0.0.tar.gz
- Upload date:
- Size: 46.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 745fd4b05934b764f3ebca0dd9b1e7bd9b5934fcbb6c620d7087d24bcc8241c7 |
|
MD5 | dc8c00de7d1a67deda6e6cc619eed51d |
|
BLAKE2b-256 | f578f269b8a9431e79ce11674646f8df7288d1226bd3f4ec8c64dd864f3a1046 |
File details
Details for the file opensearch_dsl-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: opensearch_dsl-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 64.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee9199b3fee8a572bc476e22be44d8acafbef8f1b777a51fac898623f125b56 |
|
MD5 | 1f229f1557628c6c097cb63dce2a78f3 |
|
BLAKE2b-256 | a0e2b28d846a840b1a0d80615af95164400246db5fc710258f7f1086b38da0a1 |