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 and *search-dsl packages).
See the documentation for more information on what is provided.
Documentation is available on Read the Docs.
- Python 3.6, 3.7, 3.8, 3.9, 3.10 or 3.11.
Install latest stable version from PyPI:
pip install anysearchor latest stable version from GitHub:
pip install https://github.com/barseghyanartur/anysearch/archive/main.tar.gzAnySearch 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")With elasticsearch you would do:
from elasticsearch import Connection, ElasticsearchWith opensearch you would do:
from opensearch_py import Connection, OpenSearchWith anysearch you would change that to:
from anysearch.search import Connection, AnySearchWith elasticsearch-dsl you would do:
from elasticsearch_dsl import AggsProxy, connections, Keyword
from elasticsearch_dsl.document import DocumentWith opensearch-dsl you would do:
from opensearch_dsl import AggsProxy, connections, Keyword
from opensearch_dsl.document import DocumentWith anysearch you would change that to:
from anysearch.search_dsl import AggsProxy, connections, Keyword
from anysearch.search_dsl.document import DocumentProject is covered with tests.
To test with all supported Python versions type:
toxTo test against specific environment, type:
tox -e py39To test just your working environment type:
pytestTo run a single test in your working environment type:
pytest test_anysearch.pyTo run a single test class in a given test module in your working environment type:
pytest test_anysearch.py::AnySearchTestCaseIt's assumed that you have either elasticsearch-dsl or opensearch-dsl
installed. If not, install the requirements first.
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
**************************
MIT
For any security issues contact me at the e-mail given in the Author section. For overall issues, go to GitHub.
Artur Barseghyan <artur.barseghyan@gmail.com>