百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

meilisearch-dotnet

> 数据库
开源

Meilisearch 的 NET 客户端

342 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Meilisearch 的 NET 客户端

Meilisearch .NET

Meilisearch | Meilisearch Cloud | Documentation | Discord | Roadmap | Website | FAQ

⚡ The Meilisearch API client written for .NET

Meilisearch .NET is the Meilisearch API client for C# developers.

Meilisearch is an open-source search engine. Learn more about Meilisearch.

Table of Contents

  • Documentation
  • Installation
  • Getting started
  • Compatibility with Meilisearch
  • Examples
    • Indexes
    • Documents
    • Get Task information
    • Search
  • Use a Custom HTTP Client
  • ⚙️ Contributing

Documentation

This readme contains all the documentation you need to start using this Meilisearch SDK.

For general information on how to use Meilisearch—such as our API reference, tutorials, guides, and in-depth articles—refer to our main documentation website.

Installation

This package targets .NET Standard 2.1.

Using the .NET Core command-line interface (CLI) tools:

bash
dotnet add package MeiliSearch

or with the Package Manager Console:

bash
Install-Package MeiliSearch

Run Meilisearch

⚡️ Launch, scale, and streamline in minutes with Meilisearch Cloud—no maintenance, no commitment, cancel anytime. Try it free now.

Prefer to self-host? Download and deploy our fast, open-source search engine on your own infrastructure.

Getting started

Add Documents

…

With the uid, you can check the status (enqueued, canceled, processing, succeeded or failed) of your documents addition using the task.

Basic Search

csharp
//Meilisearch is typo-tolerant:
SearchResult movies = await index.SearchAsync("philadalphia");
foreach(var prop in movies.Hits) {
    Console.WriteLine (prop.Title);
}

JSON Output:

json
{
    "hits": [
        {
            "id": 6,
            "title": "Philadelphia",
        }
    ],
    "offset": 0,
    "limit": 20,
    "processingTimeMs": 10,
    "query": "philadalphia"
}

Custom Search

All the supported options are described in the search parameters section of the documentation.

csharp
var movies = await index.SearchAsync(
    "car",
    new SearchQuery
    {
        AttributesToHighlight = new string[] { "title" },
    }
);

foreach(var prop in movies.Hits) {
    Console.WriteLine (prop.Title);
}

JSON Output:

json
{
    "hits": [
        {
            "id": 1,
            "title": "Carol",
            "_formatted": {
                "id": 1,
                "title": "Carol"
            }
        }
    ],
    "offset": 0,
    "limit": 20,
    "processingTimeMs": 10,
    "query": "car"
}

Custom Search With Filters

If you want to enable filtering, you must add your attributes to the FilterableAttributes index setting.

csharp
TaskInfo task = await index.UpdateFilterableAttributesAsync(
    new string[] { "id", "genres" }
);

You only need to perform this operation once.

Note that MeiliSearch will rebuild your index whenever you update FilterableAttributes. Depending on the size of your dataset, this might take time. You can track the process using the update status.

Then, you can perform the search:

csharp
var movies = await index.SearchAsync(
    "wonder",
    new SearchQuery
    {
        Filter = "id > 1 AND genres = Action",
    }
);

JSON Output:

json
{
  "hits": [
    {
      "id": 2,
      "title": "Wonder Woman",
      "genres": ["Action","Adventure"]
    }
  ],
  "offset": 0,
  "limit": 20,
  "estimatedTotalHits": 1,
  "processingTimeMs": 0,
  "query": "wonder"
}

Search with Limit and Offset

You can paginate search results by making queries combining both offset and limit.

csharp
var results = await index.SearchAsync(query, new SearchQuery()
{
    Limit = 5,
    Offset = 0
});

if (results is SearchResult limitedResults)
{
    var estimatedTotalHits = limitedResults.EstimatedTotalHits;
}

Search with defined number of results per page

To get paginated results with page numbers, the HitsPerPage and Page properties must be defined.

csharp
var results = await index.SearchAsync(query, new SearchQuery()
{
    HitsPerPage = pageSize,
    Page = pageNumber,
});

if (results is PaginatedSearchResult paginatedResults)
{
    var totalHits = paginatedResults.TotalHits;
    var totalPages = paginatedResults.TotalPages;
}

Search with sort

To get results sorted by attributes and preferred sorting order, the Sort property must be defined.

csharp
var results = await index.SearchAsync(query, new SearchQuery()
{
    Sort = new List { "genre:asc", "name:desc" }
});

Compatibility with Meilisearch

This package guarantees compatibility with version v1.x of Meilisearch, but some features may not be present. Please check the issues for more info.

Examples

Indexes

Create an index

csharp
var index = await client.CreateIndexAsync("movies");

Create an index and give the primary-key

csharp
var index = await client.CreateIndexAsync("movies", "id");

List all an index

csharp
var indexes = await client.GetAllIndexesAsync();

Get an Index object

csharp
var index = await client.GetIndexAsync("movies");

Documents

Add or Update Documents

csharp
var task = await index.AddDocumentsAsync(new Movie[] { new Movie { Id = "1", Title = "Carol" } } );
var task = await index.UpdateDocumentsAsync(new Movie[] { new Movie { Id = "1", Title = "Carol" } } );

The returned task is a TaskInfo that can access to Uid to get the status of the task.

Get Documents

csharp
var documents = await index.GetDocumentsAsync(new DocumentsQuery { Limit = 1 });

Get Document by Id

csharp
var document = await index.GetDocumentAsync("10");

Delete documents

csharp
var task = await index.DeleteOneDocumentAsync("11");

Delete in Batch

csharp
var task = await index.DeleteDocumentsAsync(new [] {"12","13","14"});

Delete all documents

csharp
var task = await indextoDelete.DeleteAllDocumentsAsync();

Get Task information

Get one Task By Uid

csharp
TaskInfo task = await index.GetTaskAsync(1);
// Or
TaskInfo task = await client.GetTaskAsync(1);

Get All Tasks

csharp
var task = await index.GetTasksAsync();
// Or
var task = await client.GetTasksAsync();

Search

Basic Search

csharp
var movies = await this.index.SearchAsync("prince");

Custom Search

csharp
var movies = await this.index.SearchAsync("prince", new SearchQuery { Limit = 100 });

Use a Custom HTTP Client

You can replace the default client used in this package by the one you want.

For example:

csharp
var _httpClient = ClientFactory.Instance.CreateClient();
var client = new MeilisearchClient(_httpClient);

Where ClientFactory is declared like this.

⚙️ Contributing

Any new contribution is more than welcome in this project!

If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!

Meilisearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#dotnetmeilisearchsearchvector

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库