Elasticsearch
Elasticsearch 扩展提供了对 Elasticsearch 的支持,实现了以下接口:
EventStore
EventStreamQueryService
SnapshotRepository
SnapshotQueryService
安装
kotlin
implementation("me.ahoo.wow:wow-elasticsearch")
groovy
implementation 'me.ahoo.wow:wow-elasticsearch'
xml
<dependency>
<groupId>me.ahoo.wow</groupId>
<artifactId>wow-elasticsearch</artifactId>
<version>${wow.version}</version>
</dependency>
配置
YAML 配置样例
yaml
wow:
eventsourcing:
store:
storage: elasticsearch
snapshot:
storage: elasticsearch
配置事件流索引模板
http
POST _index_template/wow-event-stream-template
{
"index_patterns": [
"wow.*.es"
],
"template": {
"settings": {
"number_of_shards": 3,
"number_of_replicas": 2
},
"mappings": {
"properties": {
"aggregateId": {
"type": "keyword"
},
"aggregateName": {
"type": "keyword"
},
"body": {
"properties": {
"bodyType": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"name": {
"type": "keyword"
},
"revision": {
"type": "keyword"
}
}
},
"commandId": {
"type": "keyword"
},
"contextName": {
"type": "keyword"
},
"createTime": {
"type": "long"
},
"header": {
"properties": {
"upstream_id": {
"type": "keyword"
},
"upstream_name": {
"type": "keyword"
}
}
},
"id": {
"type": "keyword"
},
"requestId": {
"type": "keyword"
},
"tenantId": {
"type": "keyword"
},
"version": {
"type": "integer"
}
},
"dynamic_templates": [
{
"string_as_keyword": {
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
}
]
}
}
}
配置快照索引模板
http
POST _index_template/wow-snapshot-template
{
"index_patterns": [
"wow.*.snapshot"
],
"template": {
"settings": {
"number_of_shards": 3,
"number_of_replicas": 2
},
"mappings": {
"properties": {
"contextName": {
"type": "keyword"
},
"aggregateName": {
"type": "keyword"
},
"tenantId": {
"type": "keyword"
},
"aggregateId": {
"type": "keyword"
},
"version": {
"type": "integer"
},
"eventId": {
"type": "keyword"
},
"firstOperator": {
"type": "keyword"
},
"operator": {
"type": "keyword"
},
"firstEventTime": {
"type": "long"
},
"eventTime": {
"type": "long"
},
"snapshotTime": {
"type": "long"
},
"deleted": {
"type": "boolean"
},
"state": {
"properties": {
"id": {
"type": "keyword"
},
"tenantId": {
"type": "keyword"
}
}
}
},
"dynamic_templates": [
{
"id_string_as_keyword": {
"match": "id",
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
},
{
"id_suffix_string_as_keyword": {
"match": "*Id",
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
}
]
}
}
}