Skip to main content

This library manages the communication between python programs and elasticsearch database

Project description

# Elastic search wrapper for Python

This library allows access to a Elasticsearch from a Python program.

https://pypi.org/project/elasticsearchlib/

## Installation

### Command line This library can be installed with the following command:

` pip3 install elasticsearchlib ` ### Dockerfile

You can add these lines in your Dockerfile to include this library in your image:

` RUN pip3 install elasticsearchlib `

## Uploading to pip

These steps are needed to distribute the library on Pip repository manager:

### Prerequisites

First, these packages must be installed on your Python environment:

  • Setuptools

  • Wheel

  • Twine

  • Tqdm

` sudo python -m pip install --upgrade pip setuptools wheel sudo python -m pip install tqdm sudo python -m pip install --user --upgrade twine `

### Customization

On the _setup.py_ file, these fields can be customized:

  • Version: The current version of the build.

### Execution

` python3 setup.py bdist_wheel ` This command will generate a _.whl_ file inside the _dist_ folder of the root of the project. Then, execute the following command to upload this file to PyPi repository:

` python3 -m twine upload dist/* `

## Usage This section will explain the usage of this library.

### Constructor ` Elasticsearchlib() `

### start_connection This function creates the connection to the elasticsearch database, checking if the server is up. Returns True if the database answered correctly. ` def start_connection(self, host, port, request_retries=3, total_retries=9): ` - host: Base IP address for the elasticsearch database. - port: Port where the elasticsearch database is published. - request_retries: number of times a request will be retried before being dropped (defaults to 3). - total_retries: number of consecutive retries before dropping the connection and throwing an Exception (defaults to 9).

### create_index This function checks if an index is already created and, if not, creates it, according to the provided mapping. ` def create_index(self, index, mapping=None): ` - index: Name of the index to create. - mapping: Mapping provided as the template for this index.

### add_to index This function adds a document to the provided index. If the index does not exist, it will be created first. ` def add_to_index(self, index, body, id=''): ` - index: Index where the document will be added. - body: Body for the document. - id: Optional argument for the document id on the database. If not provided, a random one will be created.

### search_last_n_measures This functions allows for the retrieval of the last n measures of one dataset item. ` def search_last_n_measures(self, index, id_dataset, n): ` - index: Index to search in. - id_dataset: Dataset id to retrieve the measures. - n: Number of measures desired.

### scrolled_query This function returns all measures stored in an index, following a query. ` def scrolled_query(self, query, index, filter_path=None): ` - query: Query to use on the request. - index: Index on which to use the query. - filter_path: Filter that can be applied to the request.

### get_entities_ids This function returns all the entity ids stored under an index. ` def get_entities_ids(self, index): ` - index: Index on which to request the ids.

### get_last_document This function returns the last document stored under an index, for a specific device_id. ` def get_last_document(self, index, device_id): ` - index: Index on which to request the document. - device_id: Id of the device to query.

### get_data_history This function returns the data history for a specific device in a period of time. ` def get_data_history(self, index, device_id, gte, lte='now'): ` - index: Index on which to request the data. - device_id: Id of the device to query. - gte: Lower bound for the time period. - lte: Upper bound for the time period (defaults to now).

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

easierai_elasticsearchlib-1.3.4.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

easierai_elasticsearchlib-1.3.4-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file easierai_elasticsearchlib-1.3.4.tar.gz.

File metadata

  • Download URL: easierai_elasticsearchlib-1.3.4.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

File hashes

Hashes for easierai_elasticsearchlib-1.3.4.tar.gz
Algorithm Hash digest
SHA256 d88f690ada2baa22bc89a4f18373507d3b566fc31f3f69b5c95742c3514ef35a
MD5 6aec091e38542e37dc271d25af1140dc
BLAKE2b-256 036e5f902de1ea4f68d68c2f7c7d7b663d128483a3b3e9e52e6c568fe566b8ad

See more details on using hashes here.

File details

Details for the file easierai_elasticsearchlib-1.3.4-py3-none-any.whl.

File metadata

  • Download URL: easierai_elasticsearchlib-1.3.4-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

File hashes

Hashes for easierai_elasticsearchlib-1.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 09873eb84781a408c273764add98e9d6de166202aab0d323a98d31b156f6c37c
MD5 c56e483a4ac5f4e111d4ec2ef7c7665e
BLAKE2b-256 b523d4bb9b54ed567e0b1c5fb0210bf48b9f79234a555cd1aaf36583e80c1e5f

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