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

  • IFlexSearchStore is 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 call SearchAsync<TDocument>(query, skip, take).

  • Provider bridge: the Elasticsearch implementation is exposed via an IFlexSearchStoreBridge internally, but most consumers only need IFlexSearchStore.

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: ApiKey or Username/Password.

  • IndexName should be a stable physical index name (consider aliases/rollovers operationally).

Last updated