Skip to main content

No project description provided

Project description

OpenSearch ORM

opensearch-orm is a high-level OpenSearch ORM for Python. The query syntax is similar to django-orm.

May be compatible with Elasticsearch, depending on opensearch-py.

Installation

pip install opensearch-orm

Getting Started

First, define your document model with indexing pattern.

from opensearchorm import SearchSession, BaseModel


class UserLog(BaseModel):
    __index__ = 'user_access_log-*'

    method: str
    path: str
    remote_ip: str
    created: datetime

You can use django-like syntax or typed query expressions together.

filter

# {'bool': {'must_not': [], 'should': [], 'filter': [{'range': {'created': {'gte': '2022-09-01'}}}, {'match_phrase': {'remote_ip': '127.0.0.1'}}]}}        
with SearchSession() as session:
    result = (
        session.select(UserLog)
        .filter(created__gte='2022-09-01', remote_ip='127.0.0.1')
        .fetch()
    )
    print(result)

    # equals to
    result = (
        session.select(UserLog)
        .filter(Range('created', date(2022, 9, 1)), remote_ip='127.0.0.1')
        .fetch()
    )

contains

# {'bool': {'must_not': [], 'should': [], 'filter': [{'bool': {'should': [{'match_phrase': {'method': 'GET'}}, {'match_phrase': {'method': 'POST'}}], 'minimum_should_match': 1}}]}}      
with SearchSession() as session:
    result = (
        session.select(UserLog)
        .filter(method__contains=['GET', 'POST'])
        .fetch()
    )
    print(result)

    # equals to
    result = (
        session.select(UserLog)
        .filter(Contains('method', ['GET', 'POST']))
        .fetch()
    )

exclude

{'bool': {'must_not': [{'match_phrase': {'method': 'get'}}, {'match_phrase': {'path': '/login'}}], 'should': [], 'filter': []}}
with SearchSession() as session:
    result = (
        session.select(UserLog)
        .exclude(method='get', path='/login')
        .fetch()
    )
    print(result)

paginate

with SearchSession() as session:
    result = (
        session.select(UserLog)
        .filter(method='get')
        .limit(100)
        .offset(100)
        .fetch()
    )
    print(result)

aggregations

group by path and count unique remote_ip

with SearchSession() as session:
    result = (
        session.select(UserLog)
        .aggregate(Terms('path').nested(Cardinality('remote_ip')))
    )
    print(result)
    # result -> {'path': 1, 'path2': 2}

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-orm-0.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opensearch_orm-0.1.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file opensearch-orm-0.1.2.tar.gz.

File metadata

  • Download URL: opensearch-orm-0.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Linux/5.10.102.1-microsoft-standard-WSL2

File hashes

Hashes for opensearch-orm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1ee8b5e3ca017c218a6be8c6ccd9b1958789e373648334272e904e46ff7deac6
MD5 88c41c72b28c4f2fc0c0d3b046835f96
BLAKE2b-256 f9048df674c662780142cd63558c53c0e43eeb84bd46d9de30295185e26c4082

See more details on using hashes here.

File details

Details for the file opensearch_orm-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: opensearch_orm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Linux/5.10.102.1-microsoft-standard-WSL2

File hashes

Hashes for opensearch_orm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f5e88f1fa6615d494f27d9cd033f5bd6992217480c3f482b50b470787937745
MD5 7ac99e19be1fb0cc25284b7c82e42b97
BLAKE2b-256 30446191b85b936a7bbf985f6252b2768585a7affb5c423334e54172221f33e4

See more details on using hashes here.

Supported by

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