OpenSearch
Bielu.BetterSearch.OpenSearch runs queries on an OpenSearch cluster. It translates queries the same way as the Elasticsearch provider, so the same queries give the same results, with paging, sorting, post filters, facets, highlighting and scores.
Warning
Invalid or missing connection settings make searching and every indexing method return a failed Result
whose message names the setting to fix, such as Bielu:BetterSearch:OpenSearch:SharedIndexSettings:ConnectionString.
A request that throws, as it does when ThrowExceptions() is on in the connection settings, is a failed
Result from every indexing method, with the exception as its cause. So is a client factory that throws.
OperationCanceledException still propagates.
A request cancelled through the CancellationToken, before or during the request, throws
OperationCanceledException from every indexing method. A write cancelled after the server received it may
still have been applied.
Install
dotnet add package Bielu.BetterSearch.Core --prerelease
dotnet add package Bielu.BetterSearch.OpenSearch --prerelease
Register
AddOpenSearch() reads its settings from Bielu:BetterSearch:OpenSearch, so pass the configuration in. The
AddBetterSearch overload without configuration leaves the provider with empty settings.
using Bielu.BetterSearch.DependencyInjection;
using Bielu.BetterSearch.OpenSearch.DependencyInjection;
builder.Services.AddBetterSearch(builder.Configuration, search => search.AddOpenSearch());
Configure
{
"Bielu": {
"BetterSearch": {
"OpenSearch": {
"SharedIndexSettings": {
"ConnectionString": "http://localhost:9200",
"AdditionalNodes": [ "http://node-2:9200", "http://node-3:9200" ],
"PoolType": "Static",
"AuthenticationType": "Password",
"AuthenticationDetails": { "Username": "admin", "Password": "..." }
},
"Indexes": {
"people": { "ConnectionString": "http://people-cluster:9200" }
},
"MaxResultWindow": 10000
}
}
}
}
| Setting | Meaning |
|---|---|
SharedIndexSettings |
Connection used for every index without its own entry |
ConnectionString |
Cluster URL, http or https; a missing or invalid one makes each call for that index return a failed Result |
AdditionalNodes |
URLs of the cluster's other nodes, each an absolute http or https URL with the same scheme as ConnectionString. A request that can't reach a node is sent to the next one, and the node is left out for a while before it is tried again. An Indexes entry with its own ConnectionString uses only its own nodes; an entry without one takes its own AdditionalNodes if set, or the shared ones |
PoolType |
How requests are spread over the nodes: Static (the nodes take turns, starting from a random one), Sticky (always the first node that is up, in the order listed, starting from ConnectionString) or Sniffing (as Static, but the client asks the cluster for its nodes at startup and after a node fails, and then uses the addresses the nodes publish, which it must be able to reach). Unset, a lone ConnectionString is the only node the client uses, as before, and with AdditionalNodes the pool is Static. An Indexes entry that leaves it out takes the shared value |
AuthenticationType |
None, Password (basic, Username and Password) or ApiKey (an OpenSearch 3.x API key in ApiKey, sent as Authorization: ApiKey <key>) |
CertificateFingerprint |
The SHA-256 fingerprint of the server's certificate or of the CA that signed it, 64 hex digits with or without colons. A certificate the system does not trust is then accepted when it has this fingerprint, or chains through valid signatures to a CA that has it, whatever host name it names; one the system trusts is accepted as before. Can't be set together with DevelopmentOnlySkipCertificateValidation |
DevelopmentOnlySkipCertificateValidation |
true accepts any server certificate, so anyone between the application and the cluster can read and change the traffic, credentials included. Only for a local development cluster, such as one running the security plugin's demo certificates. A certificate the system trusts needs neither TLS setting; set CertificateFingerprint only for one it does not, such as a self-signed CA |
Indexes |
Per-index settings; an entry can set its own connection string or authentication, and takes whatever it leaves out from SharedIndexSettings. An entry's "AuthenticationType": "None" turns the shared authentication off for that index. Indexes that end up with the same nodes, pool type and authentication share one client, and changed settings take effect on the next call. Keys match index names whatever their case, so People applies to the index people. The TLS settings go with the connection string: an entry with its own ConnectionString uses only its own CertificateFingerprint and DevelopmentOnlySkipCertificateValidation, and one without takes the shared ones; setting either on an entry without its own ConnectionString fails validation |
Mappings |
Explicit field mappings, in SharedIndexSettings or an Indexes entry; see Field mappings |
BulkBatchSize |
Most documents IndexMultipleDocumentsAsync sends in one bulk request, 1000 by default, in SharedIndexSettings or an Indexes entry; see Indexing several documents. It must be greater than 0, or startup validation fails |
WriteVisibility |
Default or WaitUntilSearchable, in SharedIndexSettings or an Indexes entry; see When writes are searchable. An entry that leaves it out takes the shared value, and "WriteVisibility": "Default" there turns the shared one off |
RequestTimeout |
How long a request may take, such as "00:00:10", in SharedIndexSettings or an Indexes entry; unset, the client's default of 60 seconds. The client also limits a request and its retries together to this time, unless configureClient sets MaxRetryTimeout. It must be greater than 0 and at most 24.20:31:23.647 (int.MaxValue milliseconds, the longest the client accepts), or startup validation fails |
MaxRetries |
How many times the client retries a failed request, in SharedIndexSettings or an Indexes entry; unset, the client's default. It must not be negative, or startup validation fails |
IndexPrefix |
Put before every index name sent to the server, so applications or environments can share a cluster: with app-, the index people is app-people on the server. Indexing, search, GetDocumentAsync, CountAsync, UpdateDocumentAsync, removal, the index checks, DeleteIndexAsync and rebuilds all add it, and you keep using people. Lower case only, without \ / * ? " < > \| , # : or spaces, and not starting with -, _ or +; startup validation fails otherwise, naming IndexPrefix |
MaxResultWindow |
Deepest result a search may page to, 10,000 by default; match it to the indexes' index.max_result_window. It must be greater than 0, or startup validation fails |
You can also set the options in code with services.Configure<OpenSearchOptions>(...).
The options are validated at startup (ValidateOnStart), so a host with invalid settings fails to start with
OptionsValidationException, listing every setting that is wrong, each by its configuration path. The connection
string and authentication are checked as each call checks them, after merging each Indexes entry with
SharedIndexSettings. For example ConnectionString is not an http or https URL. Set Bielu:BetterSearch:OpenSearch:Indexes:people:ConnectionString. A failure for an Indexes entry names only the setting that changes its value: the entry's own path when it sets the value, and the SharedIndexSettings path when it inherits it, as an entry takes the authentication details only with its own AuthenticationType.
Connection messages never include the connection string or a credential; the other messages show the rejected value, such as MaxResultWindow is 0. A missing section, or one whose name is misspelled, gives the single
failure No Bielu:BetterSearch:OpenSearch settings were found., naming the section. Each of AdditionalNodes is checked as ConnectionString is, and a failure names its position, such as AdditionalNodes:1 is not an http or https URL. Set Bielu:BetterSearch:OpenSearch:SharedIndexSettings:AdditionalNodes:1, or Bielu:BetterSearch:OpenSearch:Indexes:<index>:AdditionalNodes:1 for one index. The shared settings are not checked on their own when they set
no connection string and every Indexes entry sets its own connection: shared authentication is then checked with each index that inherits it, and an index not listed fails when it is used. CertificateFingerprint must be 64 hex digits, with or without colons, and can't be set together with DevelopmentOnlySkipCertificateValidation. MaxResultWindow must be greater than 0. The same
checks run whenever the options are read, so after a configuration reload to invalid settings, every call returns a
failed Result with the same messages.
Client settings
For anything the options don't cover, such as a proxy, a header or certificate validation, pass configureClient. It
gets the client's ConnectionSettings after the provider has applied the options, so it can override them too:
builder.Services.AddBetterSearch(builder.Configuration, search => search.AddOpenSearch(
configureClient: settings => settings.Proxy(new Uri("http://proxy:3128"), "user", "password")));
The provider keeps one client per distinct connection: the connection string, the authentication, RequestTimeout
and MaxRetries, so two indexes with different timeouts get two clients. The callback runs once for each client, when
it is created, not on every request; two calls racing to create the same client can each run it, and only one of the
clients is kept. It runs for every client the provider creates, whichever Indexes entry the client is for.
A changed connection setting, such as a password or API key rotated through IOptionsMonitor, gets the client for
the new setting on the next call for the index, which is a new client unless another index name already uses that
setting. The provider then drops the client for the old setting once no index name resolves to it any more, so the
number of cached clients stays at one per connection that is in use, however often a credential rotates. An index name
that has not been used for an hour is forgotten, so short-lived index names do not accumulate and an abandoned name does
not keep an old client cached. A dropped client is not disposed, so a request already running on it finishes. Switching
back to an earlier setting after its client was dropped creates a new client, and the configureClient callbacks run
again.
Amazon OpenSearch Service and Serverless (AWS SigV4)
Amazon OpenSearch Service with IAM authentication and Amazon OpenSearch Serverless need each request signed with
AWS Signature Version 4. Add the Bielu.BetterSearch.OpenSearch.Aws package, which signs through
OpenSearch.Net.Auth.AwsSigV4, so the base
package takes no AWS dependency:
dotnet add package Bielu.BetterSearch.OpenSearch.Aws --prerelease
using Bielu.BetterSearch.OpenSearch.Aws;
builder.Services.AddBetterSearch(builder.Configuration, search => search
.AddOpenSearch()
.AddOpenSearchAwsSigV4());
"OpenSearch": {
"SharedIndexSettings": { "ConnectionString": "https://search-my-domain.eu-west-1.es.amazonaws.com" },
"AwsSigV4": { "Service": "es", "Region": "eu-west-1" }
}
| Setting | Meaning |
|---|---|
Service |
es (the default) for an Amazon OpenSearch Service domain, or aoss for an Amazon OpenSearch Serverless collection. Any other value fails startup validation, naming Bielu:BetterSearch:OpenSearch:AwsSigV4:Service |
Region |
The region the requests are signed for. Unset, the AWS SDK finds it, from AWS_REGION or the AWS profile. An empty value fails startup validation |
Credentials |
Set in code only, through AddOpenSearchAwsSigV4(options => options.Credentials = ...). Unset, the AWS SDK's default credential chain finds them: environment variables, the AWS profile, or the role of the container or instance. Session credentials send X-Amz-Security-Token |
Leave AuthenticationType at None: the signature is the request's Authorization header. Every OpenSearch client the
provider creates signs its requests, whichever Indexes entry it is for, and each client gets its connection when it
is created, with the settings current then. Two calls racing to create the same client can each create a connection,
and only one client and its connection are kept.
Note
The signing is tested against a local endpoint, not a real Amazon OpenSearch domain or Serverless collection: the
tests send requests with known credentials, region, service and clock, and check Authorization (its Credential
scope, SignedHeaders and signature), X-Amz-Date, X-Amz-Content-Sha256 and X-Amz-Security-Token, recomputing
the signature with a reference signer that matches AWS's published SigV4 examples.
AddOpenSearchAwsSigV4 is built on UseOpenSearchConnection, in the base package, which sends every OpenSearch
client's requests through the IConnection its callback returns. The callback runs when a client is created, with the
same race as configureClient: two calls creating the same client can each run it, and the connection of the client
that isn't kept is dropped without being disposed. configureClient can't
do this, as the client takes its connection when it is created. A client the provider creates again, after a changed
setting dropped it, runs the callback again.
How queries behave
Documents are stored with their values under fields, as with Elasticsearch, so a query on Name searches
fields.Name.
- Text fields are analyzed.
TermQueryandPrefixQuerymatch analyzed tokens and ignore ASCII case only. UseField.keywordto match the whole value. PrefixQueryneeds a text or keyword field, andPrefixPhraseQuerya text field. On a field holding numbers or dates, OpenSearch rejects the query and the search returns a failedResult.StringRangeSubQuerybounds are case-sensitive. They are compared to the indexed tokens as given, so on an analyzed field, whose tokens are lower-cased,"a"–"z"matchesJanebut"A"–"Z"doesn't. Pass lower-case bounds, or useField.keywordto compare whole values.- Sorting on a text field is rejected by OpenSearch. A field mapped as
TextinMappingssorts on itskeywordsub-field under its plain name; an unmapped text field still sorts asField.keyword. SpatialSearchSubQueryneeds the field mapped asGeoPointinMappings; dynamic mapping doesn't create one.LuceneQueryfield names need thefields.prefix.FuzzySubQueryallows at most 2 edits, and usesAUTOwhenMaxEditsis unset. A value that is not a string or a number, such as a date or a boolean, returns a failedResult.- Dates are stored and queried as ISO 8601 text in UTC, with fractional seconds only when they are not zero
(
2026-11-08T13:05:00Z,2026-11-08T13:05:00.123Z). A localDateTimeand aDateTimeOffsetare converted to UTC, and aDateTimewithKind.Unspecifiedis taken as UTC, so a date comes back from a search in UTC. ATermQuery,TermsQueryorPrefixQuerywith a date value matches that text on a keyword field. Dynamic mapping maps these strings as dates, which OpenSearch rejects a prefix query on. Re-index documents indexed before this version, which keep the text the client wrote then. - Total hit count is exact up to
MaxResultWindowmatches, then a lower bound.
Field mappings
Indexes are created with dynamic mapping, which makes a string a text field with a keyword sub-field,
unless the first value it sees looks like a date (2026-11-13), which date detection maps as date with no sub-field.
Mappings maps fields explicitly instead. Each entry names a Field, as queries name it (City, not
fields.City), and a Type: Text, Keyword, Date, Long, Integer, Short, Byte, Double, Float,
Boolean or GeoPoint. A Text field can set an Analyzer and a Date field a Format.
"SharedIndexSettings": {
"Mappings": [
{ "Field": "City", "Type": "Keyword" },
{ "Field": "Location", "Type": "GeoPoint" }
]
},
"Indexes": {
"articles": {
"Mappings": [ { "Field": "Title", "Type": "Text", "Analyzer": "english" } ]
}
}
- An
Indexesentry's mappings add to the shared ones, and replace a shared mapping of the same field. - Fields not listed keep dynamic mapping.
Keywordholds the whole value.TermQuerymatches it whole, ignoring case, and sorting uses it, both under the plain field name.Textis analyzed and gets akeywordsub-field (ignore_above256), as dynamic mapping gives it.TermQueryandTermsQuerymatch one token the field's analyzer produced, ignoring case: with the default analyzer that is one word, as on every provider, while with anotherAnalyzerthe term must equal one of its tokens (withkeyword, the whole value). Sorting usesField.keywordautomatically, so callers sort onField. That sort compares whole values as given: upper case sorts before lower case (Bananabeforeapple), a multi-valued field sorts ascending by its lowest value, and a value longer than 256 characters isn't in the sub-field, so it sorts as if the field were missing.GeoPointmakesSpatialSearchSubQuerywork. A point is a"lat,lon"string or a dictionary withlatandlon.Datewith aFormatmust accept the values documents hold, or indexing them fails. The provider writes aDateTimeorDateTimeOffsetas ISO 8601 text in UTC (2026-11-08T13:05:00Z) and aDateOnlyasyyyy-MM-dd, so a custom format has to accept ISO 8601 as well, for examplestrict_date_optional_time||yyyy-MM-dd.yyyy-MM-ddalone rejects everyDateTimedocument.
CreateIndexAsync creates the index with its mappings. It returns false when the index already exists,
leaving its mappings as they are, and a failed Result for any other rejection, such as an unknown analyzer.
EnsureIndexExistsAsync creates a missing index the same way. When the index exists, or another caller created
it in between, it adds the mappings to it. It returns true whenever the index exists afterwards. A mapping that conflicts with how the field is already mapped, such as
Keyword on a field dynamic mapping already made text, returns a failed Result naming the field. Re-index
into a new index to change a field's type. When the cluster takes the mappings but doesn't acknowledge them in
time, the result is failed too: the mappings aren't rolled back, and calling EnsureIndexExistsAsync again
confirms them.
The options are validated at startup (ValidateOnStart) and whenever they are read. A missing Field or
Type, a Field starting with fields., the same field twice in one list, an Analyzer on a field that isn't
Text or a Format on a field that isn't Date throws OptionsValidationException, naming the setting, such as
Bielu:BetterSearch:OpenSearch:Indexes:articles:Mappings:0:Type.
Highlighting
Each entry in HighlightQueries asks for the fragments of one field (Field) or of every field
(IsAllField, sent as fields.*). The fragments come back on each hit, in ISearchHit.Highlights, keyed by
the field name without the fields. prefix (Name, also when the request names fields.Name), with each matched term between <em> and </em>
(SearchHit.HighlightPreTag and HighlightPostTag).
- Terms the main query matched in that field are marked. With
IsAllField, only the fields the query matched have an entry. A request's ownQueriesreplace the main query for that field, so they mark their own terms; they don't change which documents are hits. - A hit with nothing marked has no entries, and a field with nothing marked has no entry.
- A multi-valued field returns only the values that matched, each as its own fragment.
- Fragments use OpenSearch's default size and count.
- Fragments are HTML-escaped. The document text is escaped (
<becomes<,&becomes&), so the<em>tags are the only markup and a fragment is safe to render as HTML. - Invalid requests return a failed
Result: anullentry, an entry with neitherFieldnorIsAllField, two entries for the same field, also under different names for it (Nameandfields.Name), and anullclause in a request's ownQueries.
Facets
FacetQueries become OpenSearch aggregations, and their results come back in ISearchResult.Aggregations, read with
RetrieveBucketAggregation(name) and RetrieveSingleAggregation(name):
TermAggregationis atermsaggregation: oneKeyBucketper value, the values with the most documents first,Sizeof them (10 when it is 0).MultiTermAggregationis amulti_termsaggregation: oneKeyBucketper combination of values, each value inKeysand the joined key, such asRed|acme, inKey.FilterAggregationQueryis afilteraggregation: aSingleAggregationwhose one bucket holds the number of documents itsQueriesmatch.NestedAggregationsare sub-aggregations, counted per bucket and returned in the bucket'sAggregations.- Counts cover the main query's matches. A post filter narrows the hits, not the counts.
- A field mapped as
TextinMappingsis counted on itskeywordsub-field, so facet on the plain name. - An unmapped text field, such as a string field dynamic mapping created, can't be counted: the search returns
a failed
Resultsaying to map the field or to facet onField.keyword, the sub-field dynamic mapping adds. - Keys are text: a whole number comes back in the invariant culture, such as
5.
Indexing several documents
IndexMultipleDocumentsAsync sends each index's documents in bulk requests of at most BulkBatchSize
documents (1000 unless set), one after another, so a large import stays under the cluster's
http.max_content_length (100 MB unless changed), and returns how many documents it indexed. OpenSearch
applies each document of a bulk request on its own, so when it rejects some (a value that doesn't fit the field's
mapping, say), the remaining requests are still sent, and the Result fails naming their ids, with every id in the
error's ids metadata, and the other documents are already stored. When the first request is rejected as a
whole, such as a 403, the Result fails with OpenSearch's error and nothing after it is sent. When a later request
fails as a whole, the requests after it are not sent, and the Result fails naming every document not confirmed
as stored: the ones rejected so far, the ones in that request, which may or may not be stored, and the ones not
sent.
When writes are searchable
By default a successful write is stored but not yet searchable: OpenSearch makes it visible at the next index
refresh, about a second later unless index.refresh_interval is changed. Set WriteVisibility to
WaitUntilSearchable to have every index and remove call return only once a search can see the write:
"SharedIndexSettings": { "ConnectionString": "http://localhost:9200", "WriteVisibility": "WaitUntilSearchable" }
IndexDocumentAsync,IndexMultipleDocumentsAsync,RemoveDocumentAsyncandRemoveDocumentsAsyncsendrefresh=wait_for, so the call waits for the next scheduled refresh rather than forcing one.RemoveAllDocumentsAsyncsendsrefresh=true, because delete by query can't wait for a refresh; it refreshes the index once the documents are removed.- Cost: each call can take up to the refresh interval, and
IndexMultipleDocumentsAsyncwaits once for each bulk request ofBulkBatchSizedocuments, so a large import waits many times. Leave it atDefaultfor bulk loads and turn it on where a write must be visible straight away, such as tests and small sites. - Waiting doesn't change what a failure means: a failed or cancelled call may still have stored the write.
Whatever WriteVisibility is, RemoveAllDocumentsAsync first refreshes the index, then sends the delete by query.
Delete by query removes only the documents that are searchable when it starts, so without the refresh a write that
was acknowledged under Default but not refreshed yet would be left behind. Remove all is rare, so the extra
request is a small cost. When the refresh fails, for example with a 403, a missing index or a failed shard, the call
returns a failed Result and removes nothing.
Rebuilding an index without downtime
The indexing provider also implements IIndexLifecycleProviderAsync, which IIndexLifecycleServiceAsync, registered
by AddBetterSearch and by key like the other services, runs:
var rebuild = await lifecycle.StartRebuildAsync("people"); // creates app-people-rebuild-<time>-<random>
if (rebuild.IsFailed)
{
return;
}
var indexed = await lifecycle.IndexRebuildDocumentsAsync(rebuild.Value, documents); // searches still read the old index
if (indexed.IsFailed)
{
await lifecycle.AbortRebuildAsync(rebuild.Value); // deletes the new index; the old one stays live
return;
}
var deleted = await lifecycle.CompleteRebuildAsync(rebuild.Value); // swaps the alias and deletes the old indexes
Complete doesn't know whether every document reached the new index, so check the result of each
IndexRebuildDocumentsAsync call and abort, rather than complete, when one fails.
- Start creates a new index named after the index (with the prefix),
-rebuild-, the UTC start time and a random suffix, with the index's configuredMappings. - Index writes the documents to the new index only. Each document's
Indexmust be the index being rebuilt; the service checks the whole batch, asIndexMultipleDocumentsAsyncdoes, before writing any of it. - Complete refreshes the new index, and fails without touching the alias when the refresh fails on any shard. It
then sends one update aliases request that points an alias named like the index at it and deletes, with
remove_index, every index the alias pointed at before. OpenSearch applies the request atomically, so searches switch from the old documents to the new ones at once, and when OpenSearch rejects it, nothing changes and the alias stays on the old index. When OpenSearch doesn't acknowledge it in time, theResultfails but the change may still apply, so the old indexes may already be gone: callCompleteRebuildAsyncagain, which succeeds once the alias points at the new index. It returns the names of the deleted indexes. The first rebuild of an index created as a plain index replaces that index with the alias in the same request. Completing a rebuild that is already complete succeeds and deletes nothing. - Abort deletes the new index and leaves the alias where it is. It fails, deleting nothing, once the rebuild is
complete. Start gives the new index a pending alias,
<new index>-pending. Complete removes it in its update aliases request, and Abort removes it before deleting the new index, each withmust_exist, so when a complete and an abort of the same rebuild overlap, even in different processes, only one takes effect: either the rebuild completes and the abort fails, or the abort deletes the new index and the complete fails. Two overlapping completes both succeed. - Each call reads
IndexPrefixonce, so a configuration reload during a call can't make it check one alias and change another. A rebuild whose new index is gone, aborted or deleted elsewhere, fails to complete and leaves the alias on the old index. - A rebuild that names an index
StartRebuildAsynccould not have created for it fails without touching anything.
Writes to the index name while a rebuild runs go to the old index and are not copied to the new one, so pause them or
write them again after the swap. After a rebuild the index name is an alias: searches and writes go through it, and
DeleteIndexAsync deletes the index behind it, and so the alias.
Removing documents
DeleteDocumentRequest.Index names the index to remove the document from.
- A document that is not there:
RemoveDocumentAsyncsucceeds, as the document is already gone. - An index that does not exist:
RemoveDocumentAsyncreturns a failedResult. - Several documents:
RemoveDocumentsAsync(index, ids)sends one bulk request and returns how many documents it removed; an id that is not there is not counted. When items fail, theResultfails naming their ids, and the other documents are already removed. A missing index returns a failedResultnaming the ids. A request cancelled through theCancellationToken, before or during the request, throwsOperationCanceledException.
Getting, counting and updating documents
GetDocumentAsync(index, id)reads the document withGET index/_doc/idand returns its fields as hits return them. A 404 that OpenSearch gave for a missing document (found: false) or a missing index (index_not_found_exception) is success withnull. Any other failure, such as a 401, a 5xx or a 404 without that answer (from a proxy, say), is a failedResult.CountAsync(query)sends_countwith the query and its post filter, so the count is exact, with no cap atMaxResultWindow. A missing index is a failedResult, as a search there is.UpdateDocumentAsync(index, id, fields)sends a partial_updatethat replaces each named field underfieldsand keeps the others, and retries up to 3 times on a version conflict. It returnsfalsefor a missing document or index and creates neither. OpenSearch creates a missing index on an update, without the configuredMappings, so the provider checks the index exists first; an index deleted between that check and the update is still created again.WriteVisibilityapplies to it as to the other writes.
Health check
As on Elasticsearch, PingAsync sends HEAD / with the client of the index it is given, or of
SharedIndexSettings when it is given none, and any answer other than 200, an unreachable server or invalid
settings is a failed Result. AddBetterSearchHealthCheck() from Bielu.BetterSearch.HealthChecks registers it as a health check,
which the application maps to an endpoint such as /health; see observability.
Checking an index exists
IndexExistsAsync is success with true on a 200 and false on a 404. Any other answer, such as a 401, 403
or 5xx, or no answer at all, is a failed Result. Its message names the HTTP status when there was one, then
the server's error, or the transport's exception when the server sent none, and that exception is attached as
its cause. A request
cancelled through the CancellationToken throws OperationCanceledException. EnsureIndexExistsAsync returns
a failed check as it is rather than trying to create the index.
As on Elasticsearch, index operations report what happened: creating an existing index is success with
false, and any other rejection, such as a 403, is a failed Result. EnsureIndexExistsAsync and
DeleteIndexAsync succeed with true, and EnsureIndexExistsAsync is true too when another caller created
the index between its check and its create. The
feature matrix has the full detail.