Architecture
jEAP OpenSearch Index Writer is a Spring Boot service template for event-driven indexing of search items into OpenSearch. A service instance is created by depending on the template and adding index type and message configuration specific to the owning domain.
Modules and responsibilities
The template follows hexagonal architecture: the domain module contains all business logic and defines ports (interfaces); adapters implement those ports against concrete infrastructure.
| Module | Key types | Responsibility |
|---|---|---|
domain | MessageIndexingService, IndexWriter, ReferenceProvider, IndexingCondition | Core indexing logic; no framework dependency |
adapter-opensearch | OpenSearchIndexWriter, IndexTemplateManager, PhysicalIndexManager, IndexMappingManager | Creates/updates index templates and writes documents to OpenSearch |
adapter-kafka | KafkaIndexWriterMessageListener, KafkaIndexWriterConsumerFactory | Consumes Kafka events and forwards them to the domain |
adapter-remote-data | HttpSearchItemProvider | Fetches SearchItem data from the owning domain service via REST |
index-config-repository | JsonMessageConfigurationRepository | Loads and parses /opensearch/messages.json at startup |
index-type-repository | ServiceLoaderIndexTypeRepository | Discovers registered IndexType Spring beans |
web | OpenSearchIndexWriterApplication | Spring Boot wiring, auto-configuration |
service-instance | BOM | Thin dependency entry point for service instances |
Event flow
An incoming Kafka event travels through the adapters to the domain and ends up as a document write in OpenSearch:
Step by step:
- Consume.
KafkaIndexWriterMessageListenerreceives a message from the configured Kafka topic and forwards it to theMessageIndexingService. - Extract references. The
ReferenceProviderbean configured for the operation extracts one or moreOriginReferenceobjects from the message. Each reference is processed independently. - Fetch SearchItem. For
UPSERToperations,HttpSearchItemProvidercalls the owning domain service's SearchItem Provider endpoint and retrieves the current search representation. The provider chooses the schema major; the optionalorigin_versionof the reference is passed through. Maintenance requests the current data in a fixed schema major instead viaCurrentSearchItemFetcher(see Write operations). - Validate and enrich. For
UPSERToperations, the service validates theSearchItemfields against theIndexTypemapping and enriches the document with metadata (upserted_at,major_version,minor_version). - Write. For
UPSERT,OpenSearchIndexWritersends the document to OpenSearch via theIndexWriteAlias(PUT).DELETEskips steps 3 and 4 and removes the document via theIndexWriteAliasof every registered major of the index type, without calling the provider (see Write operations). - Error handling. If any step fails, the triggering event is forwarded to the jEAP error handling service.
Startup flow
On startup, IndexMappingUpdater iterates over every registered IndexType and calls
ensureIndexReady:
See Startup behaviour for details.
Key design decisions
Service-owned templates. Index templates are created and managed by the index writer service at
startup, not by IaC. This keeps the template in sync with the IndexType mapping and removes the
need for separate IaC for each index.
Write alias not in template. The write alias is set explicitly only when the initial physical index is created. Placing it in the template would cause OpenSearch to reject ISM rollovers with a duplicate-alias error.
Declarative message configuration. All message-to-operation mappings are declared in a JSON file rather than in code. This allows the same template code to power many different service instances without any business logic changes.
Hexagonal architecture. The domain module carries no framework dependency. All Spring Boot, Kafka, and OpenSearch specifics live in adapters, making the core logic independently testable.