CAST supports Elasticsearch via its com.castsoftware.nosqljava extension. Details about the support provided for Java with Spring Data source code is discussed below.
Supported Client Libraries
Library | Version | Supported |
---|---|---|
spring-data-elasticsearch | Up to: 4.2.3 | |
spring-data-jest | Up to: 3.3.1 |
Supported Operations
Operation | Methods Supported |
---|---|
Insert | org.springframework.data.repository.CrudRepository.save org.springframework.data.repository.CrudRepository.saveAll org.springframework.data.repository.ElasticsearchRepository.save org.springframework.data.repository.ElasticsearchRepository.saveAll org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.save org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.saveAll org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.save org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.saveAll org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate.saveAll org.springframework.data.elasticsearch.core.ReactiveDocumentOperations.saveAll org.springframework.data.elasticsearch.core.IndexOperations.create org.springframework.data.elasticsearch.core.IndexOperations.putMapping com.github.vanroy.springdata.jest.JestElasticsearchTemplate.prepareIndex com.github.vanroy.springdata.jest.JestElasticsearchTemplate.putMapping |
Select |
|
Update |
|
Delete |
|
Objects
Icon | Description |
---|---|
Java Elasticsearch Cluster | |
Java Elasticsearch Index | |
Java Unknown Elasticsearch Cluster | |
Java Unknown Elasticsearch Index |
Links
All links are created between Elasticsearch Cluster object and Elasticsearch Index objects:
Link type | Methods supported |
---|---|
parentLink | - |
useDeleteLink | delete deleteAll deleteById deleteAllById |
useInsertLink | save saveAll |
useSelectLink | findAllById findAll findById count existsById searchSimilar indexOps get multiGet search |
useUpdateLink | bulkUpdate |
What results can you expect?
Some example scenarios are shown below:
Cluster and Index Creation
public class EsConfig { @Autowired private EsSinkProperties properties; @Bean public Client client() throws Exception { Settings esSettings = Settings.builder() .put("cluster.name", properties.getClusterName()) .build(); TransportClient client = new PreBuiltTransportClient(esSettings) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(properties.getHost()), Integer.parseInt(properties.getPort()))); } }
public class EsSinkProperties { /** * Elasticsearch cluster name. */ private String clusterName = "elasticsearch"; /** * Elasticsearch host name. */ private String host = "localhost"; /** * Elasticsearch native port. */ private String port = "9300"; @NotBlank public String getClusterName() { return clusterName; } public void setClusterName(String clusterName) { this.clusterName = clusterName; } }
@Document(indexName = "trader", type = "trade") public class Trade { @Id private String id; public String getId() { return id; } public void setId(String id) { this.id = id; }
Insert Operation
public override void Configure(EntityTypeBuilder<Contractor> builder) { builder.ToTable("Trial"); builder.OwnsOne(m => m.Name, a => { a.Property(p => p.FirstName).HasMaxLength(300) .HasColumnName("FirstName") .HasDefaultValue(""); a.Property(p => p.LastName).HasMaxLength(300) .HasColumnName("LastName") .HasDefaultValue(""); a.Ignore(p => p.FullName); });
public Book save(Book book) { return bookRepository.save(book); }
Delete Operation
public void delete(Book book) { bookRepository.delete(book); }
Select Operation
public Iterable<Book> findAll() { return bookRepository.findAll(); }
Query Methods
public interface BookRepository extends ElasticsearchRepository<Book, String> { Page<Book> findByAuthor(String author, Pageable pageable); List<Book> findByTitle(String title); }
public Page<Book> findByAuthor(String author, PageRequest pageRequest) { return bookRepository.findByAuthor(author, pageRequest); }
Elasticsearch Operations / Elasticsearch Template
public void deleteIndex() { operations.indexOps(Conference.class).delete(); }
Known Limitations
- Index is created as unknown, if the name is not retrieved from the properties file or if the name could not be resolved.
- Limited support for Spring Data Elasticsearch 3.x
- In 3.x, CRUD operations performed using ElasticsearchRepository are supported
- In 3.x no support for CRUD operations performed using ElasticsearchTemplate. However, if the user configures version 3.x jars inside its class path, then ElasticsearchTemplate will produce links.