Zymergi.Search.Elastic
11.4.0-alpha
dotnet add package Zymergi.Search.Elastic --version 11.4.0-alpha
NuGet\Install-Package Zymergi.Search.Elastic -Version 11.4.0-alpha
<PackageReference Include="Zymergi.Search.Elastic" Version="11.4.0-alpha" />
<PackageVersion Include="Zymergi.Search.Elastic" Version="11.4.0-alpha" />
<PackageReference Include="Zymergi.Search.Elastic" />
paket add Zymergi.Search.Elastic --version 11.4.0-alpha
#r "nuget: Zymergi.Search.Elastic, 11.4.0-alpha"
#:package Zymergi.Search.Elastic@11.4.0-alpha
#addin nuget:?package=Zymergi.Search.Elastic&version=11.4.0-alpha&prerelease
#tool nuget:?package=Zymergi.Search.Elastic&version=11.4.0-alpha&prerelease
Zymergi.Search.Elastic
Elasticsearch adapter for the engine-neutral search contracts in Zymergi.Core (ISearchProvider<T>, ISearchIndexer<T>, IIndexManager). Application code never references Elasticsearch types. It talks to the REST API over HttpClient.
Targets .NET 10. Depends on Zymergi.Core. Supports every SearchCapabilities feature, including recency boost and exact totals.
Install
dotnet add package Zymergi.Search.Elastic
Register in Program.cs
{ "Elasticsearch": { "ConnectionString": "https://search.example.com:9200" } }
Put credentials in user-secrets or an environment variable (Elasticsearch__ConnectionString=https://user:password@host:9200), not in appsettings.json.
using Zymergi.Search;
using Zymergi.Search.Elastic;
builder.Services
.AddElasticSearch(builder.Configuration) // named HttpClient "elasticsearch" + IIndexManager
.AddElasticSearchIndex<ProductDoc>("products", d => d.Id); // singleton provider + indexer
// Optional: rotate connections and add resilience (package Microsoft.Extensions.Http.Resilience).
builder.Services.AddHttpClient(ElasticSearchServiceCollectionExtensions.HttpClientName)
.ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromMinutes(5) })
.AddStandardResilienceHandler();
var app = builder.Build();
var indexes = app.Services.GetRequiredService<IIndexManager>();
if (!await indexes.ExistsAsync("products"))
{
await indexes.CreateAsync("products", ProductDoc.Definition); // mappings for facets, filters, sort
}
ProductDoc is your own record plus an IndexDefinition. See the Zymergi.Search.Sqlite README for a full example; the same document works with every adapter.
Use it
app.MapGet("/search", async (string? q, ISearchProvider<ProductDoc> search, CancellationToken ct) =>
{
var result = await search.SearchAsync(new SearchRequest
{
Query = q,
Filter = new RangeFilter("Price", Min: 10, Max: 100),
Facets = [new TermsFacetRequest("Brand"), new StatsFacetRequest("Price")],
Recency = new RecencyBoost("Released", TimeSpan.FromDays(90)),
Highlight = new HighlightRequest(["Title"]),
Limit = 20,
}, ct);
return Results.Ok(result);
});
Indexing: inject ISearchIndexer<ProductDoc> and call IndexAsync, DeleteAsync, or ClearAsync. A completed task means the change is searchable.
Best practices
- Depend on the
Zymergi.Searchinterfaces only. Swap engines by changing the registration. - Pass the request's
CancellationToken. - Create indexes once (startup or deploy), not per request.
- Index in batches from a background job or queue consumer.
- Rate-limit public search endpoints and cache popular queries (output caching or
HybridCache). - Catch
SearchTransportException(it carries the HTTP status and body) and return a ProblemDetails 502/503. Do not echo the body to the client.
Testing
- Unit-test your code against a fake
ISearchProvider<T>. - The adapter's own unit tests use a stub
HttpMessageHandler. Do the same if you need to check the requests you send. - Run Elasticsearch in Testcontainers for integration tests. Never test against production.
Gotchas
- The provider and indexer are singletons. Each holds one
HttpClientcreated at startup, soIHttpClientFactoryhandler rotation does not apply. SetPooledConnectionLifetimeas shown so DNS changes are picked up. - The client timeout is 20 s.
- Credentials come from the URL's user-info and are sent as Basic auth without URL decoding. A password with characters that the URL must percent-encode does not work.
- Field names in the
IndexDefinitionmust match the JSON property names of the document.
Version notes
11.4.0-alpha: no API change. The README sample no longer uses Zymergi.Articles, which is not packed.
| 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
- Microsoft.Extensions.Configuration (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection (>= 10.0.12)
- Microsoft.Extensions.Http (>= 10.0.12)
- Newtonsoft.Json (>= 13.0.4)
- Zymergi.Core (>= 11.4.0-alpha)
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 |
|---|---|---|
| 11.4.0-alpha | 52 | 11/16/2026 |
| 11.3.0-alpha | 68 | 11/12/2026 |
| 11.2.0-alpha | 58 | 11/2/2026 |
| 11.1.1-alpha | 72 | 10/4/2026 |
| 11.1.0-alpha | 109 | 10/1/2026 |
| 11.0.6-alpha | 122 | 7/10/2026 |
| 11.0.5-alpha | 83 | 7/9/2026 |
| 11.0.4-alpha | 88 | 7/6/2026 |
| 11.0.3-alpha | 85 | 7/6/2026 |
| 11.0.2-alpha | 126 | 6/30/2026 |
| 11.0.1-alpha | 134 | 6/30/2026 |
| 11.0.0-alpha | 105 | 6/29/2026 |