or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bulk-operations.mdcluster-operations.mddocument-operations.mdindex-management.mdindex.mdsearch-operations.mdtransport-connection.md
tile.json

tessl/pypi-elasticsearch5

Python client for Elasticsearch 5.x providing comprehensive access to all Elasticsearch APIs and features.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/elasticsearch5@5.5.x

To install, run

npx @tessl/cli install tessl/pypi-elasticsearch5@5.5.0

index.mddocs/

Elasticsearch5

A comprehensive Python client library for Elasticsearch 5.x clusters. Provides low-level access to all Elasticsearch APIs and features through a clean Python interface, serving as the foundation for Elasticsearch-related Python applications with complete API coverage, connection management, and automatic retry logic.

Package Information

  • Package Name: elasticsearch5
  • Language: Python
  • Installation: pip install elasticsearch5

Core Imports

from elasticsearch5 import Elasticsearch

Common imports for advanced usage:

from elasticsearch5 import (
    Elasticsearch,
    Transport,
    ConnectionPool,
    RequestsHttpConnection,
    Urllib3HttpConnection,
    JSONSerializer
)

Exception handling:

from elasticsearch5.exceptions import (
    ElasticsearchException,
    TransportError,
    ConnectionError,
    NotFoundError,
    ConflictError,
    RequestError
)

Basic Usage

from elasticsearch5 import Elasticsearch

# Create client instance
es = Elasticsearch(['localhost:9200'])

# Test connectivity
if es.ping():
    print("Connected to Elasticsearch")

# Index a document
doc = {
    'title': 'My Document',
    'content': 'This is the document content',
    'timestamp': '2023-01-01T12:00:00'
}
response = es.index(index='my_index', doc_type='_doc', body=doc)
print(f"Document indexed with ID: {response['_id']}")

# Search for documents
search_body = {
    'query': {
        'match': {
            'title': 'My Document'
        }
    }
}
results = es.search(index='my_index', body=search_body)
print(f"Found {results['hits']['total']} documents")

# Get a document by ID
doc_id = response['_id']
retrieved_doc = es.get(index='my_index', doc_type='_doc', id=doc_id)
print(f"Retrieved document: {retrieved_doc['_source']}")

Architecture

The client is built on a layered architecture:

  • Elasticsearch Client: Main interface providing all API methods organized by functionality
  • Transport Layer: Handles HTTP communication, request/response processing, and connection pooling
  • Connection Pool: Manages multiple connections with failure detection and node discovery
  • Connections: HTTP implementations (urllib3-based by default, requests optional)
  • Serializers: Handle data serialization/deserialization (JSON by default)
  • Helper Functions: High-level utilities for bulk operations, scanning, and reindexing

This design provides reliability, performance, and complete API coverage while maintaining compatibility with the underlying Elasticsearch REST API.

Capabilities

Core Document Operations

Essential CRUD operations for working with individual documents including creation, retrieval, updates, and deletion with support for various document types and indexing strategies.

def create(index: str, doc_type: str, id: str, body: dict, **params) -> dict: ...
def index(index: str, doc_type: str, body: dict, id: str = None, **params) -> dict: ...
def get(index: str, id: str, doc_type: str = '_all', **params) -> dict: ...
def update(index: str, doc_type: str, id: str, body: dict = None, **params) -> dict: ...
def delete(index: str, doc_type: str, id: str, **params) -> dict: ...
def exists(index: str, doc_type: str, id: str, **params) -> bool: ...

Document Operations

Search and Query Operations

Comprehensive search functionality including full-text search, query execution, aggregations, scroll operations, and search templates with support for complex queries and result processing.

def search(index: str = None, doc_type: str = None, body: dict = None, **params) -> dict: ...
def count(index: str = None, doc_type: str = None, body: dict = None, **params) -> dict: ...
def scroll(scroll_id: str = None, body: dict = None, **params) -> dict: ...
def msearch(body: list, index: str = None, doc_type: str = None, **params) -> dict: ...
def suggest(body: dict, index: str = None, **params) -> dict: ...

Search Operations

Bulk and Batch Operations

High-performance operations for processing multiple documents efficiently including bulk indexing, updates, deletions, and specialized helper functions for streaming and parallel processing.

def bulk(body: list, index: str = None, doc_type: str = None, **params) -> dict: ...
def update_by_query(index: str, doc_type: str = None, body: dict = None, **params) -> dict: ...
def delete_by_query(index: str, body: dict, doc_type: str = None, **params) -> dict: ...
def reindex(body: dict, **params) -> dict: ...

Bulk Operations

Index Management

Complete index lifecycle management including creation, deletion, mapping management, settings configuration, alias operations, and maintenance tasks like refresh and forcemerge.

# Via es.indices
def create(index: str, body: dict = None, **params) -> dict: ...
def delete(index: str, **params) -> dict: ...
def put_mapping(doc_type: str, body: dict, index: str = None, **params) -> dict: ...
def get_mapping(index: str = None, doc_type: str = None, **params) -> dict: ...
def put_settings(body: dict, index: str = None, **params) -> dict: ...

Index Management

Cluster Administration

Cluster-level operations and monitoring including health status, cluster state, node information, statistics, and administrative tasks for cluster management and maintenance.

# Via es.cluster
def health(index: str = None, **params) -> dict: ...
def state(metric: str = None, index: str = None, **params) -> dict: ...
def stats(node_id: str = None, **params) -> dict: ...
def put_settings(body: dict = None, **params) -> dict: ...

Cluster Operations

Connection and Transport

Low-level connection management, transport configuration, and client customization including connection pooling, retry logic, serialization, and advanced client configuration options.

class Elasticsearch:
    def __init__(
        self,
        hosts=None,
        transport_class=Transport,
        **kwargs
    ): ...

class Transport:
    def __init__(
        self,
        hosts,
        connection_class=Urllib3HttpConnection,
        connection_pool_class=ConnectionPool,
        **kwargs
    ): ...

Transport and Connection

Exception Handling

class ElasticsearchException(Exception):
    """Base exception for all elasticsearch5 errors"""

class TransportError(ElasticsearchException):
    """HTTP transport errors with status code and error details"""
    @property
    def status_code(self) -> str: ...
    @property
    def error(self) -> str: ...
    @property
    def info(self) -> dict: ...

class ConnectionError(TransportError):
    """Connection-level errors"""

class NotFoundError(TransportError):
    """HTTP 404 Not Found errors"""

class ConflictError(TransportError):
    """HTTP 409 Conflict errors"""

class RequestError(TransportError):
    """HTTP 400 Bad Request errors"""

Helper Utilities

from elasticsearch5.helpers import bulk, scan, reindex

def bulk(client, actions, stats_only: bool = False, **kwargs) -> tuple: ...
def scan(client, query: dict = None, scroll: str = '5m', **kwargs): ...
def reindex(client, source_index: str, target_index: str, **kwargs) -> tuple: ...