Skip to content

dev-vivekkumarverma/elastic-search

Repository files navigation

Elastic-Search

Elasticsearch

Overview

This repository provides a comprehensive guide to setting up, configuring, and using Elasticsearch effectively with Python 3. It includes best practices, hands-on examples, and real-world use cases to help you leverage Elasticsearch for search, analytics, and data management.

Features

  • Powerful Search Capabilities: Supports full-text search, fuzzy matching, and relevance scoring.
  • Scalable & Distributed: Handles large datasets efficiently with horizontal scaling.
  • Real-time Data Processing: Enables quick indexing and retrieval of structured and unstructured data.
  • Custom Mappings & Analyzers: Define schemas and optimize search performance.
  • Integration with Kibana & Logstash: Provides visualization and data processing capabilities.

Getting Started

Prerequisites

  • Python 3.x
  • Elasticsearch and elasticsearch-py Python client
  • Docker (recommended) or direct installation
  • Java 11+ (if running without Docker)
  • Basic understanding of JSON and RESTful APIs

Installation

Using Docker

docker network create elastic

docker run --name elasticsearch --net elastic -p 9200:9200 -p 9300:9300 \
  -e "discovery.type=single-node" \
  -e "xpack.security.enabled=false" \
  docker.elastic.co/elasticsearch/elasticsearch:8.6.2

or

Use the docker compose file and run the following command

docker-compose -f path/to/docker-compose.yaml up

or [Easiest way]

Use run.sh file see run.sh file: Link [click me]

# change the chmod of the run.sh file
chmode +x run.sh
# execute the run.sh file
./run.sh

Manual Installation

  1. Download Elasticsearch.
  2. Extract and navigate to the directory.
  3. Run Elasticsearch:
    ./bin/elasticsearch
  4. Access the UI via http://localhost:9200.

Installing Elasticsearch Python Client

pip install elasticsearch

Basic Usage with Python

Connecting to Elasticsearch

from elasticsearch import Elasticsearch

es = Elasticsearch(["http://localhost:9200"])
print(es.info())

Creating an Index

es.indices.create(index="my_index", body={
    "settings": {"number_of_shards": 1, "number_of_replicas": 1}
})

Indexing a Document

doc = {"title": "Introduction to Elasticsearch", "content": "Elasticsearch is a powerful search and analytics engine."}
es.index(index="my_index", id=1, document=doc)

Searching Documents

resp = es.search(index="my_index", query={"match": {"title": "Elasticsearch"}})
print(resp)

Folder Structure

/elastic-search
├── configs/         # Elasticsearch configurations
├── scripts/         # Custom automation scripts
├── data/            # Sample datasets
├── logs/            # Elasticsearch logs
├── docs/            # Documentation and guides
└── README.md        # This file

Best Practices

  • Use proper indexing strategies to improve search efficiency.
  • Optimize queries and filters to reduce execution time.
  • Implement snapshot and backup mechanisms to prevent data loss.
  • Enable monitoring and logging to analyze performance and troubleshoot issues.

Author

👤 Vivek Kumar Verma
📧 Contact: vivekkumarverma332@gmail.com
🔗 GitHub: https://github.com/dev-vivekkumarverma


Happy Searching with Elasticsearch and Python! 🚀

For notes and Use : Link [click me...]