Added samples, benchmarks and docs for nox format. (#556)

* Added samples for nox format.

Signed-off-by: dblock <[email protected]>

* Added space after #!/usr/bin/env python.

Signed-off-by: dblock <[email protected]>

* Added benchmarks and docs.

Signed-off-by: dblock <[email protected]>

---------

Signed-off-by: dblock <[email protected]>
This commit is contained in:
Daniel (dB.) Doubrovkine
2023-10-26 19:55:50 -07:00
committed by GitHub
parent 0da60b2623
commit bcfef113c4
28 changed files with 745 additions and 726 deletions
+31 -32
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: Apache-2.0
#
@@ -9,62 +11,59 @@
# GitHub history for details.
import logging
from os import environ
from time import sleep
from urllib.parse import urlparse
from boto3 import Session
from opensearchpy import RequestsAWSV4SignerAuth, OpenSearch, RequestsHttpConnection
from opensearchpy import OpenSearch, RequestsAWSV4SignerAuth, RequestsHttpConnection
# verbose logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
# cluster endpoint, for example: my-test-domain.us-east-1.es.amazonaws.com
url = urlparse(environ['ENDPOINT'])
region = environ.get('AWS_REGION', 'us-east-1')
service = environ.get('SERVICE', 'es')
url = urlparse(environ["ENDPOINT"])
region = environ.get("AWS_REGION", "us-east-1")
service = environ.get("SERVICE", "es")
credentials = Session().get_credentials()
auth = RequestsAWSV4SignerAuth(credentials, region, service)
client = OpenSearch(
hosts=[{
'host': url.netloc,
'port': url.port or 443
}],
http_auth=auth,
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection,
timeout=30
hosts=[{"host": url.netloc, "port": url.port or 443}],
http_auth=auth,
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection,
timeout=30,
)
# TODO: remove when OpenSearch Serverless adds support for /
if service == 'es':
info = client.info()
print(f"{info['version']['distribution']}: {info['version']['number']}")
if service == "es":
info = client.info()
print(f"{info['version']['distribution']}: {info['version']['number']}")
# create an index
index = 'movies'
index = "movies"
client.indices.create(index=index)
try:
# index data
document = {'director': 'Bennett Miller', 'title': 'Moneyball', 'year': 2011}
client.index(index=index, body=document, id='1')
# index data
document = {"director": "Bennett Miller", "title": "Moneyball", "year": 2011}
client.index(index=index, body=document, id="1")
# wait for the document to index
sleep(1)
# wait for the document to index
sleep(1)
# search for the document
results = client.search(body={'query': {'match': {'director': 'miller'}}})
for hit in results['hits']['hits']:
print(hit['_source'])
# search for the document
results = client.search(body={"query": {"match": {"director": "miller"}}})
for hit in results["hits"]["hits"]:
print(hit["_source"])
# delete the document
client.delete(index=index, id='1')
# delete the document
client.delete(index=index, id="1")
finally:
# delete the index
client.indices.delete(index=index)
# delete the index
client.indices.delete(index=index)
+31 -32
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: Apache-2.0
#
@@ -9,62 +11,59 @@
# GitHub history for details.
import logging
from os import environ
from time import sleep
from urllib.parse import urlparse
from boto3 import Session
from opensearchpy import Urllib3AWSV4SignerAuth, OpenSearch, Urllib3HttpConnection
from opensearchpy import OpenSearch, Urllib3AWSV4SignerAuth, Urllib3HttpConnection
# verbose logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
# cluster endpoint, for example: my-test-domain.us-east-1.es.amazonaws.com
url = urlparse(environ['ENDPOINT'])
region = environ.get('AWS_REGION', 'us-east-1')
service = environ.get('SERVICE', 'es')
url = urlparse(environ["ENDPOINT"])
region = environ.get("AWS_REGION", "us-east-1")
service = environ.get("SERVICE", "es")
credentials = Session().get_credentials()
auth = Urllib3AWSV4SignerAuth(credentials, region, service)
client = OpenSearch(
hosts=[{
'host': url.netloc,
'port': url.port or 443
}],
http_auth=auth,
use_ssl=True,
verify_certs=True,
connection_class=Urllib3HttpConnection,
timeout=30
hosts=[{"host": url.netloc, "port": url.port or 443}],
http_auth=auth,
use_ssl=True,
verify_certs=True,
connection_class=Urllib3HttpConnection,
timeout=30,
)
# TODO: remove when OpenSearch Serverless adds support for /
if service == 'es':
info = client.info()
print(f"{info['version']['distribution']}: {info['version']['number']}")
if service == "es":
info = client.info()
print(f"{info['version']['distribution']}: {info['version']['number']}")
# create an index
index = 'movies'
index = "movies"
client.indices.create(index=index)
try:
# index data
document = {'director': 'Bennett Miller', 'title': 'Moneyball', 'year': 2011}
client.index(index=index, body=document, id='1')
# index data
document = {"director": "Bennett Miller", "title": "Moneyball", "year": 2011}
client.index(index=index, body=document, id="1")
# wait for the document to index
sleep(1)
# wait for the document to index
sleep(1)
# search for the document
results = client.search(body={'query': {'match': {'director': 'miller'}}})
for hit in results['hits']['hits']:
print(hit['_source'])
# search for the document
results = client.search(body={"query": {"match": {"director": "miller"}}})
for hit in results["hits"]["hits"]:
print(hit["_source"])
# delete the document
client.delete(index=index, id='1')
# delete the document
client.delete(index=index, id="1")
finally:
# delete the index
client.indices.delete(index=index)
# delete the index
client.indices.delete(index=index)