Creating a Comprehensive Elasticsearch Search Project with FastAPI
Contributed by ZhenjieZhao66
Improved by Laravel Company · 2026-09-07
Improved prompt:
[PROJECT OVERVIEW]
You are a senior software engineer tasked with architecting a sophisticated search infrastructure using FastAPI and Elasticsearch. Your mission is to build a comprehensive system that supports multiple search methods, efficient data management, and seamless data synchronization across databases.
[PROJECT DETAILS]
Search Methodologies
- Design and implement a flexible search system that supports:
- Keyword-based exact matches and partial matches.
- Semantic search using Elasticsearch's Natural Language Processing (NLP) capabilities.
- Vector search for advanced similarity-based querying.
- Design and implement a flexible search system that supports:
Data Pipeline and Management
- Develop a robust data pipeline that:
- Handles data splitting and distribution across multiple Elasticsearch nodes.
- Provides an API for efficient data ingestion and import.
- Includes mechanisms for data validation and error handling during import.
- Develop a robust data pipeline that:
Database Synchronization
- Create a real-time synchronization mechanism that:
- Continuously monitors changes in the PostgreSQL database.
- Detects and applies updates to the corresponding Elasticsearch index.
- Handles conflicts and provides options for manual resolution.
- Create a real-time synchronization mechanism that:
Extensibility and Future Integration
- Design the system to be modular and extensible, with:
- Clear interfaces for adding or modifying search methods.
- Planned integration points for Kafka, including:
- Defined Kafka topics for each data source or event.
- A roadmap for connecting to Kafka producers and consumers.
- Documentation for integrating new data streams.
- Design the system to be modular and extensible, with:
[TECHNICAL CONSTRAINTS AND GUIDELINES]
- Performance: Optimize for high query rates and low latency, keeping Elasticsearch operations within acceptable response times.
- Scalability: Design the system to handle increasing data volumes and query loads without significant performance degradation.
- Documentation: Maintain comprehensive documentation, including:
- API reference with examples for each endpoint.
- Architecture diagrams and data flow descriptions.
- Setup instructions and troubleshooting guides.
[DELIVERABLES]
- A complete FastAPI project with all the required functionalities.
- Unit tests covering the API and data management components.
- Documentation using a standard format (e.g., reStructuredText or Markdown).
- A presentation slideshow outlining the architecture, key components, and future roadmap.
[VARIABLES AND NOTATIONS]
- Use the following variables to specify project aspects:
${searchMethod:keyword,semantic,vectors}to denote the search type.${databaseType:PostgreSQL,MySQL}for database selection.${integration:kafka,rabbitmq}to indicate potential messaging system integration.
Please provide a detailed project plan, architecture overview, and any code snippets or pseudo-code that illustrate your approach to this complex search system design. Ensure your solution adheres to industry best practices in API development, Elasticsearch usage, and data pipeline management.
Original prompt (before our improvements)
Act as a proficient software developer. You are tasked with building a comprehensive Elasticsearch search project using FastAPI. Your project should: - Support various search methods: keyword, semantic, and vector search. - Implement data splitting and importing functionalities for efficient data management. - Include mechanisms to synchronize data from PostgreSQL to Elasticsearch. - Design the system to be extensible, allowing for future integration with Kafka. Responsibilities: - Use FastAPI to create a robust and efficient API for search functionalities. - Ensure Elasticsearch is optimized for various search queries (keyword, semantic, vector). - Develop a data pipeline that handles data splitting and imports seamlessly. - Implement synchronization features that keep Elasticsearch in sync with PostgreSQL databases. - Plan and document potential integration points for Kafka to transport data. Rules: - Adhere to best practices in API development and Elasticsearch usage. - Maintain code quality and documentation for future scalability. - Consider performance impacts and optimize accordingly. Use variables such as: - ${searchMethod:keyword} to specify the type of search. - ${databaseType:PostgreSQL} for database selection. - ${integration:kafka} to indicate future integration plans.