ElastiKJay is a Java library that provides annotation-based object mapping and simplified interaction with Elasticsearch. It allows developers to easily map Java POJOs to Elasticsearch indices using annotations, similar to how JPA works with relational databases.
- Annotation-driven mapping: Use simple annotations to define how your Java objects map to Elasticsearch indices
- Simplified CRUD operations: Easy-to-use API for creating, reading, updating, and deleting documents
- Bulk operations: High-performance bulk insert and update operations
- Index management: Create, delete, and manage Elasticsearch indices programmatically
- Flexible configuration: Support for both single-node and cluster configurations
- Type safety: Strongly-typed operations with automatic serialization/deserialization
- Java 17 or later
- Maven 3.6+
- Elasticsearch 1.2.1+ (compatible)
Add ElastiKJay to your Maven project:
<dependency>
<groupId>com.arquivolivre</groupId>
<artifactId>elastikjay</artifactId>
<version>1.2.1-SNAPSHOT</version>
</dependency>Use annotations to define how your Java classes map to Elasticsearch:
import com.arquivolivre.elastikjay.annotations.*;
@Index(name = "products", type = "product")
public class Product {
private String id;
@Analyzer("standard")
private String name;
@NotAnalyzed
private String category;
@NotIndexed
private String internalNotes;
private double price;
@Nested
private List<Review> reviews;
// Getters and setters...
}
public class Review {
private String author;
private int rating;
private String comment;
// Getters and setters...
}Create a properties file es.properties in your resources:
# Single node configuration
elasticsearch.node=localhost
elasticsearch.port=9300
# Or cluster configuration
elasticsearch.cluster.name=my-cluster
elasticsearch.cluster.nodes=node1,node2,node3
elasticsearch.cluster.ports=9300,9301,9302import com.arquivolivre.elastikjay.commons.IndexManager;
import com.arquivolivre.elastikjay.commons.IndexManagerImpl;
import com.arquivolivre.elastikjay.config.Configuration;
// Initialize the IndexManager
Configuration config = new Configuration();
IndexManager indexManager = new IndexManagerImpl(config.elasticSearchClient());
// Create an index for your class
Product sampleProduct = new Product();
indexManager.createIndex("products", "product", sampleProduct);
// Insert a document
Product product = new Product();
product.setId("1");
product.setName("Laptop Computer");
product.setCategory("electronics");
product.setPrice(999.99);
indexManager.addToBulk("1", product);
indexManager.executeBulkAdd();
// Retrieve a document
Product retrievedProduct = indexManager.get("1", Product.class);
System.out.println("Product: " + retrievedProduct.getName());
// Check if index exists
boolean exists = indexManager.indexExists("products");// Bulk insert multiple documents
List<Product> products = Arrays.asList(
new Product("1", "Laptop", "electronics", 999.99),
new Product("2", "Mouse", "electronics", 29.99),
new Product("3", "Keyboard", "electronics", 79.99)
);
for (Product product : products) {
indexManager.addToBulk(product.getId(), product);
}
// Execute all bulk operations at once
indexManager.executeBulkAdd();// Create index with custom settings
indexManager.createIndex("products", "product", new Product());
// Delete an index
indexManager.deleteIndex("products");
// Delete multiple indices
indexManager.deleteIndices("products", "orders", "customers");
// Check if index exists
if (!indexManager.indexExists("products")) {
indexManager.createIndex("products", "product", new Product());
}| Annotation | Description |
|---|---|
@Index |
Defines the Elasticsearch index name and type for a class |
@Analyzer |
Specifies the analyzer to use for text analysis |
@NotAnalyzed |
Marks a field as not analyzed (exact match only) |
@NotIndexed |
Excludes a field from being indexed |
@Ignored |
Completely ignores a field during mapping |
@Nested |
Defines nested object mapping for complex types |
@Analysis |
Configures analysis settings for the field |
@Filter |
Applies filters during analysis |
ElastiKJay supports flexible configuration through properties:
elasticsearch.node=localhost
elasticsearch.port=9300elasticsearch.cluster.name=production-cluster
elasticsearch.cluster.nodes=es-node1,es-node2,es-node3
elasticsearch.cluster.ports=9300,9300,9300# Clean and compile
mvn clean compile
# Run tests
mvn test
# Full build with verification
mvn clean verify
# Run code quality checks
mvn spotbugs:check checkstyle:check
# Generate test coverage report
mvn test
# Report available at: core/target/site/jacoco/index.htmlThis project uses several tools to maintain code quality:
- SpotBugs: Static analysis for bug detection
- Checkstyle: Code style enforcement (Google Java Style)
- JaCoCo: Test coverage reporting
- Java: 17 (upgraded from 1.7)
- Elasticsearch: 1.2.1
- Log4j: 2.20.0 (security update)
- Gson: 2.10.1
- JUnit: 4.13.2
This project is licensed under the terms specified in the LICENSE file.
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and code quality checks
- Submit a pull request
Thiago da Silva Gonzaga thiagosg@sjrp.unesp.br