Skip to main content
Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Products
  • Resources
    • Cheatsheets
    • Tech Comparisons
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# ASP.NET MVC ASP.NET Web Forms C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet General Web Development HTML, CSS HTML/CSS Java JavaScript JavaScript, HTML, CSS JavaScript, Node.js Node.js
      Python Python 3.11, Pandas, SQL Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. ASP.NET Core
  4. Integrating Meilisearch with ASP.NET Core: Building a Fast Open-Source Search Engine

Integrating Meilisearch with ASP.NET Core: Building a Fast Open-Source Search Engine

Date- May 09,2026 326
meilisearch asp.net core

Overview

Meilisearch is a fast, open-source search engine that is designed to provide users with relevant search results in real time. It is built to index large datasets quickly while maintaining a high level of performance and relevance. The core problem Meilisearch addresses is the need for a robust search solution that can handle complex queries with speed and efficiency, making it ideal for applications where search functionality is critical.

Real-world use cases for Meilisearch span various domains, including e-commerce platforms, content management systems, and applications requiring extensive data retrieval capabilities. For instance, an e-commerce website can use Meilisearch to provide users with instant product searches, while a blog platform may leverage it to allow users to quickly find articles based on keywords or tags.

Prerequisites

  • ASP.NET Core: Familiarity with building applications using the ASP.NET Core framework.
  • NuGet Package Manager: Understanding how to install and manage packages in your ASP.NET Core project.
  • Meilisearch: Basic knowledge of what Meilisearch is and how it operates.
  • Postman or cURL: Tools for testing API endpoints.
  • Development Environment: A working setup with .NET SDK installed.

Setting Up Meilisearch

To integrate Meilisearch into your ASP.NET Core application, you first need to set up a running instance of Meilisearch. You can run Meilisearch locally using Docker, which is the recommended way due to its simplicity and quick setup.

Here’s how to set up Meilisearch using Docker:

docker run -it -p 7700:7700 getmeili/meilisearch

This command pulls the Meilisearch image from Docker Hub and runs it, exposing it on port 7700. Once your Meilisearch instance is running, you can interact with it via its RESTful API.

Why Use Docker?

Using Docker for running Meilisearch allows for easy environment management and ensures that you are using a consistent version across different development setups. It also simplifies deployment when moving to production environments.

Integrating Meilisearch with ASP.NET Core

To integrate Meilisearch into your ASP.NET Core application, you will need to add a client library that can communicate with the Meilisearch API. One popular library is Meilisearch.Client, which can be easily installed via NuGet.

To install the Meilisearch client, run the following command in your ASP.NET Core project directory:

dotnet add package Meilisearch.Client

This command adds the Meilisearch client library to your project, enabling you to interact with the Meilisearch API from your application. After installation, you can set up the client in your application’s startup configuration.

services.AddSingleton(new MeiliSearchClient("http://localhost:7700", "YOUR_MASTER_KEY"));

In this snippet, we register the Meilisearch client as a singleton service in the ASP.NET Core dependency injection container. Replace YOUR_MASTER_KEY with your actual Meilisearch master key, if you have set one.

Creating an Index

Once you have the client set up, the next step is to create an index in Meilisearch. An index is a collection of documents that you can search through. Here’s how to create an index:

var client = new MeiliSearchClient("http://localhost:7700", "YOUR_MASTER_KEY");
var index = await client.CreateIndexAsync(new CreateIndexRequest("products"));

This code creates an index named products. The CreateIndexRequest object allows you to specify additional parameters for the index, such as its name and settings.

Indexing Documents

After creating an index, you need to index documents so that they can be searched. Documents can be any JSON-compatible data structure. Here’s an example of how to index a list of products:

var products = new List {
new Product { Id = 1, Name = "Laptop", Description = "A high performance laptop" },
new Product { Id = 2, Name = "Smartphone", Description = "A latest model smartphone" }
};
await client.Index("products").AddDocumentsAsync(products);

This code snippet creates a list of Product objects and indexes them to the products index. The AddDocumentsAsync method takes care of sending the documents to Meilisearch.

Creating the Product Class

Before running the indexing code, you need to define the Product class:

public class Product {
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}

This class defines the structure of the documents you will be indexing, including properties for Id, Name, and Description.

Searching for Documents

Once documents are indexed, you can search for them using Meilisearch's search functionality. Here's how to perform a search:

var searchResults = await client.Index("products").SearchAsync("laptop");
foreach (var hit in searchResults.Hits)
{
Console.WriteLine(hit);
}

This code performs a search for the keyword laptop in the products index. The SearchAsync method returns the search results, which you can iterate through and display.

Understanding Search Results

The Hits property of the search results contains the documents that match the search query. Each hit corresponds to a document that was indexed, allowing you to easily access the relevant data.

Edge Cases & Gotchas

When working with Meilisearch, there are several pitfalls to be aware of:

Indexing Errors

If the structure of the documents does not match the expected format, Meilisearch will return an error. Always ensure that your data structures are consistent with what you are indexing.

// Wrong approach: Indexing a null object
await client.Index("products").AddDocumentsAsync(null);

The above code will throw an error because you cannot index null objects. Always check for null before attempting to index.

Search Queries

Meilisearch is case-insensitive by default, but be cautious about how you structure your queries. Ensure that your search terms are relevant to the indexed content to avoid empty results.

// Potential pitfall: Searching with incorrect terms
var searchResults = await client.Index("products").SearchAsync("invalid term");

This may return no results. Always validate user input before performing searches.

Performance & Best Practices

To maximize the performance of your Meilisearch integration, consider the following best practices:

Batch Indexing

Index documents in batches instead of one by one. This reduces the number of API calls and improves performance.

var batchProducts = new List();
for (int i = 0; i < 100; i++)
{
batchProducts.Add(new Product { Id = i, Name = "Product " + i, Description = "Description for product " + i });
}
await client.Index("products").AddDocumentsAsync(batchProducts);

Batching the documents reduces the load on the server and speeds up the indexing process.

Optimize Search Settings

Adjust the search settings in Meilisearch to suit your application's needs. This includes configuring ranking rules, synonyms, and searchable attributes to improve the relevance of search results.

Real-World Scenario: Building a Simple Product Search API

To tie everything together, let's create a simple ASP.NET Core API that allows users to search for products.

public class ProductsController : ControllerBase {
private readonly MeiliSearchClient _client;

public ProductsController(MeiliSearchClient client) {
_client = client;
}

[HttpGet("search")]
public async Task Search(string query) {
var results = await _client.Index("products").SearchAsync(query);
return Ok(results.Hits);
}
}

This ProductsController class defines a search endpoint that takes a query string and returns the search results from Meilisearch. The Search method utilizes the SearchAsync method to retrieve matching products.

Testing the API

You can test this API using Postman or cURL:

curl -X GET "http://localhost:5000/api/products/search?query=laptop"

This command sends a GET request to the search endpoint, and you should receive a JSON response with the matching products.

Conclusion

  • Meilisearch is an efficient and powerful search engine that can enhance your ASP.NET Core applications.
  • Integrating Meilisearch involves setting up the client, creating indexes, and indexing documents.
  • It's crucial to handle edge cases and optimize your search settings for better performance.
  • Batching and optimizing search queries can significantly improve the user experience.

Next, consider exploring advanced features of Meilisearch, such as synonyms and filterable attributes, to further enhance your search functionality.

S
Shubham Saini
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Deep Dive into WooCommerce REST API Integration with ASP.NET Core
May 19, 2026
Integrating Slack API in ASP.NET Core: Building Bots, Webhooks, and Notifications
May 24, 2026
Integrating Azure Cognitive Search into ASP.NET Core Applications
May 08, 2026
Integrating Backblaze B2 Cloud Storage with ASP.NET Core Applications
May 03, 2026
Previous in ASP.NET Core
Integrating Azure Cognitive Search into ASP.NET Core Applications
Next in ASP.NET Core
Integrating Typesense with ASP.NET Core for Advanced Typo-Toleran…
Buy me a pizza

Comments

🔥 Trending This Month

  • 1
    Elasticsearch Integration in ASP.NET Core - Full-Text Sear… 231 views
  • 2
    CWE-269: Improper Privilege Management - Implementing the … 248 views
  • 3
    Building Custom Bedrock Add-Ons with JavaScript: A Complet… 1,887 views
  • 4
    Error-An error occurred while processing your request in .… 11,922 views
  • 5
    Mastering Unconditional Statements in C: A Complete Guide … 22,166 views
  • 6
    How to Connect to a Database with MySQL Workbench 8,350 views
  • 7
    How to create a read-only MySQL user 11,053 views

On this page

🎯

Interview Prep

Ace your ASP.NET Core interview with curated Q&As for all levels.

View ASP.NET Core Interview Q&As

More in ASP.NET Core

  • How to Encrypt and Decrypt Password in Asp.Net 26668 views
  • Exception Handling Asp.Net Core 21692 views
  • HTTP Error 500.31 Failed to load ASP NET Core runtime 21140 views
  • How to implement Paypal in Asp.Net Core 20115 views
  • Task Scheduler in Asp.Net core 18188 views
View all ASP.NET Core posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1780
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Products
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • ASP.NET MVC
  • ASP.NET Web Forms
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • General Web Development
  • HTML, CSS
  • HTML/CSS
  • Java
  • JavaScript
  • JavaScript, HTML, CSS
  • JavaScript, Node.js
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor