A simple API built with ASP.NET Core that demonstrates integration with Elasticsearch for indexing and searching products.
If you find this repository valuable, please consider giving it a star to show your support!
- Index products: Add products to Elasticsearch index.
- Search products: Search products by name using Elasticsearch.
- Swagger Integration: Easily test and explore the API using Swagger UI.
Before running the application, ensure you have the following:
- .NET 6 SDK installed on your machine.
- Elasticsearch instance running locally or on a remote server.
- Basic understanding of how Elasticsearch works.
-
Clone this repository:
git clone https://github.com/yourusername/ProductSearchWithElasticsearch.git cd ProductSearchWithElasticsearch
-
Configure the
Elasticsearch
connection settings in the code. Adjust the following values in the code to point to your running Elasticsearch instance:var uri = new List<string>() { "http://127.0.0.1:2367" // Change this to your Elasticsearch server URL }; var settings = new ElasticsearchClientSettings(pool) .Authentication(new BasicAuthentication("elastic", "yourpassword")) // Add your credentials .DefaultIndex("product");
-
Run the application:
dotnet run
-
Once the application is running, open your browser and navigate to
http://localhost:5024/index.html
to explore the API using Swagger UI.
Endpoint: /products
Description: Index a new product into Elasticsearch.
{
"id": "1",
"name": "Laptop",
"description": "A high-performance laptop.",
"price": 1500.00
}
Endpoint: /products/search
Description: Search for products based on their name.
name
: The name of the product to search for.
Example:
GET /products/search?name=Laptop
- Elasticsearch: Open source, distributed, RESTful search engine.
- Elastic.Clients.Elasticsearch: Elasticsearch client for .NET.
- Swagger: API documentation tool.