All Projects → jloisel → elastic-crud

jloisel / elastic-crud

Licence: Apache-2.0 license
Simple yet elegant ElasticSearch Crud Repository.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to elastic-crud

spring-boot-starter-elasticsearchHighLevelClient
提供elasticsearch-rest-high-level-client连接池功能,同时对接spring-boot-starter
Stars: ✭ 57 (+23.91%)
Mutual labels:  elasticsearch-client, elasticsearch6
velox
The minimal PHP micro-framework.
Stars: ✭ 55 (+19.57%)
Mutual labels:  crud
Handsontable
JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡
Stars: ✭ 16,059 (+34810.87%)
Mutual labels:  crud
friendly-id
Java Friendly Id for UUID
Stars: ✭ 173 (+276.09%)
Mutual labels:  jackson
doyto-query
DoytoQuery - A Java implementation for the modern ORM Framework.
Stars: ✭ 18 (-60.87%)
Mutual labels:  crud
Elasticsearch
Elasticsearch是一个实时的分布式搜索和分析引擎,
Stars: ✭ 23 (-50%)
Mutual labels:  elasticsearch-queries
Php Crud Api
Single file PHP script that adds a REST API to a SQL database
Stars: ✭ 2,904 (+6213.04%)
Mutual labels:  crud
jackson-js
JavaScript object serialization and deserialization library using decorators. It supports also advanced Object concepts such as polymorphism, Object identity and cyclic objects.
Stars: ✭ 86 (+86.96%)
Mutual labels:  json-serialization
mesan-nodejs-auth-crud-api
NodeJS Authentication and CRUD operations API -: Email Verification, Image Upload, Password Reset
Stars: ✭ 72 (+56.52%)
Mutual labels:  crud
JMantic
Java library for connecting to sc-machine
Stars: ✭ 14 (-69.57%)
Mutual labels:  jackson
mezon
Mezon is a simple php framework wich will help you to create business applications.
Stars: ✭ 35 (-23.91%)
Mutual labels:  crud
serverless-nestjs-typeorm
Example how to nestjs using the serverless framework with TypeORM
Stars: ✭ 99 (+115.22%)
Mutual labels:  crud
repository
[PHP 7] Implementation and definition of a base Repository in Domain land.
Stars: ✭ 26 (-43.48%)
Mutual labels:  crud
catnap
Partial JSON response framework for RESTful web services
Stars: ✭ 55 (+19.57%)
Mutual labels:  jackson
Codeigniter-4-CRUD-generator
ADEL CCG is an easy open-source intuitive web app to create AdminLTE4 -Bootstrap 5- dashboards with CRUD operations in php.
Stars: ✭ 87 (+89.13%)
Mutual labels:  crud
Cssobj
Runtime CSS manager, Turn CSS into dynamic JS module, Stylesheet CRUD (Create, Read, Update, Delete) in CSSOM, name space (local) class names
Stars: ✭ 253 (+450%)
Mutual labels:  crud
godot-rpgdb
An easy to use JSON database-manager for Godot.
Stars: ✭ 25 (-45.65%)
Mutual labels:  json-serialization
Ffast-Java
Ffast 基于Srping boot + Mybatis Plus后台管理系统前后分离快速开发解决方案
Stars: ✭ 104 (+126.09%)
Mutual labels:  crud
domino-jackson
Jackson with Annotation processing
Stars: ✭ 46 (+0%)
Mutual labels:  json-serialization
Attendance-1
A simple attendance list with a delete button, that can delete from the inputs you submitted to the database
Stars: ✭ 15 (-67.39%)
Mutual labels:  crud

Build Status Dependency Status Coverage Status Maven Central Javadoc

Elasticsearch Simple CRUD Repository

Easily perform Create / Read / Update / Delete operations on beans stored in Elasticsearch. Spring Data Elasticsearch lacks maintenance and is already a few Elasticsearch versions behind the latest version.

This project powers our JMeter Load Testing platform.

Versions

The following table shows the correspondance between our versions and Elasticsearch versions:

Version ElasticSearch Version
1.1.x 2.1.x
2.2.x 2.2.x
2.3.x 2.3.x
5.1.x 5.1.x
5.6.x 5.6.x

As of 2.2.x, the project is going to strictly follow the same versioning as elasticsearch.

Spring

Add the following Maven dependency to get started quickly with Spring:

<dependency>
    <groupId>com.jeromeloisel</groupId>
    <artifactId>db-spring-elasticsearch-starter</artifactId>
    <version>5.6.3</version>
</dependency>

Vanilla Java

To get started with Vanilla Java application, you need to add two dependencies:

<dependency>
    <groupId>com.jeromeloisel</groupId>
    <artifactId>db-conversion-jackson</artifactId>
    <version>5.6.3</version>
</dependency>

This dependency provides the Jackson Json serialization mechanism.

<dependency>
    <groupId>com.jeromeloisel</groupId>
    <artifactId>db-repository-elasticsearch</artifactId>
    <version>5.6.3</version>
</dependency>

This dependency provides the ElasticSearchRepositoryFactory to create ElasticRepository.

Java Example

Suppose we would like to persist the following Bean in Elasticsearch:

@Value
@Builder
@Document(indexName="datas", type="person")
public class Person implements Entity {
  @Wither
  String id;
  String firstname;
  String lastname;
  
  @JsonCreator
  Person(
      @JsonProperty("id") final String id, 
      @JsonProperty("firstname") final String firstname, 
      @JsonProperty("lastname") final String lastname) {
    super();
    this.id = id;
    this.firstname = checkNotNull(firstname);
    this.lastname = checkNotNull(lastname);
  }
} 

The following code shows how to use the CRUD repository:

@Autowired
private ElasticSearchRepositoryFactory factory;

public void method() {
  final ElasticRepository<Person> repository = factory.create(Person.class);
  
  final Person person = Person.builder().id("").firstname("John").lastname("Smith").build();
  final Person withId = repository.save(person);
  
  // Find by id
  final Optional<Person> byId = repository.findOne(withId.getId());
  assertTrue(repository.exists(byId));
  
  // Search by firstname (with "not_analyzed" string mapping)
  final TermQueryBuilder term = new TermQueryBuilder("firstname", PERSON.getFirstname());
  final List<Person> found = repository.search(term);
  assertTrue(found.contains(byId));
  
  // Delete from Elasticsearch definitively
  repository.delete(withId.getId());
  assertFalse(repository.exists(byId));
}

Also, scrolling through massive amount of results is made dead easy with the scrolling API:

@Autowired
private DatabaseScrollingFactory factory;

public void example() {
  // Incorporated bulk delete
  factory
    .newScroll("myIndex")
    .withQuery(new MatchAllQueryBuilder())
    .scroll(factory.bulkDelete());
  
}

You simply have to implement the DatabaseScroll interface:

@FunctionalInterface
public interface DatabaseScroll {

  default void onStartBatch() throws IOException {

  }

  void accept(SearchHit hit) throws IOException;

  default void onEndBatch() throws IOException {

  }
}

Type mapping

Beans stored in Elasticsearch must have _source field enabled: see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html. The following example Json shows how to enable _source field:

{
  "template": "datas",
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 1,
    "index.refresh_interval": -1,
  },
  "mappings": {
    "_default_": {
      "_all": {
          "enabled": false
       },
       "_source": {
          "enabled": true
       }
    }
  }
}

Index refresh

Every mutating query (insert, delete) performed on the index automatically refreshes it. I would recommend to disable index refresh as shows in the Json above.

Json Serialization

The Json serialization is configured to use Jackson by default. To use Jackson Json serialization, simply add Jackson as dependency:

<dependency>
	<groupId>com.fasterxml.jackson.core</groupId>
	<artifactId>jackson-databind</artifactId>
	<version>${jackson.version}</version>
</dependency>

Replace ${jackson.version} with the version you are using.

If you intend to use your own Json serialization mechanism (like Gson), please provide an implementation for the JsonSerializationFactory interface.

Elasticsearch Client

An instance of the Elasticsearch Client must be provided.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].