Page tree
Skip to end of metadata
Go to start of metadata

CAST supports Elasticsearch via its NoSQL for Java extension. Details about the support provided for Java with Spring Data source code is discussed below.

Supported Client Libraries

Supported Operations

Operation

Methods Supported

Select
  • findAllById
  • findAll
  • findById
  • count
  • existsById
  • searchSimilar
  • indexOps
  • get
  • multiGet
  • search
Delete
  • delete
  • deleteAll
  • deleteById
  • deleteAllById
Insert
  • save
  • saveAll
Update
  • bulkUpdate

Objects

Icon Description

Java Elasticsearch Cluster

Java Elasticsearch Index

Java Unknown Elasticsearch Cluster

Java Unknown Elasticsearch Index

Links are created for transaction and function point needs:

Link typeSource and destination of link Methods supported
parentLink

Between Elasticsearch Cluster object and Elasticsearch Index object







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?

Once the analysis/snapshot generation is completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

Cluster & Index Creation

 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())));

     }
}

cluster
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;
	}
}
index
@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

 Insert Operation
Insert
public Book save(Book book) {
        return bookRepository.save(book);
    }

Delete Operation

 Delete Operation
Delete
public void delete(Book book) {
        bookRepository.delete(book);
    }

Select Operation

 Select Operation
Select
public Iterable<Book> findAll() {
        return bookRepository.findAll();
    }

Query Methods

 Query Methods
book repo
public interface BookRepository extends ElasticsearchRepository<Book, String> {

    Page<Book> findByAuthor(String author, Pageable pageable);

    List<Book> findByTitle(String title);

}
query method
public Page<Book> findByAuthor(String author, PageRequest pageRequest) {
        return bookRepository.findByAuthor(author, pageRequest);
    }

Elasticsearch Operations / Elasticsearch Template

 Elasticsearch Operations
ES Operations
public void deleteIndex() {
		operations.indexOps(Conference.class).delete();
}

Evolution

  • Better resolution for cluster and index names
  • Support for ReactiveElasticsearchRepository
  • Query Methods are supported for Spring Data
  • Query methods with @Query annotation for Spring Data are supported
  • Elasticsearch operations and Elasticsearch template support for more APIs

Limitations

  • Cluster 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.
  • No labels