Type-safe metamodel generator for Elasticsearch in Kotlin. Automatically generates compile-time validated field accessors from Spring Data Elasticsearch documents.
π Read the full documentation at ekino.github.io/Metalastic
Metalastic is a compile-time code generator that transforms your Spring Data Elasticsearch @Document classes into type-safe metamodels. It eliminates string-based field names and provides full IDE support for building Elasticsearch queries.
- π« No more typos - Compile-time validation prevents
"staus"β"status"errors - π IDE autocomplete - Full IntelliSense for nested document structures
- π‘οΈ Type safety - Compile-time verification of field types and relationships
- π¦ Zero runtime overhead - All code generation happens at compile time
- π Automatic refactoring - Rename fields once, queries update everywhere
- β‘ Optional Query DSL - Fluent API with innovative operator syntax
// build.gradle.kts
plugins {
kotlin("jvm") version "2.2.21"
id("com.google.devtools.ksp") version "2.3.2"
id("com.ekino.oss.metalastic") version "1.1.0"
}
repositories {
mavenCentral()
}./gradlew buildMetamodels are automatically generated in build/generated/ksp/main/kotlin/
import com.example.MetaProduct.Companion.product
// Type-safe field access
product.title.path() // "title"
product.category.name.path() // "category.name"
// Use in queries
QueryBuilders.termQuery(product.status.path(), "ACTIVE")Full Getting Started Guide β
// Error-prone string literals
NativeSearchQuery query = new NativeSearchQueryBuilder()
.withQuery(
QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("staus", "active")) // β Typo!
.filter(QueryBuilders.rangeQuery("prcie").gte(100)) // β Typo!
)
.build();
// No IDE support, no refactoring, errors found at runtime πimport com.example.MetaProduct.Companion.product
// Compile-time validated
val query = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery(product.status.path(), "active"))
.filter(QueryBuilders.rangeQuery(product.price.path()).gte(100))
// IDE autocomplete, refactoring support, compile-time safety πimport com.metalastic.dsl.*
import com.example.MetaProduct.Companion.product
val query = BoolQuery.of {
boolQueryDsl {
must + {
product.title match "laptop"
product.status term ProductStatus.ACTIVE
}
filter + {
product.price range 500.0.fromInclusive()..2000.0
product.category.name term "electronics"
}
}
}- π Quick Start Guide - Get up and running in 5 minutes
- βοΈ Configuration - Customize metamodel generation
- π― Understanding Metamodels - How generation works
- π Field Types Reference - All supported field types
- π Query DSL Guide - Type-safe query building
- π‘ Complete Examples - Real-world use cases
- π§ Advanced Features - MultiField, nested, circular references
plugins {
id("com.google.devtools.ksp") version "2.3.2"
id("com.ekino.oss.metalastic") version "1.1.0"
}dependencies {
implementation("com.ekino.oss:metalastic-core:1.1.0")
ksp("com.ekino.oss:metalastic-processor:1.1.0")
// Optional: Query DSL module
implementation("com.ekino.oss:metalastic-elasticsearch-dsl:1.1.0")
}Detailed installation instructions β
| Spring Data ES | Elasticsearch | Metalastic Core | Query DSL Artifact |
|---|---|---|---|
| 6.0.x | 8.18.x | β 1.1.0 | metalastic-elasticsearch-dsl:1.1.0 |
| 5.4.x - 5.5.x | 8.15.x - 8.18.x | β 1.1.0 | metalastic-elasticsearch-dsl-5.5:1.1.0 |
| 5.0.x - 5.3.x | 8.5.x - 8.13.x | β 1.1.0 | metalastic-elasticsearch-dsl-5.3:1.1.0 |
- β
Type-safe field access with
path()methods - β Automatic dotted notation for nested structures
- β All Elasticsearch field types supported
- β MultiField support with inner fields
- β Circular reference handling
- β Centralized metamodels registry
- β Java & Kotlin compatible
- β
Innovative
clause + { }operator syntax - β
Mathematical notation for ranges (
10.fromInclusive()..100) - β Type-safe nested queries
- β Automatic value conversion (dates, enums, collections)
- β Full Elasticsearch query type support
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes following our code style:
./gradlew spotlessApply # Format code ./gradlew check # Run all checks
- Commit your changes:
git commit -m 'Add amazing feature' - Push to your branch:
git push origin feature/amazing-feature - Open a Pull Request
Code Style:
- Use ktfmt Google Style
- No star imports
- Write tests with Kotest
git clone https://github.com/ekino/Metalastic.git
cd Metalastic
./gradlew build- π Documentation
- π Issue Tracker
- π¬ Discussions
- π¦ Maven Central
This project is licensed under the MIT License - see the LICENSE.md file for details.
Copyright Β© 2025 ekino