Rig.TUnit.Databases.NoSql.ElasticSearch
0.1.0-beta.2
dotnet add package Rig.TUnit.Databases.NoSql.ElasticSearch --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Databases.NoSql.ElasticSearch -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Databases.NoSql.ElasticSearch" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Databases.NoSql.ElasticSearch" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Databases.NoSql.ElasticSearch" />
paket add Rig.TUnit.Databases.NoSql.ElasticSearch --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Databases.NoSql.ElasticSearch, 0.1.0-beta.2"
#:package Rig.TUnit.Databases.NoSql.ElasticSearch@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Databases.NoSql.ElasticSearch&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Databases.NoSql.ElasticSearch&version=0.1.0-beta.2&prerelease
Rig.TUnit.Databases.NoSql.ElasticSearch
Testcontainers-backed Elasticsearch 8.x fixture with
IndexRefreshHelperand strongly-typedDslAssert.
What this package is
The Rig.TUnit Elasticsearch provider. ElasticSearchFixture spins
Elasticsearch 8.x via Testcontainers and returns an ElasticsearchClient
configured for HTTPS + basic auth against the container's self-signed
certificate. IndexRefreshHelper.RefreshAsync forces the near-real-time
refresh so indexed documents are queryable immediately — required because
Elasticsearch's default 1-second refresh interval would otherwise race
every test. DslAssert.HitCountAsync<T> provides a fluent hit-count
assertion over typed DSL queries.
When to use it
- Integration tests for full-text search features.
- Asserting indexed document counts or query-DSL equivalence.
- Verifying index template / mapping behaviour.
- Not for: pure-unit search-logic tests — Elasticsearch's query DSL is best tested against a real server.
Prerequisites
- .NET 10 SDK
- Docker Desktop / Colima (Elasticsearch image ~1.1 GB)
Elastic.Clients.Elasticsearch8.x (transitive; note Elastic 2.0 / SSPL dual licence).
Quick start
using Rig.TUnit.Databases.NoSql.ElasticSearch.Fixtures;
using Rig.TUnit.Databases.NoSql.ElasticSearch.Helpers;
await using var fx = new ElasticSearchFixture();
await fx.InitializeAsync();
await fx.Client.Indices.CreateAsync("orders");
await IndexRefreshHelper.RefreshAsync(fx.Client, "orders");
Options
| Property | Type | Default | Description |
|---|---|---|---|
Image |
string |
"docker.elastic.co/elasticsearch/elasticsearch:8.15.0" |
Image |
StartupTimeoutSeconds |
int |
180 |
ES boot is slow |
Password |
string |
"rigtunit" |
elastic user password |
DiscoveryType |
string |
"single-node" |
Dev mode |
XpackSecurityEnabled |
bool |
true |
Auth enforced |
Fixture + helper APIs
Rig.TUnit.Databases.NoSql.ElasticSearch.Fixtures.ElasticSearchFixtureRig.TUnit.Databases.NoSql.ElasticSearch.Options.ElasticSearchFixtureOptionsRig.TUnit.Databases.NoSql.ElasticSearch.Builder.ElasticSearchRigBuilderRig.TUnit.Databases.NoSql.ElasticSearch.Helpers.IndexRefreshHelperRig.TUnit.Databases.NoSql.ElasticSearch.Assertions.DslAssert
Per-test isolation
Per-test index naming via IsolationKey: orders_{IsolationKey:short}.
DELETE {index} on teardown. Indexes are cheap; full parallelism is safe.
Parallelism + performance
- First-run pull: ~90 s (~1.1 GB).
- Warm startup: ~45–60 s.
- Per-test index create + delete: ~50 ms.
- Parallelism: 8+ concurrent tests; ES handles index churn well.
Troubleshooting
search_phase_execution_exceptionwith zero hits immediately after indexing — you forgotIndexRefreshHelper.RefreshAsync. Default refresh interval is 1 s; tests cannot wait.- Certificate validation errors — the fixture disables cert
validation on the embedded
HttpClient; do not share that handler with production-shaped code.
See docs/troubleshooting.md#elasticsearch.
Provider quirks + edge cases
- Elasticsearch's
matchquery is analysed by default; usetermto hit exact tokens. Tests asserting on non-tokenised content must say so. _idis not searchable by default; useidsquery or a mappedkeywordfield.- Index settings are immutable after creation for many fields (shard count, analyser); tests that mutate these must recreate the index.
Benchmarks
See ElasticSearchBenchmarks.cs;
baseline in benchmarks/baseline-005.json.
Related docs
License
MIT. See 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
- Bogus (>= 35.6.1)
- Elastic.Clients.Elasticsearch (>= 8.17.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Rig.TUnit.Databases.NoSql (>= 0.1.0-beta.2)
- Testcontainers (>= 4.11.0)
- Testcontainers.Elasticsearch (>= 4.11.0)
- TUnit.Core (>= 1.34.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rig.TUnit.Databases.NoSql.ElasticSearch:
| Package | Downloads |
|---|---|
|
Rig.TUnit.All
Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 41 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 44 | 4/26/2026 |