Skip to content

div5252/elastic_search_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Electronic Products Search with Elasticsearch

This is a live search application for electronic products using Elasticsearch and FastAPI. The application provides a powerful search interface that can handle natural language queries and return relevant results even with irrelevant keywords.

Prerequisites

  • Python 3.8 or higher
  • Elasticsearch 8.x
  • Docker (optional, for running Elasticsearch)

Setup

  1. Install the required dependencies:
pip install -r requirements.txt
  1. Set up Elasticsearch:

    • You can run Elasticsearch locally or use a cloud service
    • For local development, you can use Docker:
    docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:8.11.0
  2. Create a .env file with your Elasticsearch credentials (if needed):

ELASTICSEARCH_URL=http://localhost:9200
ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASSWORD=changeme

Running the Application

Start the FastAPI server:

python search_app.py

The server will start on http://localhost:8000

API Usage

Search Products

GET /search?query=your search query

Example:

GET /search?query=apple phone with good camera

The search is designed to handle natural language queries and will return relevant results even if the query contains irrelevant keywords.

Features

  • Fuzzy matching for typo tolerance
  • Field boosting (name has highest priority, followed by description and features)
  • Support for natural language queries
  • Sample product data included for testing
  • FastAPI for high-performance API endpoints
  • Pydantic models for data validation

Customization

You can modify the search_app.py file to:

  • Add more product fields
  • Change the search scoring
  • Add more sample products
  • Implement additional search features

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published