Skip to main content

Elasticsearch and OpenSearch compatibility library.

Project description

AnySearch is a Elasticsearch and OpenSearch compatibility library. It provides utility functions for smoothing over the differences between the Python libraries with the goal of writing Python code that is compatible on both (including the *search, *search-dsl and django-*search-dsl integration packages).

See the documentation for more information on what is provided.

PyPI Version Supported Python versions Build Status Documentation Status MIT Coverage

Documentation

Documentation is available on Read the Docs.

Prerequisites

  • Python 3.6, 3.7, 3.8, 3.9 and 3.10.

Installation

Install latest stable version from PyPI:

pip install anysearch

or latest stable version from GitHub:

pip install https://github.com/barseghyanartur/anysearch/archive/main.tar.gz

Configuration

AnySearch automatically detects whether you use Elasticsearch or OpenSearch by looking at which packages are installed. However, if you have both packages installed, you can instruct AnySearch which one do you actually want to use. The way to do that is to set the ANYSEARCH_PREFERRED_BACKEND environment variable to either Elasticsearch or OpenSearch.

For Elasticsearch:

import os
os.environ.setdefault("ANYSEARCH_PREFERRED_BACKEND", "Elasticsearch")

For OpenSearch:

import os
os.environ.setdefault("ANYSEARCH_PREFERRED_BACKEND", "OpenSearch")

Usage

elasticsearch/opensearch

How-to

With elasticsearch you would do:

from elasticsearch import Connection, Elasticsearch

With opensearch you would do:

from opensearch_py import Connection, OpenSearch

With anysearch you would change that to:

from anysearch.search import Connection, AnySearch

elasticsearch-dsl/opensearch-dsl

How-to

With elasticsearch-dsl you would do:

from elasticsearch_dsl import AggsProxy, connections, Keyword
from elasticsearch_dsl.document import Document

With opensearch-dsl you would do:

from opensearch_dsl import AggsProxy, connections, Keyword
from opensearch_dsl.document import Document

With anysearch you would change that to:

from anysearch.search_dsl import AggsProxy, connections, Keyword
from anysearch.search_dsl.document import Document

django-elasticsearch-dsl/django-opensearch-dsl

How-to

With django-elasticsearch-dsl you would do:

from django_elasticsearch_dsl import fields, registry
from django_elasticsearch_dsl.documents import Document
from django_elasticsearch_dsl.fields import TextField

With opensearch-dsl you would do:

from django_opensearch_dsl import fields, registry
from django_opensearch_dsl.documents import Document
from django_opensearch_dsl.fields import TextField

With anysearch you would change that to:

from anysearch.django_search_dsl import fields, registry
from anysearch.django_search_dsl.documents import Document
from anysearch.django_search_dsl.fields import TextField

Configuration

INSTALLED_APPS

Both django-elasticsearch-dsl and django-opensearch-dsl will need to be added to your INSTALLED_APPS list.

With django-elasticsearch-dsl you would do:

INSTALLED_APPS = (
    ...
    "django_elasticsearch_dsl",
    ...
)

With django-opensearch-dsl you would do:

INSTALLED_APPS = (
    ...
    "django_opensearch_dsl",
    ...
)

With anysearch you would change that to:

INSTALLED_APPS = (
    ...
    "anysearch.django_search_dsl.DjangoAnySearchConfig",
    ...
)
Tuning

If you intent to support both Elasticsearch and OpenSearch, you could specify your settings as follows:

# Elasticsearch configuration
ELASTICSEARCH_DSL = {
    'default': {
        'hosts': 'localhost:9200',
        'timeout': 30,
    },
}
OPENSEARCH_DSL = ELASTICSEARCH_DSL

ELASTICSEARCH_DSL_SIGNAL_PROCESSOR = "anysearch.django_search_dsl.RealTimeSignalProcessor"
OPENSEARCH_DSL_SIGNAL_PROCESSOR = ELASTICSEARCH_DSL_SIGNAL_PROCESSOR

Testing

Project is covered with tests.

To test with all supported Python versions type:

tox

To test against specific environment, type:

tox -e py39

To test just your working environment type:

pytest

To run a single test in your working environment type:

pytest test_anysearch.py

To run a single test class in a given test module in your working environment type:

pytest test_anysearch.py::DjangoSearchDSLTestCase

It’s assumed that you have either elasticsearch-dsl or opensearch-dsl installed. If not, install the requirements first.

Writing documentation

Keep the following hierarchy.

=====
title
=====

header
======

sub-header
----------

sub-sub-header
~~~~~~~~~~~~~~

sub-sub-sub-header
^^^^^^^^^^^^^^^^^^

sub-sub-sub-sub-header
++++++++++++++++++++++

sub-sub-sub-sub-sub-header
**************************

License

MIT

Support

For any security issues contact me at the e-mail given in the Author section. For overall issues, go to GitHub.

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

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

anysearch-0.1.6.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

anysearch-0.1.6-py2.py3-none-any.whl (8.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file anysearch-0.1.6.tar.gz.

File metadata

  • Download URL: anysearch-0.1.6.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for anysearch-0.1.6.tar.gz
Algorithm Hash digest
SHA256 753b6dbd090c4c84ee01e3887557340771cab525745aac12a735299abc2e63ca
MD5 12095afb1ebc73ea60f9f462e60834df
BLAKE2b-256 1b5aadabdcdf213c30b80fc38fd8bb6db621cfeda918fa8c78b8e80c1829c90d

See more details on using hashes here.

File details

Details for the file anysearch-0.1.6-py2.py3-none-any.whl.

File metadata

  • Download URL: anysearch-0.1.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for anysearch-0.1.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 92032adb383d80118af5cd8f35e5024ff45528a3a6fa12b97757396225ebd309
MD5 bce248c31936b57e27dadc6bcdbb8336
BLAKE2b-256 53f09401f60371c87346771b0f9db2a95742f217203dec6839f0dd72edae5248

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