Bielu.BetterSearch.Models
1.0.0-beta.20261122185900
Prefix Reserved
dotnet add package Bielu.BetterSearch.Models --version 1.0.0-beta.20261122185900
NuGet\Install-Package Bielu.BetterSearch.Models -Version 1.0.0-beta.20261122185900
<PackageReference Include="Bielu.BetterSearch.Models" Version="1.0.0-beta.20261122185900" />
<PackageVersion Include="Bielu.BetterSearch.Models" Version="1.0.0-beta.20261122185900" />
<PackageReference Include="Bielu.BetterSearch.Models" />
paket add Bielu.BetterSearch.Models --version 1.0.0-beta.20261122185900
#r "nuget: Bielu.BetterSearch.Models, 1.0.0-beta.20261122185900"
#:package Bielu.BetterSearch.Models@1.0.0-beta.20261122185900
#addin nuget:?package=Bielu.BetterSearch.Models&version=1.0.0-beta.20261122185900&prerelease
#tool nuget:?package=Bielu.BetterSearch.Models&version=1.0.0-beta.20261122185900&prerelease
Bielu.BetterSearch
<p align="center"> <img src="https://raw.githubusercontent.com/bielu/bielu.bettersearch/main/assets/icon.png" alt="Bielu.BetterSearch logo" width="128"> </p>
A provider-agnostic search abstraction for .NET: describe a query once, then run it against whichever search engine you configure. Elasticsearch, OpenSearch, Meilisearch, Typesense, PostgreSQL full-text search and an in-memory provider ship today, and a new engine is a new provider package, with no change to the core.
📖 Full documentation: https://search.bielu.pl/
Status: beta, not production ready. The public API will change before 1.0. The roadmap is the plan for a stable release, and the feature matrix records what each provider really supports.
Quick start
1. Install
dotnet add package Bielu.BetterSearch.Core --prerelease
# Then one provider:
dotnet add package Bielu.BetterSearch.ElasticSearch --prerelease # Elasticsearch
dotnet add package Bielu.BetterSearch.OpenSearch --prerelease # OpenSearch
dotnet add package Bielu.BetterSearch.Meilisearch --prerelease # Meilisearch
dotnet add package Bielu.BetterSearch.Typesense --prerelease # Typesense
dotnet add package Bielu.BetterSearch.PostgreSql --prerelease # PostgreSQL full-text search
dotnet add package Bielu.BetterSearch.Lifti --prerelease # in-memory
2. Register a provider
Elasticsearch, configured from Bielu:BetterSearch:ElasticSearch:
using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.ElasticSearch.DependencyInjection;
builder.Services.AddBetterSearch(builder.Configuration, search => search.AddElasticSearch());
OpenSearch, configured from Bielu:BetterSearch:OpenSearch:
using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.OpenSearch.DependencyInjection;
builder.Services.AddBetterSearch(builder.Configuration, search => search.AddOpenSearch());
{
"Bielu": {
"BetterSearch": {
"OpenSearch": {
"SharedIndexSettings": {
"ConnectionString": "http://localhost:9200",
"AuthenticationType": "Password",
"AuthenticationDetails": { "Username": "admin", "Password": "..." }
}
}
}
}
}
AuthenticationType is None, Password (basic, Username and Password) or ApiKey (an OpenSearch
3.x API key in ApiKey). An entry under Indexes overrides the connection string or the authentication
for that one index and takes the rest from the shared settings (set "AuthenticationType": "None" there to
turn the shared authentication off for that index), and MaxResultWindow (10,000 by default)
should match the indexes' index.max_result_window.
AdditionalNodes lists the cluster's other nodes, on OpenSearch and Elasticsearch, and PoolType (Static,
Sticky or Sniffing) chooses how requests are spread over them; a request that can't reach a node goes to the
next one. See the OpenSearch and
Elasticsearch pages.
In every provider, keys under Indexes match index names whatever their case, so Indexes:People applies
to the index people.
Elasticsearch and OpenSearch also take explicit field mappings under SharedIndexSettings:Mappings or an
Indexes entry's Mappings, applied when the index is created: a Keyword field matches and sorts on its
whole value under its plain name, a Text field sorts on its keyword sub-field automatically, and a
GeoPoint field makes geo distance queries work. Fields not listed keep dynamic mapping, and invalid mappings
fail at startup. See field mappings.
On Elasticsearch and OpenSearch a successful write becomes searchable at the next index refresh, about a
second later. Set "WriteVisibility": "WaitUntilSearchable" under SharedIndexSettings or an Indexes entry
to have index and remove calls return only once a search can see the write; Meilisearch, Typesense, PostgreSQL and Lifti
already wait. See when writes are searchable.
Meilisearch, configured from Bielu:BetterSearch:Meilisearch:
using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.Meilisearch.DependencyInjection;
builder.Services.AddBetterSearch(builder.Configuration, search => search.AddMeilisearch());
{
"Bielu": {
"BetterSearch": {
"Meilisearch": {
"SharedIndexSettings": {
"ConnectionString": "http://localhost:7700",
"ApiKey": "..."
}
}
}
}
}
ApiKey is the master key or an API key; leave it empty when the server has none. An entry under
Indexes without a ConnectionString uses the shared server and key. Meilisearch filters rather than
ranks, so fuzzy queries return a failed Result, and raw Lucene queries are translated into filters where
they can be: a term needs a field, and a Lucene fuzzy term matches the exact word with a TranslationWarning. Spatial queries work on one field, named by
"GeoField" under Meilisearch, holding a "lat,lon" string or a dictionary with lat and lon. Phrase
prefix queries store word runs for every text field; list the fields that need them in "PhraseFields" to keep
long texts small, and re-index after adding a field to it (see the feature matrix).
Typesense, configured from Bielu:BetterSearch:Typesense:
using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.Typesense.DependencyInjection;
builder.Services.AddBetterSearch(builder.Configuration, search => search.AddTypesense());
{
"Bielu": {
"BetterSearch": {
"Typesense": {
"SharedIndexSettings": {
"ConnectionString": "http://localhost:8108",
"ApiKey": "..."
}
}
}
}
}
AdditionalNodes lists a cluster's other nodes, tried in order when one can't be reached. Typesense also runs
queries as filters, so hits aren't ranked; fuzzy, raw Lucene and string range queries, facets and highlighting
return a failed Result, and so does a MustNot range, prefix or spatial query, as Typesense filters can only
negate an equality. See the Typesense page.
PostgreSQL full-text search, configured from Bielu:BetterSearch:PostgreSql:
using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.PostgreSql.DependencyInjection;
builder.Services.AddBetterSearch(builder.Configuration, search => search.AddPostgreSql());
{
"Bielu": {
"BetterSearch": {
"PostgreSql": {
"SharedIndexSettings": {
"ConnectionString": "Host=localhost;Database=app;Username=app;Password=..."
}
}
}
}
}
Leave the connection string empty to use the NpgsqlDataSource registered in the container. Each index is a table
with the fields as jsonb and a generated tsvector under a GIN index. Queries run as SQL conditions, so hits
aren't ranked; raw Lucene queries, facets and highlighting return a failed Result, and fuzzy queries need the
fuzzystrmatch extension. See the PostgreSQL page.
Or in memory:
using Bielu.BetterSearch.DependencyInjection;
builder.Services.AddBetterSearch(search => search.AddLiftiSearch());
3. Index and search
await indexing.IndexDocumentAsync(new SearchDocument
{
Id = "1",
Index = "people",
Fields = new Dictionary<string, IList<object>> { ["Name"] = ["Jane Doe"] },
});
var query = new SearchQuery { Index = "people", Page = 1, PageSize = 20 };
query.Add(Occurrence.Must, new PrefixSubQuery { Field = "Name", Value = "ja" });
var result = await search.SearchAsync(query, cancellationToken);
if (result.IsSuccess)
{
foreach (var hit in result.Value.Items) { /* hit.Document.Id, hit.Score, ... */ }
}
To search one culture, index it in the plain Culture field and filter on it with the fluent API:
Fields[CultureField.Name] = [CultureField.Value("en-US")];
var query = FluentApiSearchQueryCreator.Create()
.WithSearchQuery(search => search.WithIndex("pages"))
.CreateSearchQuery(search => search
.CreateTermQuery(term => term.WithField("Title").WithValue("welcome"))
.FilterByCulture("en-US"));
The Getting Started guide covers this in more detail.
Features
- ✅ One query model for every provider: term, terms, prefix, prefix phrase, fuzzy, date, numeric and string ranges, geo distance, raw Lucene, and nested boolean logic with Lucene semantics
- ✅ Fluent query builder in
Bielu.BetterSearch.FluentApi - ✅ Paging, sorting, post filters, highlighting and scores on the Elasticsearch and OpenSearch providers; paging, sorting and post filters on Meilisearch, Typesense and PostgreSQL
- ✅ Field mappings on Elasticsearch and OpenSearch:
Text,Keyword,Date, numeric,BooleanandGeoPointfields, with an optional analyzer or format, validated at startup - ✅ Zero-downtime rebuilds on Elasticsearch and OpenSearch through
IIndexLifecycleServiceAsync: fill a new index while searches read the old one, then swap an alias and delete the old index in one atomic step; on Typesense through a collection alias, in separate steps, one rebuild of an index at a time, with a short gap on an index's first rebuild - ✅ Index name prefix (
IndexPrefix) on Elasticsearch, OpenSearch, Meilisearch and Typesense, so applications or environments can share one cluster - ✅ Errors as results: searching and indexing return FluentResults
Results. Lifti, Typesense and PostgreSQL fail a query that asks for facets, and Meilisearch one that asks for any facet other than a top-level term facet; Meilisearch, Typesense, PostgreSQL and Lifti also fail a query that asks for highlighting. Lifti ignores paging, sorting and post filters, so check the feature matrix for what your provider applies - ✅ Opt-in search result cache: the built-in memory cache for one instance, FusionCache with a backplane for
several, or your own
ISearchResultCache, as decorators over the search and indexing services; every write through the indexing service evicts the index's cached searches. See caching - ✅ Observability: OpenTelemetry spans and metrics and
LoggerMessagelogs from the Core services, so every provider has them, wired withAddBetterSearchInstrumentation(), and a health check that pings the engine (AddBetterSearchHealthCheck()); see the feature matrix - ✅ Shared provider tests: provider-agnostic behavior tests in
BaseTestsrun against every provider - ✅ .NET Aspire AppHost that starts Elasticsearch, OpenSearch, Meilisearch and Typesense for local development and the integration tests, with meilisearch-ui for browsing Meilisearch indexes and trying queries
Elasticsearch and OpenSearch run term, multi-term and filter facets, nested inside each other; Meilisearch runs top-level term facets, and Lifti none. Only Elasticsearch and OpenSearch highlight. See the feature matrix for the full picture.
Packages
| Package | Description |
|---|---|
Bielu.BetterSearch.Abstractions |
Query model (SearchQuery and its sub-queries) and service interfaces |
Bielu.BetterSearch.Models |
SearchDocument and the request models |
Bielu.BetterSearch.Core |
AddBetterSearch and the indexing and search services |
Bielu.BetterSearch.FluentApi |
Fluent query builder |
Bielu.BetterSearch.Caching.FusionCache |
Search result cache over FusionCache |
Bielu.BetterSearch.OpenTelemetry |
AddBetterSearchInstrumentation() for OpenTelemetry tracing and metrics |
Bielu.BetterSearch.HealthChecks |
AddBetterSearchHealthCheck(), which pings the configured engine |
Bielu.BetterSearch.OpenSearch.Aws |
AddOpenSearchAwsSigV4(), which signs OpenSearch requests with AWS SigV4 for Amazon OpenSearch Service and Serverless |
Providers
| Package | Engine | Status |
|---|---|---|
Bielu.BetterSearch.ElasticSearch |
Elasticsearch | Available |
Bielu.BetterSearch.OpenSearch |
OpenSearch | Available |
Bielu.BetterSearch.Meilisearch |
Meilisearch | Available; filters only, see the feature matrix |
Bielu.BetterSearch.Lifti |
In memory, on LIFTI | Available; to be replaced by Lucene.NET |
Bielu.BetterSearch.Lucene |
Lucene.NET, in memory or on disk | Planned (roadmap) |
Documentation
The changelog lists what changed in each release.
Building from source
The repository needs the .NET 10 SDK. The solution is src/Bielu.BetterSearch.slnx. The Elasticsearch,
OpenSearch and Meilisearch tests start their engine through the Aspire AppHost, so they need Docker.
dotnet build src/Bielu.BetterSearch.slnx
dotnet test --solution src/Bielu.BetterSearch.slnx
To run the engines yourself, start src/examples/Bielu.BetterSearch.Examples.AppHost (aspire run from
src/, or dotnet run the project). For Meilisearch the Aspire dashboard links to Meilisearch's own search
preview and to meilisearch-ui; the master key is the meilisearch-masterKey parameter shown in the dashboard.
See CONTRIBUTING.md before opening a pull request. Every pull request needs a changeset.
License
Copyright (c) 2024 Arkadiusz Biel. Licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-beta.20261122185900 | 56 | 11/22/2026 |
| 1.0.0-beta.20261115140832 | 128 | 11/15/2026 |
| 1.0.0-beta.20261115131256 | 120 | 11/15/2026 |
| 1.0.0-beta.20261115130723 | 119 | 11/15/2026 |
| 1.0.0-beta.20261115125817 | 109 | 11/15/2026 |
| 1.0.0-beta.20261115125225 | 117 | 11/15/2026 |
| 1.0.0-beta.20261114231717 | 110 | 11/14/2026 |
| 1.0.0-beta.20261114225816 | 113 | 11/14/2026 |
| 1.0.0-beta.20261114221153 | 111 | 11/14/2026 |
| 1.0.0-beta.20261114212816 | 108 | 11/14/2026 |
| 1.0.0-beta.20261114211723 | 108 | 11/14/2026 |
| 1.0.0-beta.20261114210618 | 98 | 11/14/2026 |
| 1.0.0-beta.20261114210103 | 102 | 11/14/2026 |
| 1.0.0-beta.20261114205610 | 101 | 11/14/2026 |
| 1.0.0-beta.20261114195414 | 96 | 11/14/2026 |
| 1.0.0-beta.20261114194127 | 97 | 11/14/2026 |
| 1.0.0-beta.20261114192126 | 93 | 11/14/2026 |
| 1.0.0-beta.20261114190827 | 95 | 11/14/2026 |
| 1.0.0-beta.20261114185948 | 92 | 11/14/2026 |
| 1.0.0-beta.20261114173856 | 94 | 11/14/2026 |