OpenSearch Helper for Easy I/O
Project description
Open Search Helper (opensearch-helper)
A collection of methods for assisting with OpenSearch querying on AWS
MultiMatch Query Generator
Method Definition
multimatch_generator(input_text: str, size: int = 5, *args) -> MultiMatchQuery
Invoke Function
Pass in one-or-more field names after the query:
from opensearch_helper import multimatch_generator
d_query = multimatch_generator("what is the average PH of rainwater?" "question", "context")
Sample Output
{
"size":5,
"query":{
"multi_match":{
"query":"input_text",
"fields":[
"question"
]
}
}
}
API Query (AWS)
Method Definition
query(d_query: MultiMatchQuery, index_name: str) -> OpenSearchResult
Invoke Function
The following environment variables must exist and be encrypted via baseblock::Run-Encrypt
- OPENSEARCH_HOST
- OPENSEARCH_REGION
- OPENSEARCH_USERNAME
- OPENSEARCH_PASSWORD
from opensearch_helper import query
query(d_query, index_name='myindex')
Score Top Hit
This method will retrieve the top hit and both quantitatively and qualitatively score the result.
Method Definition
score_top_hit(d_hits: dict) -> ScoreResult
Invoke Function
from opensearch_helper import score_top_hit
score_top_hit(d_hits)
Sample Output
{
"score":14.23432,
"type":"HIGH"
}
Local OpenSearch
From the terminal run
docker-compose up
The following environment variables must exist and be encrypted via baseblock::Run-Encrypt
- OPENSEARCH_HOST
- OPENSEARCH_USERNAME
- OPENSEARCH_PASSWORD
Unless these have been modified, the default values can be found here https://opensearch.org/docs/latest/opensearch/install/docker/
from a python script import
from opensearch_helper import OpenSearchDEV
The following functions are available
client = OpenSearchDEV()
client.create_index(...)
client.delete_index(...)
client.add(...)
client.query(...)
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-helper-0.1.9.tar.gz
.
File metadata
- Download URL: opensearch-helper-0.1.9.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.8.5 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 145c20bda0aad5802a0d576665ce6154dc44f527949e47e006f8122d9bd6a6a2 |
|
MD5 | 83d331971099b54ce3d62d1b6844c61a |
|
BLAKE2b-256 | 350f8de66d2ea59d4b61dd4df6a6ccdd8742f8caaf392b4e06dfb6cf50d81a58 |
File details
Details for the file opensearch_helper-0.1.9-py3-none-any.whl
.
File metadata
- Download URL: opensearch_helper-0.1.9-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.8.5 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | edee31e43cd8e7a79080fd8490bccbbf3093f4cccb6a7ab2ecf8350c3fa1fe3a |
|
MD5 | bca6f3b67d1ae038e864bc7692d84572 |
|
BLAKE2b-256 | 10a07c37fc8bb7e336ef41fb7635e5ad26fba1d56bee0154461dcf50e2e450a8 |