Skip to main content

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

  1. OPENSEARCH_HOST
  2. OPENSEARCH_REGION
  3. OPENSEARCH_USERNAME
  4. 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

  1. OPENSEARCH_HOST
  2. OPENSEARCH_USERNAME
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opensearch-helper-0.1.12.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

opensearch_helper-0.1.12-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file opensearch-helper-0.1.12.tar.gz.

File metadata

  • Download URL: opensearch-helper-0.1.12.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.5 Windows/10

File hashes

Hashes for opensearch-helper-0.1.12.tar.gz
Algorithm Hash digest
SHA256 f79ab6885339ff4345f614460c411b0c45112bb02d3a892825b1a0eef69126fa
MD5 ed68f2ae6c9735056828c5e43ac5b89a
BLAKE2b-256 1a4e3427c76692da855a3fbc26e815df43b99b5b96288cfe8686fd46c5f6ab5e

See more details on using hashes here.

File details

Details for the file opensearch_helper-0.1.12-py3-none-any.whl.

File metadata

File hashes

Hashes for opensearch_helper-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 d52458894bea3e66b073450b9525ddd579b66e2ab16303bc212e5f49cb439dda
MD5 751b0bd7aaa6ec9a935defed01106d42
BLAKE2b-256 7319412d53e7b1ca5a10dcdaf0841afc9032878e290a80a512e9a7bf494173d7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page