Reader small image

You're reading from  Advanced Elasticsearch 7.0

Product typeBook
Published inAug 2019
Reading LevelBeginner
PublisherPackt
ISBN-139781789957754
Edition1st Edition
Languages
Right arrow
Author (1)
Wai Tak Wong
Wai Tak Wong
author image
Wai Tak Wong

Wai Tak Wong is a faculty member in the Department of Computer Science at Kean University, NJ, USA. He has more than 15 years professional experience in cloud software design and development. His PhD in computer science was obtained at NJIT, NJ, USA. Wai Tak has served as an associate professor in the Information Management Department of Chung Hua University, Taiwan. A co-founder of Shanghai Shellshellfish Information Technology, Wai Tak acted as the Chief Scientist of the R&D team, and he has published more than a dozen algorithms in prestigious journals and conferences. Wai Tak began his search and analytics technology career with Elasticsearch in the real estate market and later applied this to data management and FinTech data services.
Read more about Wai Tak Wong

Right arrow

Elasticsearch from Java Programming

In the last chapter, we used aggregation frameworks to explore data analysis. We drew the Bollinger Band for one of the exchange-traded funds (ETFs) to demonstrate operational data analysis daily. We also examined the role of Elasticsearch in sentiment analysis and showed how a number of different open source projects integrated Elasticsearch into the analysis. In this chapter, we will focus on the basics of two supported Java REST clients. We’ll also explore the main features and operations for each approach. The advantage of using a REST client is that it accepts the request objects or the response objects as arguments in the APIs. The high-level REST client is responsible for the corresponding serialization and deserialization. If we choose the low-level REST client, we need to handle such operations by ourselves. Each API can be called...

Overview of Elasticsearch Java REST client

You will recall that in the Talking to Elasticsearch section in Chapter 1, Overview of Elasticsearch 7, we discussed that Elasticsearch officially supports two protocols only. They are HTTP (the RESTful API) and native. When using the Java language, the transport client was the preferred method of the native protocol. However, transport clients such as the Java API are deprecated in Elasticsearch 7.0, and completely removed in 8.0. In short, we should use the Java high-level REST client. According to the Elasticsearch client in the Maven repository (available at https://search.maven.org/search?q=g:org.elasticsearch.client), we can sketch the hierarchy of the group ID and artifact ID, as shown in the following diagram:

Because the length of the chapter is limited, we are only focusing on two artifacts, elasticsearch-rest-high-level-client...

The Java low-level REST client

The Java low-level REST client was released in 2016 for version 5.0.0, which is based on the Apache HTTP client. This was the first time that we could get the Java client to work in the same way as all the other language clients. Low level means that it has minimum support for Java users to build requests or to parse responses. Users have to handle the request's path, query-string construction, and the JSON response body. We are not going to elaborate on how the entire program works. Instead, we'll target only the workflow of the Java low-level REST client.

The Java low-level REST client workflow

Basically, there are three major steps involved: REST client initialization, performing...

The Java high-level REST client

The Java high-level REST client is built on the top of the low-level REST client. It is responsible for the serialization and deserialization of the request and response objects. According to the official announcement from Elasticsearch (available at https://www.elastic.co/guide/en/elasticsearch/client/java-api/7.0/transport-client.html), the transport client will be removed in version 8.0. Using the Java high-level REST client should be the preference. Similarly to how we presented the low-level REST client, we'll target only the workflow of the Java high-level REST client.

The Java high-level REST client workflow

Similar to what we did in the previous section, there are three major...

Spring Data Elasticsearch

Spring Data's goal is to significantly reduce the boilerplate codes that are used to implement the data access layer. The Spring Data repository takes the domain class to manage its life cycle and provides basic functionalities such as CRUD, paging, and sorting. In order to use Spring Boot and Spring Data Elasticsearch, a new Spring Boot starter dependency is required to be added to pom.xml, as shown in the following code block:

  <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>

At the time of writing, the latest version of Spring Boot Starter Data Elasticsearch is 2.1.4, which supports Spring Data Elasticsearch 3.1.6 for Elasticsearch version 6.5.2. Interested users will need to wait for the new version to be released...

Summary

Cheers! We have completed a basic study of Java programming with Elasticsearch. We should now be able to understand and access the different Elasticsearch clients in Java. We also learned how to incorporate Elasticsearch into Java applications, especially Spring Boot applications. We also outlined the basic programming concept of Spring Data Elasticsearch. We pointed out the issue that Spring Data needs to revise significantly, due to the fact that the transport client is deprecated in version 7.0 and will be removed fully in version 8.0.

In the following Chapter 12, Elasticsearch from Python Programming, we will introduce Python programming with Elasticsearch. The elasticsearch-py package is the official low-level client for Elasticsearch. The goal of the Python package is to provide commonality to all Elasticsearch-related codes in Python. We will also review Elasticsearch...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Advanced Elasticsearch 7.0
Published in: Aug 2019Publisher: PacktISBN-13: 9781789957754
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Wai Tak Wong

Wai Tak Wong is a faculty member in the Department of Computer Science at Kean University, NJ, USA. He has more than 15 years professional experience in cloud software design and development. His PhD in computer science was obtained at NJIT, NJ, USA. Wai Tak has served as an associate professor in the Information Management Department of Chung Hua University, Taiwan. A co-founder of Shanghai Shellshellfish Information Technology, Wai Tak acted as the Chief Scientist of the R&D team, and he has published more than a dozen algorithms in prestigious journals and conferences. Wai Tak began his search and analytics technology career with Elasticsearch in the real estate market and later applied this to data management and FinTech data services.
Read more about Wai Tak Wong