Elastic Search
Description
Elasticsearch can be used as the backing implementation for Flex full-text search. Your application code should depend on IFlexSearchStore, while Flex provides the provider bridge and wiring.
Important concepts
IFlexSearchStoreis the contract: app code performs searches and indexing through the shared interface, not Elastic SDK types.Indexing + searching: generated plugins typically call
IndexAsync<TDocument>(document), and generated queries callSearchAsync<TDocument>(query, skip, take).Provider bridge: the Elasticsearch implementation is exposed via an
IFlexSearchStoreBridgeinternally, but most consumers only needIFlexSearchStore.
Configuration in DI
Add the provider in your DI composition root (commonly in EndPoints/...CommonConfigs/OtherApplicationServicesConfig.cs or wherever you centralize registrations).
// using Sumeru.Flex; // IFlexSearchStore
public static class OtherApplicationServicesConfig
{
public static IServiceCollection AddOtherApplicationServices(
this IServiceCollection services,
IConfiguration configuration)
{
// Registers Elasticsearch as the IFlexSearchStore bridge.
// Flex auto-wires generated Queries/Plugins that *use* IFlexSearchStore.
services.AddFlexElasticsearchSearchStore(configuration);
return services;
}
}appsettings.json
Configuration is read from FlexBase:DataStores:Search:Elasticsearch.
Examples (template-based)
These examples mirror the generated Query and PostBus plugin templates. You do not register these types manually—Flex discovers and wires generated Queries/Handlers/Plugins automatically.
Search a single document (Query)
Index a document (PostBus plugin)
Elasticsearch considerations
Configure exactly one authentication approach:
ApiKeyorUsername/Password.IndexNameshould be a stable physical index name (consider aliases/rollovers operationally).
Last updated