This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

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

LibraryVersionSupported
spring-data-elasticsearchUp to: 4.2.3(tick)
spring-data-jestUp to: 3.3.1(tick)

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
  • org.springframework.data.repository.CrudRepository.existsById
  • org.springframework.data.repository.CrudRepository.findAll
  • org.springframework.data.repository.CrudRepository.findById
  • org.springframework.data.repository.CrudRepository.findAllById
  • org.springframework.data.repository.CrudRepository.count
  • org.springframework.data.repository.PagingAndSortingRepository.findAll
  • org.springframework.data.repository.ElasticsearchRepository.existsById
  • org.springframework.data.repository.ElasticsearchRepository.findAll
  • org.springframework.data.repository.ElasticsearchRepository.findById
  • org.springframework.data.repository.ElasticsearchRepository.findAllById
  • org.springframework.data.repository.ElasticsearchRepository.count
  • org.springframework.data.repository.ElasticsearchRepository.searchSimilar
  • org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.findAll
  • org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.existsById
  • org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.count
  • org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.findById
  • org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.findAllById
  • org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.findAll
  • org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.existsById
  • org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.count
  • org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.findById
  • org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.findAllById
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.count
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.existsById
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.findAll
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.findAllById
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.findById
  • org.springframework.data.repository.reactive.ReactiveSortingRepository.findAll
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.count
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.existsById
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.findAll
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.findAllById
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.findById
Update
  • com.github.vanroy.springdata.jest.JestElasticsearchTemplate.bulkUpdate
  • com.github.vanroy.springdata.jest.JestElasticsearchTemplate.prepareUpdate
  • com.github.vanroy.springdata.jest.JestElasticsearchTemplate.update
Delete
  • org.springframework.data.repository.CrudRepository.delete
  • org.springframework.data.repository.CrudRepository.deleteById
  • org.springframework.data.repository.CrudRepository.deleteAllById
  • org.springframework.data.repository.CrudRepository.deleteAll
  • org.springframework.data.repository.ElasticsearchRepository.delete
  • org.springframework.data.repository.ElasticsearchRepository.deleteById
  • org.springframework.data.repository.ElasticsearchRepository.deleteAllById
  • org.springframework.data.repository.ElasticsearchRepository.deleteAll
  • org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.delete
  • org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.deleteById
  • org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.deleteAll
  • org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.delete
  • org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.deleteById
  • org.springframework.data.elasticsearch.repository.support.SimpleReactiveElasticsearchRepository.deleteAll
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.delete
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.deleteAll
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.deleteById
  • org.springframework.data.repository.reactive.ReactiveCrudRepository.deleteAllById
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.delete
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.deleteAll
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.deleteById
  • org.springframework.data.repository.reactive.ReactiveElasticsearchRepository.deleteAllById
  • org.springframework.data.elasticsearch.core.ElasticsearchTemplate.delete
  • org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.delete
  • org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate.delete
  • org.springframework.data.elasticsearch.core.DocumentOperations.delete
  • org.springframework.data.elasticsearch.core.ReactiveDocumentOperations.delete
  • org.springframework.data.elasticsearch.core.IndexOperations.delete
  • org.springframework.data.elasticsearch.core.ElasticsearchTemplate.deleteIndex
  • com.github.vanroy.springdata.jest.JestElasticsearchTemplate.delete

Objects

Icon Description

Java Elasticsearch Cluster

Java Elasticsearch Index

Java Unknown Elasticsearch Cluster

Java Unknown Elasticsearch Index

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.